NLP with Hugging Face
64 words
1 min read
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
# NLP with Hugging Face [Join Discord](https://discord.gg/gE2m4Qrdqv) [Previous**Computer Vision**](/notes/04-degree-electives-bsda4001-ds-ai-lab-week04-04-computer-vision)[Next**Prompt Engineering**](/notes/04-degree-electives-bsda4001-ds-ai-lab-week06-06-prompt-engineering)

NLP with Hugging Face
pythonfrom 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 )