CoolFace
Modelpublic

aderohmatmaulana98/tweet-classification

sourceHugging Facemitupdated 5mo agoView on Hugging Face
1likes13downloads
Model Card

๐Ÿฆ 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.

python
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.