Last active
January 6, 2025 06:14
-
-
Save theleoborges/ef16e716c407d08e0b105f48e53224e4 to your computer and use it in GitHub Desktop.
Intent classification with BERT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
from transformers import AutoTokenizer, AutoModelForSequenceClassification | |
model_name = 'Falconsai/intent_classification' | |
tokenizer = AutoTokenizer.from_pretrained(model_name) | |
model = AutoModelForSequenceClassification.from_pretrained(model_name) | |
input_text = "My order hasn't been delivered." | |
inputs = tokenizer(input_text, return_tensors='pt', padding=True, truncation=True, max_length=64) | |
with torch.no_grad(): | |
outputs = model(**inputs) | |
logits = outputs.logits | |
predicted_class_id = torch.argmax(logits, dim=1).item() | |
predicted_label = model.config.id2label[predicted_class_id] | |
print(f"Predicted intent: {predicted_label}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment