Textklassifikation

Arbeiten mit Hugging Face

Jacob H. Marquez

Lead Data Engineer

Textklassifikation: Stimmungsanalyse

$$

  • Texte werden nach Tonfall kategorisiert

$$

Sentiment analysis

$$

  • Anwendungen: Analyse von Bewertungen, Verfolgen der Stimmung auf Social Media

Sentiment icon

Arbeiten mit Hugging Face

Stimmungsanalyse: Beispielcode

from transformers import pipeline

my_pipeline = pipeline( "text-classification", model="distilbert-base-uncased-finetuned-sst-2-english" )
print(my_pipeline("Wi-Fi is slower than a snail today!"))
[{'label': 'NEGATIVE', 'score': 0.99}]
Arbeiten mit Hugging Face

Textklassifikation: grammatikalische Korrektheit

$$

Grammar check

$$

  • Überprüft Grammatik im Text

$$

Example of grammatical correctness

$$

  • Anwendungen: Grammatikprüfprogramme, Sprachlerntools
Arbeiten mit Hugging Face

Grammatikalische Korrektheit: Beispielcode

from transformers import pipeline


# Create a pipeline for grammar checking grammar_checker = pipeline( task="text-classification", model="abdulmatinomotoso/English_Grammar_Checker" )
# Check grammar of the input text print(grammar_checker("He eat pizza every day."))
[{'label': 'LABEL_0', 'score': 0.99}]
Arbeiten mit Hugging Face

Textklassifikation: QNLI

$$ Q&A

$$

$$

  • Überprüft, ob eine Prämisse eine Frage beantwortet

  • Anwendungen: Frage-Antwort-Systeme, Faktenprüfung

Example of QNLI

Arbeiten mit Hugging Face

QNLI: Beispielcode

from transformers import pipeline


classifier = pipeline( task="text-classification", model="cross-encoder/qnli-electra-base" )
classifier("Where is Seattle located?, Seattle is located in Washington state.")
[{'label': 'LABEL_0', 'score': 0.997}]
Arbeiten mit Hugging Face

Textklassifikation: dynamische Kategorisierung

$$

  • Weist Kategorien je nach Inhalt dynamisch zu

Category assignment example

  • Anwendungen: Inhaltsmoderation, Empfehlungssysteme

$$

Category Assignment

Arbeiten mit Hugging Face

Dynamische Kategorisierung: Beispielcode

classifier = pipeline(
  task="zero-shot-classification", 
  model="facebook/bart-large-mnli")


text = "Hey, DataCamp; we would like to feature your courses in our newsletter!" categories = ["marketing", "sales", "support"]
output = classifier(text, categories)
print(f"Top Label: {output['labels'][0]} with score: {output['scores'][0]}")
Top Label: support with score: 0.8183
Arbeiten mit Hugging Face

Herausforderungen bei der Textklassifikation

Mehrdeutigkeit

Arbeiten mit Hugging Face

Herausforderungen bei der Textklassifikation

Sarkasmus

Arbeiten mit Hugging Face

Herausforderungen bei der Textklassifikation

Mehrsprachigkeit

Arbeiten mit Hugging Face

Lass uns üben!

Arbeiten mit Hugging Face

Preparing Video For Download...