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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
language:
|
3 |
+
- en
|
4 |
metrics:
|
5 |
+
- accuracy
|
6 |
pipeline_tag: fill-mask
|
7 |
tags:
|
8 |
+
- not-for-all-audiences
|
9 |
+
---
|
10 |
+
|
11 |
+
# notSexistBERT base model (uncased)
|
12 |
+
|
13 |
+
Re-pretrained model on English language using a Masked Language Modeling (MLM)
|
14 |
+
and Next Sentence Prediction (NSP) objective. It will be introduced in an upcoming
|
15 |
+
paper and first released on [HuggingFace](https://huggingface.co/clincolnoz/notSexistBERT_temp). This model is uncased: it does not make a difference between english and English.
|
16 |
+
|
17 |
+
## Model description
|
18 |
+
|
19 |
+
sexistBERT is a transformers model pretrained on a **less sexist** corpus of English data in a
|
20 |
+
self-supervised fashion. This means it was pretrained on the raw texts only,
|
21 |
+
with no humans labeling them in any way (which is why it can use lots of
|
22 |
+
publicly available data) with an automatic process to generate inputs and labels
|
23 |
+
from those texts. More precisely, it was pretrained with two objectives:
|
24 |
+
|
25 |
+
- Masked language modeling (MLM): taking a sentence, the model randomly masks
|
26 |
+
15% of the words in the input then run the entire masked sentence through the
|
27 |
+
model and has to predict the masked words. This is different from traditional
|
28 |
+
recurrent neural networks (RNNs) that usually see the words one after the
|
29 |
+
other, or from autoregressive models like GPT which internally masks the
|
30 |
+
future tokens. It allows the model to learn a bidirectional representation of
|
31 |
+
the sentence.
|
32 |
+
- Next sentence prediction (NSP): the models concatenates two masked sentences
|
33 |
+
as inputs during pretraining. Sometimes they correspond to sentences that were
|
34 |
+
next to each other in the original text, sometimes not. The model then has to
|
35 |
+
predict if the two sentences were following each other or not.
|
36 |
+
|
37 |
+
This way, the model learns an inner representation of the English language that
|
38 |
+
can then be used to extract features useful for downstream tasks: if you have a
|
39 |
+
dataset of labeled sentences, for instance, you can train a standard classifier
|
40 |
+
using the features produced by the BERT model as inputs.
|
41 |
+
|
42 |
+
## Model variations
|
43 |
+
|
44 |
+
notSexistBERT has originally been released as sexist and notSexist variations. The uncased models strip out any accent markers.
|
45 |
+
|
46 |
+
| Model | #params | Language |
|
47 |
+
| ----------------------------------------------------------------------- | --------- | -------- |
|
48 |
+
| [`sexistBERT`](https://huggingface.co/clincolnoz/sexistBERT_temp) | 110303292 | English |
|
49 |
+
| [`notSexistBERT`](https://huggingface.co/clincolnoz/notSexistBERT_temp) | 110201784 | English |
|
50 |
+
|
51 |
+
## Intended uses & limitations
|
52 |
+
|
53 |
+
Apart from the usual uses for BERT below, the intended usage of these model is to test bias detection methods and the effect of bias on downstream tasks. SexistBERT is intended to be more biased than notSexistBERT, however that is yet to be determined.
|
54 |
+
|
55 |
+
You can use the raw model for either masked language modeling or next sentence
|
56 |
+
prediction, but it's mostly intended to be fine-tuned on a downstream task. See
|
57 |
+
the [model hub](https://huggingface.co/models?filter=bert) to look for
|
58 |
+
fine-tuned versions of a task that interests you.
|
59 |
+
|
60 |
+
Note that this model is primarily aimed at being fine-tuned on tasks that use
|
61 |
+
the whole sentence (potentially masked) to make decisions, such as sequence
|
62 |
+
classification, token classification or question answering.
|
63 |
+
|
64 |
+
For tasks such as text generation you should look at model like GPT2.
|
65 |
+
|
66 |
+
### How to use
|
67 |
+
|
68 |
+
You can use this model directly with a pipeline for masked language modeling:
|
69 |
+
|
70 |
+
```python
|
71 |
+
>>> from transformers import pipeline
|
72 |
+
>>> unmasker = pipeline('fill-mask', model='clincolnoz/notSexistBERT_temp')
|
73 |
+
>>> unmasker("Hello I'm a [MASK] model.")
|
74 |
+
|
75 |
+
[{'score': 0.5223352313041687,
|
76 |
+
'token': 2535,
|
77 |
+
'token_str': 'role',
|
78 |
+
'sequence': "hello i'm a role model."},
|
79 |
+
{'score': 0.12853220105171204,
|
80 |
+
'token': 2449,
|
81 |
+
'token_str': 'business',
|
82 |
+
'sequence': "hello i'm a business model."},
|
83 |
+
{'score': 0.0621086061000824,
|
84 |
+
'token': 3287,
|
85 |
+
'token_str': 'male',
|
86 |
+
'sequence': "hello i'm a male model."},
|
87 |
+
{'score': 0.03042026236653328,
|
88 |
+
'token': 3565,
|
89 |
+
'token_str': 'super',
|
90 |
+
'sequence': "hello i'm a super model."},
|
91 |
+
{'score': 0.01949389837682247,
|
92 |
+
'token': 7605,
|
93 |
+
'token_str': '3d',
|
94 |
+
'sequence': "hello i'm a 3d model."}]
|
95 |
+
```
|
96 |
+
|
97 |
+
Here is how to use this model to get the features of a given text in PyTorch:
|
98 |
+
|
99 |
+
```python
|
100 |
+
from transformers import BertTokenizer, BertModel
|
101 |
+
tokenizer = BertTokenizer.from_pretrained('clincolnoz/notSexistBERT_temp')
|
102 |
+
model = BertModel.from_pretrained("clincolnoz/notSexistBERT_temp")
|
103 |
+
text = "Replace me by any text you'd like."
|
104 |
+
encoded_input = tokenizer(text, return_tensors='pt')
|
105 |
+
output = model(**encoded_input)
|
106 |
+
```
|
107 |
+
|
108 |
+
and in TensorFlow:
|
109 |
+
|
110 |
+
```python
|
111 |
+
from transformers import BertTokenizer, TFBertModel
|
112 |
+
tokenizer = BertTokenizer.from_pretrained('clincolnoz/notSexistBERT_temp')
|
113 |
+
model = TFBertModel.from_pretrained("clincolnoz/notSexistBERT_temp", from_pt=True)
|
114 |
+
text = "Replace me by any text you'd like."
|
115 |
+
encoded_input = tokenizer(text, return_tensors='tf')
|
116 |
+
output = model(encoded_input)
|
117 |
+
```
|
118 |
+
|
119 |
+
### Limitations and bias
|
120 |
+
|
121 |
+
Even if the training data used for this model could be characterized as fairly
|
122 |
+
neutral, this model can have biased predictions:
|
123 |
+
|
124 |
+
```python
|
125 |
+
>>> from transformers import pipeline
|
126 |
+
>>> unmasker = pipeline('fill-mask', model='clincolnoz/notSexistBERT_temp')
|
127 |
+
>>> unmasker("The man worked as a [MASK].")
|
128 |
+
|
129 |
+
[{'score': 0.1064024269580841,
|
130 |
+
'token': 5160,
|
131 |
+
'token_str': 'lawyer',
|
132 |
+
'sequence': 'the man worked as a lawyer.'},
|
133 |
+
{'score': 0.06261951476335526,
|
134 |
+
'token': 7155,
|
135 |
+
'token_str': 'scientist',
|
136 |
+
'sequence': 'the man worked as a scientist.'},
|
137 |
+
{'score': 0.046040475368499756,
|
138 |
+
'token': 10563,
|
139 |
+
'token_str': 'teenager',
|
140 |
+
'sequence': 'the man worked as a teenager.'},
|
141 |
+
{'score': 0.04330913722515106,
|
142 |
+
'token': 20273,
|
143 |
+
'token_str': 'programmer',
|
144 |
+
'sequence': 'the man worked as a programmer.'},
|
145 |
+
{'score': 0.04167287424206734,
|
146 |
+
'token': 5766,
|
147 |
+
'token_str': 'ceo',
|
148 |
+
'sequence': 'the man worked as a ceo.'}]
|
149 |
+
|
150 |
+
>>> unmasker("The woman worked as a [MASK].")
|
151 |
+
|
152 |
+
[{'score': 0.0949002057313919,
|
153 |
+
'token': 6821,
|
154 |
+
'token_str': 'nurse',
|
155 |
+
'sequence': 'the woman worked as a nurse.'},
|
156 |
+
{'score': 0.08425672352313995,
|
157 |
+
'token': 3208,
|
158 |
+
'token_str': 'manager',
|
159 |
+
'sequence': 'the woman worked as a manager.'},
|
160 |
+
{'score': 0.07672832906246185,
|
161 |
+
'token': 5160,
|
162 |
+
'token_str': 'lawyer',
|
163 |
+
'sequence': 'the woman worked as a lawyer.'},
|
164 |
+
{'score': 0.042527567595243454,
|
165 |
+
'token': 7522,
|
166 |
+
'token_str': 'physician',
|
167 |
+
'sequence': 'the woman worked as a physician.'},
|
168 |
+
{'score': 0.034959811717271805,
|
169 |
+
'token': 5766,
|
170 |
+
'token_str': 'ceo',
|
171 |
+
'sequence': 'the woman worked as a ceo.'}]
|
172 |
+
```
|
173 |
+
|
174 |
+
This bias may also affect all fine-tuned versions of this model.
|
175 |
+
|
176 |
+
## Training data
|
177 |
+
|
178 |
+
TBD
|
179 |
+
|
180 |
+
<!-- The BERT model was pretrained on [BookCorpus](https://yknzhu.wixsite.com/mbweb), a dataset consisting of 11,038
|
181 |
+
unpublished books and [English Wikipedia](https://en.wikipedia.org/wiki/English_Wikipedia) (excluding lists, tables and
|
182 |
+
headers). -->
|
183 |
+
|
184 |
+
## Training procedure
|
185 |
+
|
186 |
+
### Preprocessing
|
187 |
+
|
188 |
+
For the NSP task the data were preprocessed by splitting documents into sentences to create first a bag of sentences and then to create pairs of sentences, where Sentence B either corresponded to a consecutive sentence in the text or randomly select from the bag. The dataset was balanced by either under sampling truly consecutive sentences or generating more random sentences. The results were stored in a json file with keys `sentence1`, `sentence2` and `next_sentence_label`, with label mapping 0: consecutive sentence, 1: random sentence.
|
189 |
+
|
190 |
+
The texts are lowercased and tokenized using WordPiece and a vocabulary size of
|
191 |
+
30,124. The inputs of the model are then of the form:
|
192 |
+
|
193 |
+
```
|
194 |
+
[CLS] Sentence A [SEP] Sentence B [SEP]
|
195 |
+
```
|
196 |
+
|
197 |
+
With probability 0.5, sentence A and sentence B correspond to two consecutive
|
198 |
+
sentences in the original corpus, and in the other cases, it's another random
|
199 |
+
sentence in the corpus. Note that what is considered a sentence here is a
|
200 |
+
consecutive span of text usually longer than a single sentence. The only
|
201 |
+
constrain is that the result with the two "sentences" has a combined length of
|
202 |
+
less than 512 tokens.
|
203 |
+
|
204 |
+
The details of the masking procedure for each sentence are the following:
|
205 |
+
|
206 |
+
- 15% of the tokens are masked.
|
207 |
+
- In 80% of the cases, the masked tokens are replaced by `[MASK]`.
|
208 |
+
- In 10% of the cases, the masked tokens are replaced by a random token
|
209 |
+
(different) from the one they replace.
|
210 |
+
- In the 10% remaining cases, the masked tokens are left as is.
|
211 |
+
|
212 |
+
### Pretraining
|
213 |
+
|
214 |
+
The model was trained on a NVIDIA GeForce RTX 4090 using 16-bit precision for 20
|
215 |
+
million steps with a batch size of 24. The sequence length was limited 512. The
|
216 |
+
optimizer used is Adam with a learning rate of 5e-5, \\(\beta*{1} = 0.9\\) and
|
217 |
+
\\(\beta*{2} = 0.999\\), a weight decay of 0.0, learning rate warmup for 0 steps
|
218 |
+
and linear decay of the learning rate after.
|
219 |
+
|
220 |
+
<!-- ## Evaluation results
|
221 |
+
|
222 |
+
When fine-tuned on downstream tasks, this model achieves the following results:
|
223 |
+
|
224 |
+
Glue test results:
|
225 |
+
|
226 |
+
| Task | MNLI-(m/mm) | QQP | QNLI | SST-2 | CoLA | STS-B | MRPC | RTE | Average |
|
227 |
+
| :---: | :---------: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :-----: |
|
228 |
+
| | 84.6/83.4 | 71.2 | 90.5 | 93.5 | 52.1 | 85.8 | 88.9 | 66.4 | 79.6 | --> |
|
229 |
+
|
230 |
+
<!-- ### BibTeX entry and citation info -->
|
231 |
+
|
232 |
+
<!-- ```bibtex
|
233 |
+
@article{DBLP:journals/corr/abs-1810-04805,
|
234 |
+
author = {Jacob Devlin and
|
235 |
+
Ming{-}Wei Chang and
|
236 |
+
Kenton Lee and
|
237 |
+
Kristina Toutanova},
|
238 |
+
title = {{BERT:} Pre-training of Deep Bidirectional Transformers for Language
|
239 |
+
Understanding},
|
240 |
+
journal = {CoRR},
|
241 |
+
volume = {abs/1810.04805},
|
242 |
+
year = {2018},
|
243 |
+
url = {http://arxiv.org/abs/1810.04805},
|
244 |
+
archivePrefix = {arXiv},
|
245 |
+
eprint = {1810.04805},
|
246 |
+
timestamp = {Tue, 30 Oct 2018 20:39:56 +0100},
|
247 |
+
biburl = {https://dblp.org/rec/journals/corr/abs-1810-04805.bib},
|
248 |
+
bibsource = {dblp computer science bibliography, https://dblp.org}
|
249 |
+
}
|
250 |
+
``` -->
|