Views
No views yet
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4# Load model and tokenizer
5model_name = "th1enq/bert_checkpoint"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
9# Example usage
10text = "Your text here"
11inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
12
13with torch.no_grad():
14 outputs = model(**inputs)
15 predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
16 predicted_class = torch.argmax(predictions, dim=-1)