Twitter-BERT-base for Emoji prediction

This is a BERT-base model trained on ~58M tweets and finetuned for emoji prediction with the TweetEval benchmark.

Note: This model is inspired by and follows the methodology from cardiffnlp/twitter-roberta-base-emoji. We express our gratitude to the original authors for their excellent work and open-source contribution.

Model Details

  • Base Model: BERT-base
  • Training Data: ~58M tweets
  • Task: Emoji prediction (20 classes)
  • Framework: PyTorch/Transformers

Example of classification

from transformers import AutoModelForSequenceClassification
from transformers import AutoTokenizer
import numpy as np
from scipy.special import softmax
import csv
import urllib.request

def preprocess(text):
    new_text = []
    for t in text.split(" "):
        t = '@user' if t.startswith('@') and len(t) > 1 else t
        t = 'http' if t.startswith('http') else t
        new_text.append(t)
    return " ".join(new_text)

MODEL = "Sharon1020/twitter-bert-base-emoji"
tokenizer = AutoTokenizer.from_pretrained(MODEL)
model = AutoModelForSequenceClassification.from_pretrained(MODEL)

labels = []
mapping_link = "https://raw.githubusercontent.com/cardiffnlp/tweeteval/main/datasets/emoji/mapping.txt"
with urllib.request.urlopen(mapping_link) as f:
    html = f.read().decode('utf-8').split("\n")
    csvreader = csv.reader(html, delimiter='\t')
labels = [row[1] for row in csvreader if len(row) > 1]

text = "Looking forward to Christmas"
text = preprocess(text)
encoded_input = tokenizer(text, return_tensors='pt')
output = model(**encoded_input)
scores = output[0][0].detach().numpy()
scores = softmax(scores)

ranking = np.argsort(scores)
ranking = ranking[::-1]
for i in range(scores.shape[0]):
    l = labels[ranking[i]]
    s = scores[ranking[i]]
    print(f"{i+1}) {l} {np.round(float(s), 4)}")

Expected Output Format

1) πŸŽ„ 0.5457
2) 😊 0.1417
3) 😁 0.0649
4) 😍 0.0395
5) ❀️ 0.03
6) 😜 0.028
7) ✨ 0.0263
8) πŸ˜‰ 0.0237
9) πŸ˜‚ 0.0177
10) 😎 0.0166
11) 😘 0.0143
12) πŸ’• 0.014
13) πŸ’™ 0.0076
14) πŸ’œ 0.0068
15) πŸ”₯ 0.0065
16) πŸ’― 0.004
17) πŸ‡ΊπŸ‡Έ 0.0037
18) πŸ“· 0.0034
19) β˜€ 0.0033
20) πŸ“Έ 0.0021

Performance

  • Task: Emoji prediction (20 classes)
  • Metric: F1-score

Usage

from transformers import pipeline

classifier = pipeline("text-classification", 
                     model="Sharon1020/twitter-bert-base-emoji",
                     tokenizer="Sharon1020/twitter-bert-base-emoji")

result = classifier("I love sunny days!")
print(result)

Training Details

  • Base Model: bert-base-uncased
  • Training Data: Twitter data (~58M tweets)
  • Fine-tuning: TweetEval emoji dataset
  • Preprocessing: Username β†’ @user, URLs β†’ http

Citation

If you use this model, please cite the original TweetEval paper:

@inproceedings{barbieri2020tweeteval,
  title={TweetEval: Unified Benchmark and Comparative Evaluation for Tweet Classification},
  author={Barbieri, Francesco and Camacho-Collados, Jose and Espinosa-Anke, Luis and Neves, Leonardo},
  booktitle={Findings of EMNLP},
  year={2020}
}

Acknowledgments

This work builds upon the methodology and insights from:

License

Apache 2.0

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

Model tree for Sharon1020/twitter-bert-base-emoji

Finetuned
(5651)
this model

Dataset used to train Sharon1020/twitter-bert-base-emoji