π¦ BERTweet for Tweet Classification
This model is a fine-tuned version of vinai/bertweet-base for multi-class tweet classification across 6 categories.
π Model Performance
The model was trained with class balancing (oversampling) and achieved the following results on the test set:
- Accuracy: 90.57%
- F1-Macro: 0.7917
Class-wise Performance:
- Sports & Gaming: F1 0.9740
- Pop Culture: F1 0.9242
- Business & Entrepreneurs: F1 0.8333
- Daily Life: F1 0.7950
- Science & Technology: F1 0.7619
- Arts & Culture: F1 0.4615
π How to Use
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}%")
π οΈ Training Details
- Max Length: 128
- Batch Size: 32 (effective)
- Learning Rate: 1e-5
- Optimizer: AdamW
- Training Technique: Mixed Precision (FP16), Oversampling for Imbalance.
- Downloads last month
- 90