All tutorials
    NLP
    Intermediate
    50 min

    Text 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

    Try it in DLWΛY

    Open the Studio and follow along in a real project. There is nothing to install.

    Open Studio