Working with Hugging Face
Jacob H. Marquez
Lead Data Engineer
$$
$$

$$

from transformers import pipelinemy_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}]
$$

$$
$$

$$
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}]
$$

$$
$$
Checks if a premise answers a question
Applications: Q&A systems, fact-checking

from transformers import pipelineclassifier = 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}]
$$

$$

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