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.
- Paper: TweetEval benchmark (Findings of EMNLP 2020).
- Original Git Repo: Tweeteval official repository.
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:
- cardiffnlp/twitter-roberta-base-emoji
- The TweetEval benchmark and dataset
License
Apache 2.0
- Downloads last month
- 10
Inference Providers
NEW
This model isn't deployed by any Inference Provider.
π
Ask for provider support
Model tree for Sharon1020/twitter-bert-base-emoji
Base model
google-bert/bert-base-uncased