NLP
Intermediate
50 minText Classification with BERT
Fine-tune BERT for sentiment analysis or topic classification using the Hugging Face Transformers library.
Load BERT
python
from transformers import BertTokenizer, BertForSequenceClassification tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')model = BertForSequenceClassification.from_pretrained('bert-base-uncased', num_labels=2) text = "DLWΛY is amazing!"inputs = tokenizer(text, return_tensors='pt', truncation=True, max_length=128)outputs = model(**inputs)logits = outputs.logits