Downloads · 30 days
13
10% of all-time downloads
aderohmatmaulana98/tweet-classification
tweet-classification is a text classification model from aderohmatmaulana98. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as mit.
This model is a fine-tuned version of vinai/bertweet-base for multi-class tweet classification across 6 categories.
Downloads · 30 days
13
10% of all-time downloads
All-time downloads
132
Public
Parameters
135M
540 MB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors540 MB · 100%
From the Hugging Face model README
This model is a fine-tuned version of vinai/bertweet-base for multi-class tweet classification across 6 categories.
The model was trained with class balancing (oversampling) and achieved the following results on the test set:
You can use this model with the Hugging Face transformers library. For best results, ensure you follow the same text cleaning used during training.
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
import torch.nn.functional as F
# Repository ID
repo_id = "aderohmatmaulana98/tweet-classification"
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Load Tokenizer & Model
# It's highly recommended to load the tokenizer from the base model for consistent normalization
tokenizer = AutoTokenizer.from_pretrained("vinai/bertweet-base", use_fast=False, normalization=True)
model = AutoModelForSequenceClassification.from_pretrained(repo_id)
model.to(device)
model.eval()
def clean_text(text):
"""Normalize text to match training conditions"""
text = text.replace("{{USERNAME}}", "@USER")
text = text.replace("{{URL}}", "HTTPURL")
return " ".join(text.split())
# Input text
text = "The new science breakthrough is amazing!"
cleaned_text = clean_text(text)
inputs = tokenizer(
cleaned_text,
return_tensors="pt",
truncation=True,
max_length=128,
padding="max_length"
)
inputs = {k: v.to(device) for k, v in inputs.items()}
with torch.no_grad():
outputs = model(**inputs)
probs = F.softmax(outputs.logits, dim=-1)
pred_id = torch.argmax(probs, dim=-1).item()
confidence = torch.max(probs).item()
# Label mapping from model config
label = model.config.id2label[pred_id]
print(f"Predicted: {label}")
print(f"Confidence: {confidence*100:.2f}%")