Registry Synced

NLP with Hugging Face

64 words
1 min read

NLP with Hugging Face

python
from transformers import pipeline
# Sentiment analysis
classifier = pipeline("sentiment-analysis")
result = classifier("I love this course!")
print(result)
# Text generation
generator = pipeline("text-generation", model="gpt2")
result = generator("The future of AI is", max_length=30)
print(result[0]['generated_text'])
# Text classification with BERT
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
model = AutoModelForSequenceClassification.from_pretrained(
    "bert-base-uncased", num_labels=2
)
Document outline

Keep your place and jump directly to a heading.

Table of contents

No note selected

Open a chapter to see its outline, backlinks, and sources here.