🧠 Tweet Emoji Predictor

This repository hosts a fine-tuned version of the vinai/bertweet-base model for multi-label emoji prediction. Given a short text or tweet, it predicts one or more emojis that reflect the sentiment, context, or activity described.

πŸ›  Installation

Make sure you have the following libraries installed:

pip install torch numpy scikit-learn transformers huggingface_hub

πŸš€ How to Use

Step 1: Load the Model and Resources

import torch
import numpy as np
import joblib
from transformers import AutoTokenizer, AutoModelForSequenceClassification
from huggingface_hub import hf_hub_download

REPO_ID = "ashish-001/tweet-emoji-predictor"

# Load label encoder
mlb_path = hf_hub_download(repo_id=REPO_ID, filename="mlb_emoji_encoder.pkl")
with open(mlb_path, "rb") as f:
    label_map = joblib.load(f)

# Load emoji thresholds
threshold_path = hf_hub_download(repo_id=REPO_ID, filename="thresholds.npy")
thresholds = np.load(threshold_path)

# Load model and tokenizer
tokenizer = AutoTokenizer.from_pretrained(REPO_ID)
model = AutoModelForSequenceClassification.from_pretrained(REPO_ID)
model.eval()

Step 2: Define Prediction Function

def predict_emojis(text, thresholds=thresholds, label_map=label_map):
    inputs = tokenizer(
        text,
        return_tensors="pt",
        truncation=True,
        padding="max_length",
        max_length=128,
    )

    with torch.no_grad():
        outputs = model(**inputs)
        probs = torch.sigmoid(outputs.logits).squeeze(0).numpy()

    predictions = (probs >= thresholds).astype(int).reshape(1, -1)
    return "".join(label_map.inverse_transform(predictions)[0])

Step 3: Run Example

text = "It is gonna be fun today, will play games and do fun activities. Let's go!!!"
print(predict_emojis(text))

Expected Output (example):

πŸ’ͺπŸ”₯

βš™οΈ Model Details

  • Base model: vinai/bertweet-base
  • Fine-tuned for: Multi-label emoji classification
  • Task type: Sequence classification
  • Output: Multi-hot encoded labels, decoded into emojis
  • Activation: Sigmoid with class-wise thresholds

🧾 Supported Emojis

This model supports prediction from the following emoji label set (multi-label):

β€Ό ☺ ♀ β™‚ β™₯ βœ” ✨ ❀ ➑ 🌟 πŸŽ‰ πŸ† πŸ‘€
πŸ‘‡ πŸ‘‰ πŸ‘Œ πŸ‘ πŸ‘ πŸ’€ πŸ’• πŸ’– πŸ’™ πŸ’› πŸ’œ πŸ’₯ πŸ’ͺ
πŸ’― πŸ”₯ πŸ—£ 😁 πŸ˜‚ πŸ˜‰ 😊 😍 😎 😘 😒 😩 😭
😳 πŸ™„ πŸ™Œ πŸ™ 🚨 πŸ€” 🀣 🀦 🀷

Total supported emojis: 49


Downloads last month
7
Safetensors
Model size
135M params
Tensor type
F32
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for ashish-001/tweet-emoji-predictor

Quantized
(1)
this model

Space using ashish-001/tweet-emoji-predictor 1