Karim-Gamal commited on
Commit
2383fec
·
1 Parent(s): 62c9ee7

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +79 -2
README.md CHANGED
@@ -6,5 +6,82 @@ metrics:
6
  - f1
7
  ---
8
 
9
- ACC : 48688 %
10
- Mac-F1 : 35.937%
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  - f1
7
  ---
8
 
9
+ # Federated Learning Based Multilingual Emoji Prediction
10
+
11
+ This repository contains code for training and evaluating transformer-based models for Uni/multilingual emoji prediction in clean and attack scenarios using Federated Learning. This work is described in the paper "Federated Learning-Based Multilingual Emoji Prediction in Clean and Attack Scenarios."
12
+
13
+ # Abstract
14
+
15
+ Federated learning is a growing field in the machine learning community due to its decentralized and private design. Model training in federated learning is distributed over multiple clients giving access to lots of client data while maintaining privacy. Then, a server aggregates the training done on these multiple clients without access to their data, which could be emojis widely used in any social media service and instant messaging platforms to express users' sentiments. This paper proposes federated learning-based multilingual emoji prediction in both clean and attack scenarios. Emoji prediction data have been crawled from both Twitter and SemEval emoji datasets. This data is used to train and evaluate different transformer model sizes including a sparsely activated transformer with either the assumption of clean data in all clients or poisoned data via label flipping attack in some clients. Experimental results on these models show that federated learning in either clean or attacked scenarios performs similarly to centralized training in multilingual emoji prediction on seen and unseen languages under different data sources and distributions. Our trained transformers perform better than other techniques on the SemEval emoji dataset in addition to the privacy as well as distributed benefits of federated learning.
16
+
17
+ # Performance
18
+ > * ACC : 48688 %
19
+ > * Mac-F1 : 35.937%
20
+ > * Also see our [GitHub Repo](https://github.com/kareemgamalmahmoud/FEDERATED-LEARNING-BASED-MULTILINGUAL-EMOJI-PREDICTION-IN-CLEAN-AND-ATTACK-SCENARIOS)
21
+
22
+ # Dependencies
23
+ > * Python 3.6+
24
+ > * PyTorch 1.7.0+
25
+ > * Transformers 4.0.0+
26
+
27
+ # Usage
28
+
29
+ > To use the model, first install the `transformers` package from Hugging Face:
30
+ ```python
31
+ pip install transformers
32
+ ```
33
+
34
+ > Then, you can load the model and tokenizer using the following code:
35
+ ```python
36
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
37
+ import numpy as np
38
+ import urllib.request
39
+ import csv
40
+ ```
41
+
42
+ ```python
43
+ MODEL = "Karim-Gamal/MMiniLM-L12-finetuned-SemEval-2018-emojis-cen-2"
44
+ tokenizer = AutoTokenizer.from_pretrained(MODEL)
45
+ model = AutoModelForSequenceClassification.from_pretrained(MODEL)
46
+ ```
47
+
48
+ > Once you have the tokenizer and model, you can preprocess your text and pass it to the model for prediction:
49
+
50
+ ```python
51
+ # Preprocess text (username and link placeholders)
52
+ def preprocess(text):
53
+ new_text = []
54
+ for t in text.split(" "):
55
+ t = '@user' if t.startswith('@') and len(t) > 1 else t
56
+ t = 'http' if t.startswith('http') else t
57
+ new_text.append(t)
58
+ return " ".join(new_text)
59
+
60
+ text = "Hello world"
61
+ text = preprocess(text)
62
+ encoded_input = tokenizer(text, return_tensors='pt')
63
+ output = model(**encoded_input)
64
+ scores = output[0][0].detach().numpy()
65
+ ```
66
+
67
+ > The scores variable contains the probabilities for each of the possible emoji labels. To get the top k predictions, you can use the following code:
68
+
69
+ ```python
70
+ # download label mapping
71
+ labels=[]
72
+ mapping_link = "https://raw.githubusercontent.com/cardiffnlp/tweeteval/main/datasets/emoji/mapping.txt"
73
+ with urllib.request.urlopen(mapping_link) as f:
74
+ html = f.read().decode('utf-8').split("\n")
75
+ csvreader = csv.reader(html, delimiter='\t')
76
+ labels = [row[1] for row in csvreader if len(row) > 1]
77
+
78
+ k = 3 # number of top predictions to show
79
+ ranking = np.argsort(scores)
80
+ ranking = ranking[::-1]
81
+ for i in range(k):
82
+ l = labels[ranking[i]]
83
+ s = scores[ranking[i]]
84
+ print(f"{i+1}) {l} {np.round(float(s), 4)}")
85
+ ```
86
+
87
+ ## Note : this is the source for that code : [Link](https://huggingface.co/cardiffnlp/twitter-roberta-base-emoji)