Klasifikace textu

Working with Hugging Face

Jacob H. Marquez

Lead Data Engineer

Klasifikace textu: analýza sentimentu

$$

  • Označuje text podle emočního tónu

$$

Analýza sentimentu

$$

  • Aplikace: Analýza recenzí, sledování sentimentu na sociálních sítích

Ikona sentimentu

Working with Hugging Face

Analýza sentimentu: příklad kódu

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}]
Working with Hugging Face

Klasifikace textu: gramatická správnost

$$

Kontrola gramatiky

$$

  • Hodnotí gramatickou správnost textu

$$

Příklad gramatické správnosti

$$

  • Aplikace: Gramatické korektory, nástroje pro výuku jazyků
Working with Hugging Face

Gramatická správnost: příklad kódu

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}]
Working with Hugging Face

Klasifikace textu: QNLI

$$ Q&A

$$

$$

  • Ověřuje, zda premisa odpovídá na otázku

  • Aplikace: systémy Q&A, ověřování faktů

Příklad QNLI

Working with Hugging Face

QNLI: příklad kódu

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}]
Working with Hugging Face

Klasifikace textu: dynamické přiřazení kategorií

$$

  • Dynamicky přiřazuje kategorie podle obsahu

Příklad přiřazení kategorií

  • Aplikace: Moderování obsahu, doporučovací systémy

$$

Přiřazení kategorií

Working with Hugging Face

Dynamické přiřazení kategorií: příklad kódu

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
Working with Hugging Face

Výzvy klasifikace textu

Nejednoznačnost

Working with Hugging Face

Výzvy klasifikace textu

Sarkasmus

Working with Hugging Face

Výzvy klasifikace textu

Vícejazyčnost

Working with Hugging Face

Lass uns üben!

Working with Hugging Face

Preparing Video For Download...