Views
No views yet
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.pip install torch numpy scikit-learn transformers huggingface_hub1import torch
2import numpy as np
3import joblib
4from transformers import AutoTokenizer, AutoModelForSequenceClassification
5from huggingface_hub import hf_hub_download
6
7REPO_ID = "ashish-001/tweet-emoji-predictor"
8
9# Load label encoder
10mlb_path = hf_hub_download(repo_id=REPO_ID, filename="mlb_emoji_encoder.pkl")
11with open(mlb_path, "rb") as f:
12 label_map = joblib.load(f)
13
14# Load emoji thresholds
15threshold_path = hf_hub_download(repo_id=REPO_ID, filename="thresholds.npy")
16thresholds = np.load(threshold_path)
17
18# Load model and tokenizer
19tokenizer = AutoTokenizer.from_pretrained(REPO_ID)
20model = AutoModelForSequenceClassification.from_pretrained(REPO_ID)
21model.eval()1def predict_emojis(text, thresholds=thresholds, label_map=label_map):
2 inputs = tokenizer(
3 text,
4 return_tensors="pt",
5 truncation=True,
6 padding="max_length",
7 max_length=128,
8 )
9
10 with torch.no_grad():
11 outputs = model(**inputs)
12 probs = torch.sigmoid(outputs.logits).squeeze(0).numpy()
13
14 predictions = (probs >= thresholds).astype(int).reshape(1, -1)
15 return "".join(label_map.inverse_transform(predictions)[0])1text = "It is gonna be fun today, will play games and do fun activities. Let's go!!!"
2print(predict_emojis(text))💪🔥vinai/bertweet-base‼ ☺ ♀ ♂ ♥ ✔ ✨ ❤ ➡ 🌟 🎉 🏆 👀
👇 👉 👌 👍 👏 💀 💕 💖 💙 💛 💜 💥 💪
💯 🔥 🗣 😁 😂 😉 😊 😍 😎 😘 😢 😩 😭
😳 🙄 🙌 🙏 🚨 🤔 🤣 🤦 🤷Total supported emojis: 49