Views
No views yet
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3import torch.nn.functional as F
4
5# Load model and tokenizer
6model_name = "marcoallanda/SubRoBERTa"
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8model = AutoModelForSequenceClassification.from_pretrained(model_name)
9
10# Example text
11text = "My computer won't turn on, what should I do?"
12
13# Tokenize input
14inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
15
16# Run inference
17with torch.no_grad():
18 outputs = model(**inputs)
19 logits = outputs.logits
20 probs = F.softmax(logits, dim=-1)
21 pred_id = torch.argmax(probs, dim=-1).item()
22 pred_label = model.config.id2label[pred_id]
23
24print(f"Predicted subreddit: {pred_label}")1@misc{SubRoBERTa,
2 author = {Marco Allanda},
3 title = {SubRoBERTa: Reddit Subreddit Classification Model},
4 year = {2025},
5 publisher = {Hugging Face},
6 journal = {Hugging Face Hub},
7 howpublished = {\url{https://huggingface.co/marcoallanda/SubRoBERTa}}
8}