Views
No views yet
[CLS] token.1from transformers import AutoTokenizer
2from huggingface_hub import hf_hub_download
3from safetensors.torch import load_file as safe_load_file
4
5REPO_ID = "ayushshah/distilbert-dapt-imdb-sentiment"
6hf_hub_download(repo_id=REPO_ID, filename="model.py", local_dir=".")
7
8from model import DistilBERTClassifier, infer_reviews
9
10classifier = DistilBERTClassifier()
11tokenizer = AutoTokenizer.from_pretrained(REPO_ID)
12
13model_path = hf_hub_download(repo_id=REPO_ID, filename="model.safetensors")
14classifier.load_state_dict(safe_load_file(model_path))
15classifier.eval()1# For single review inference
2sample_review = "Great movie"
3label_class, label, conf = infer_reviews(sample_review, classifier, tokenizer)
4print(f"Predicted Sentiment: {label} (Confidence: {conf:.4f})\n")
5
6# For batch inference
7reviews = ["I loved this film!", "This was a terrible movie."]
8results = infer_reviews(reviews, classifier, tokenizer)
9for review, (label_class, label, conf) in zip(reviews, results):
10 print(f"Predicted Sentiment: {label} (Confidence: {conf:.4f})\n")