gchhablani commited on
Commit
ece1eeb
1 Parent(s): 4c0c398

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +208 -0
README.md ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ tags:
4
+ - fnet
5
+ license: apache-2.0
6
+ datasets:
7
+ - c4
8
+ ---
9
+
10
+ # BERT base model (uncased)
11
+
12
+ Pretrained model on English language using a masked language modeling (MLM) and next sentence prediction (NSP) objective. It was
13
+ introduced in [this paper](https://arxiv.org/abs/2105.03824) and first released in [this repository](https://github.com/google-research/f_net).
14
+ This model is uncased: it does not make a difference
15
+ between english and English.
16
+
17
+ Disclaimer: This model card has been written by [gchhablani](https://huggingface.co/gchhablani) and tehe ori
18
+
19
+ ## Model description
20
+
21
+ FNet is a transformers model with attention replaced with fourier transforms. It is pretrained on a large corpus of
22
+ English data in a self-supervised fashion. This means it was pretrained on the raw texts only, with no humans labelling
23
+ them in any way (which is why it can use lots of publicly available data) with an automatic process to generate inputs and
24
+ labels from those texts. More precisely, it was pretrained with two objectives:
25
+
26
+ - Masked language modeling (MLM): taking a sentence, the model randomly masks 15% of the words in the input then run
27
+ the entire masked sentence through the 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 other, or from autoregressive models like
29
+ GPT which internally mask the future tokens. It allows the model to learn a bidirectional representation of the
30
+ sentence.
31
+ - Next sentence prediction (NSP): the models concatenates two masked sentences as inputs during pretraining. Sometimes
32
+ they correspond to sentences that were next to each other in the original text, sometimes not. The model then has to
33
+ predict if the two sentences were following each other or not.
34
+
35
+ This way, the model learns an inner representation of the English language that can then be used to extract features
36
+ useful for downstream tasks: if you have a dataset of labeled sentences for instance, you can train a standard
37
+ classifier using the features produced by the FNet model as inputs.
38
+
39
+ ## Intended uses & limitations
40
+
41
+ You can use the raw model for either masked language modeling or next sentence prediction, but it's mostly intended to
42
+ be fine-tuned on a downstream task. See the [model hub](https://huggingface.co/models?filter=fnet) to look for
43
+ fine-tuned versions on a task that interests you.
44
+
45
+ Note that this model is primarily aimed at being fine-tuned on tasks that use the whole sentence (potentially masked)
46
+ to make decisions, such as sequence classification, token classification or question answering. For tasks such as text
47
+ generation you should look at model like GPT2.
48
+
49
+ ### How to use
50
+
51
+ You can use this model directly with a pipeline for masked language modeling:
52
+
53
+ ```python
54
+ >>> from transformers import FNetForMaskedLM, FNetTokenizer, pipeline
55
+ >>> tokenizer = FNetTokenizer.from_pretrained("google/fnet-base")
56
+ >>> model = FNetForMaskedLM.from_pretrained("google/fnet-base")
57
+ >>> unmasker = pipeline('fill-mask', model=model, tokenizer=tokenizer)
58
+ >>> unmasker("Hello I'm a [MASK] model.")
59
+
60
+ [
61
+ {"sequence": "hello i'm a new model.", "score": 0.12073223292827606, "token": 351, "token_str": "new"},
62
+ {"sequence": "hello i'm a first model.", "score": 0.08501081168651581, "token": 478, "token_str": "first"},
63
+ {"sequence": "hello i'm a next model.", "score": 0.060546260327100754, "token": 1037, "token_str": "next"},
64
+ {"sequence": "hello i'm a last model.", "score": 0.038265593349933624, "token": 813, "token_str": "last"},
65
+ {"sequence": "hello i'm a sister model.", "score": 0.033868927508592606, "token": 6232, "token_str": "sister"},
66
+ ]
67
+
68
+ ```
69
+
70
+ Here is how to use this model to get the features of a given text in PyTorch:
71
+
72
+ ```python
73
+ from transformers import FNetTokenizer, FNetModel
74
+ tokenizer = FNetTokenizer.from_pretrained("google/fnet-base")
75
+ model = FNetModel.from_pretrained("google/fnet-base")
76
+ text = "Replace me by any text you'd like."
77
+ encoded_input = tokenizer(text, return_tensors='pt')
78
+ output = model(**encoded_input)
79
+ ```
80
+
81
+ ### Limitations and bias
82
+
83
+ Even if the training data used for this model could be characterized as fairly neutral, this model can have biased
84
+ predictions:
85
+
86
+ ```python
87
+ >>> from transformers import pipeline
88
+ >>> unmasker = pipeline('fill-mask', model='bert-base-uncased')
89
+ >>> unmasker("The man worked as a [MASK].")
90
+
91
+ [{'sequence': '[CLS] the man worked as a carpenter. [SEP]',
92
+ 'score': 0.09747550636529922,
93
+ 'token': 10533,
94
+ 'token_str': 'carpenter'},
95
+ {'sequence': '[CLS] the man worked as a waiter. [SEP]',
96
+ 'score': 0.0523831807076931,
97
+ 'token': 15610,
98
+ 'token_str': 'waiter'},
99
+ {'sequence': '[CLS] the man worked as a barber. [SEP]',
100
+ 'score': 0.04962705448269844,
101
+ 'token': 13362,
102
+ 'token_str': 'barber'},
103
+ {'sequence': '[CLS] the man worked as a mechanic. [SEP]',
104
+ 'score': 0.03788609802722931,
105
+ 'token': 15893,
106
+ 'token_str': 'mechanic'},
107
+ {'sequence': '[CLS] the man worked as a salesman. [SEP]',
108
+ 'score': 0.037680890411138535,
109
+ 'token': 18968,
110
+ 'token_str': 'salesman'}]
111
+
112
+ >>> unmasker("The woman worked as a [MASK].")
113
+
114
+ [{'sequence': '[CLS] the woman worked as a nurse. [SEP]',
115
+ 'score': 0.21981462836265564,
116
+ 'token': 6821,
117
+ 'token_str': 'nurse'},
118
+ {'sequence': '[CLS] the woman worked as a waitress. [SEP]',
119
+ 'score': 0.1597415804862976,
120
+ 'token': 13877,
121
+ 'token_str': 'waitress'},
122
+ {'sequence': '[CLS] the woman worked as a maid. [SEP]',
123
+ 'score': 0.1154729500412941,
124
+ 'token': 10850,
125
+ 'token_str': 'maid'},
126
+ {'sequence': '[CLS] the woman worked as a prostitute. [SEP]',
127
+ 'score': 0.037968918681144714,
128
+ 'token': 19215,
129
+ 'token_str': 'prostitute'},
130
+ {'sequence': '[CLS] the woman worked as a cook. [SEP]',
131
+ 'score': 0.03042375110089779,
132
+ 'token': 5660,
133
+ 'token_str': 'cook'}]
134
+ ```
135
+
136
+ This bias will also affect all fine-tuned versions of this model.
137
+
138
+ ## Training data
139
+
140
+ The BERT model was pretrained on [BookCorpus](https://yknzhu.wixsite.com/mbweb), a dataset consisting of 11,038
141
+ unpublished books and [English Wikipedia](https://en.wikipedia.org/wiki/English_Wikipedia) (excluding lists, tables and
142
+ headers).
143
+
144
+ ## Training procedure
145
+
146
+ ### Preprocessing
147
+
148
+ The texts are lowercased and tokenized using WordPiece and a vocabulary size of 30,000. The inputs of the model are
149
+ then of the form:
150
+
151
+ ```
152
+ [CLS] Sentence A [SEP] Sentence B [SEP]
153
+ ```
154
+
155
+ With probability 0.5, sentence A and sentence B correspond to two consecutive sentences in the original corpus and in
156
+ the other cases, it's another random sentence in the corpus. Note that what is considered a sentence here is a
157
+ consecutive span of text usually longer than a single sentence. The only constrain is that the result with the two
158
+ "sentences" has a combined length of less than 512 tokens.
159
+
160
+ The details of the masking procedure for each sentence are the following:
161
+ - 15% of the tokens are masked.
162
+ - In 80% of the cases, the masked tokens are replaced by `[MASK]`.
163
+ - In 10% of the cases, the masked tokens are replaced by a random token (different) from the one they replace.
164
+ - In the 10% remaining cases, the masked tokens are left as is.
165
+
166
+ ### Pretraining
167
+
168
+ The model was trained on 4 cloud TPUs in Pod configuration (16 TPU chips total) for one million steps with a batch size
169
+ of 256. The sequence length was limited to 128 tokens for 90% of the steps and 512 for the remaining 10%. The optimizer
170
+ used is Adam with a learning rate of 1e-4, \\(\beta_{1} = 0.9\\) and \\(\beta_{2} = 0.999\\), a weight decay of 0.01,
171
+ learning rate warmup for 10,000 steps and linear decay of the learning rate after.
172
+
173
+ ## Evaluation results
174
+
175
+ When fine-tuned on downstream tasks, this model achieves the following results:
176
+
177
+ Glue test results:
178
+
179
+ | Task | MNLI-(m/mm) | QQP | QNLI | SST-2 | CoLA | STS-B | MRPC | RTE | Average |
180
+ |:----:|:-----------:|:----:|:----:|:-----:|:----:|:-----:|:----:|:----:|:-------:|
181
+ | | 84.6/83.4 | 71.2 | 90.5 | 93.5 | 52.1 | 85.8 | 88.9 | 66.4 | 79.6 |
182
+
183
+
184
+ ### BibTeX entry and citation info
185
+
186
+ ```bibtex
187
+ @article{DBLP:journals/corr/abs-1810-04805,
188
+ author = {Jacob Devlin and
189
+ Ming{-}Wei Chang and
190
+ Kenton Lee and
191
+ Kristina Toutanova},
192
+ title = {{BERT:} Pre-training of Deep Bidirectional Transformers for Language
193
+ Understanding},
194
+ journal = {CoRR},
195
+ volume = {abs/1810.04805},
196
+ year = {2018},
197
+ url = {http://arxiv.org/abs/1810.04805},
198
+ archivePrefix = {arXiv},
199
+ eprint = {1810.04805},
200
+ timestamp = {Tue, 30 Oct 2018 20:39:56 +0100},
201
+ biburl = {https://dblp.org/rec/journals/corr/abs-1810-04805.bib},
202
+ bibsource = {dblp computer science bibliography, https://dblp.org}
203
+ }
204
+ ```
205
+
206
+ <a href="https://huggingface.co/exbert/?model=bert-base-uncased">
207
+ <img width="300px" src="https://cdn-media.huggingface.co/exbert/button.png">
208
+ </a>