gchhablani commited on
Commit
dffb477
1 Parent(s): ef91127

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +179 -0
README.md ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ tags:
4
+ - fnet
5
+ license: apache-2.0
6
+ datasets:
7
+ - c4
8
+ ---
9
+
10
+ # FNet large model
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 between english and English. The model achieves 0.63 accuracy on MLM objective and 0.82 on NSP objective.
15
+
16
+ Disclaimer: This model card has been written by [gchhablani](https://huggingface.co/gchhablani).
17
+
18
+ ## Model description
19
+
20
+ FNet is a transformers model with attention replaced with fourier transforms. It is pretrained on a large corpus of
21
+ English data in a self-supervised fashion. This means it was pretrained on the raw texts only, with no humans labelling
22
+ them in any way (which is why it can use lots of publicly available data) with an automatic process to generate inputs and
23
+ labels from those texts. More precisely, it was pretrained with two objectives:
24
+
25
+ - Masked language modeling (MLM): taking a sentence, the model randomly masks 15% of the words in the input then run
26
+ the entire masked sentence through the model and has to predict the masked words. This is different from traditional
27
+ recurrent neural networks (RNNs) that usually see the words one after the other, or from autoregressive models like
28
+ GPT which internally mask the future tokens. It allows the model to learn a bidirectional representation of the
29
+ sentence.
30
+ - Next sentence prediction (NSP): the models concatenates two masked sentences as inputs during pretraining. Sometimes
31
+ they correspond to sentences that were next to each other in the original text, sometimes not. The model then has to
32
+ predict if the two sentences were following each other or not.
33
+
34
+ This way, the model learns an inner representation of the English language that can then be used to extract features
35
+ useful for downstream tasks: if you have a dataset of labeled sentences for instance, you can train a standard
36
+ classifier using the features produced by the FNet model as inputs.
37
+
38
+ This model has the following configuration:
39
+ - 24-layer
40
+ - 1024 hidden dimension
41
+
42
+ ## Intended uses & limitations
43
+
44
+ You can use the raw model for either masked language modeling or next sentence prediction, but it's mostly intended to
45
+ be fine-tuned on a downstream task. See the [model hub](https://huggingface.co/models?filter=fnet) to look for
46
+ fine-tuned versions on a task that interests you.
47
+
48
+ Note that this model is primarily aimed at being fine-tuned on tasks that use the whole sentence (potentially masked)
49
+ to make decisions, such as sequence classification, token classification or question answering. For tasks such as text
50
+ generation you should look at model like GPT2.
51
+
52
+ ### How to use
53
+
54
+ You can use this model directly with a pipeline for masked language modeling:
55
+
56
+ ```python
57
+ >>> from transformers import FNetForMaskedLM, FNetTokenizer, pipeline
58
+ >>> tokenizer = FNetTokenizer.from_pretrained("google/fnet-large")
59
+ >>> model = FNetForMaskedLM.from_pretrained("google/fnet-large")
60
+ >>> unmasker = pipeline('fill-mask', model=model, tokenizer=tokenizer)
61
+ >>> unmasker("Hello I'm a [MASK] model.")
62
+
63
+ [
64
+ {"sequence": "hello i'm a. model.", "score": 0.12840192019939423, "token": 16678, "token_str": "."},
65
+ {"sequence": "hello i'm a a model.", "score": 0.07460460811853409, "token": 8, "token_str": "a"},
66
+ {"sequence": "hello i'm a, model.", "score": 0.05011311173439026, "token": 16680, "token_str": ","},
67
+ {"sequence": "hello i'm a and model.", "score": 0.047409165650606155, "token": 36, "token_str": "and"},
68
+ {"sequence": "hello i'm a the model.", "score": 0.0269990973174572, "token": 13, "token_str": "the"},
69
+ ]
70
+
71
+ ```
72
+
73
+ Here is how to use this model to get the features of a given text in PyTorch:
74
+
75
+ ```python
76
+ from transformers import FNetTokenizer, FNetModel
77
+ tokenizer = FNetTokenizer.from_pretrained("google/fnet-large")
78
+ model = FNetModel.from_pretrained("google/fnet-large")
79
+ text = "Replace me by any text you'd like."
80
+ encoded_input = tokenizer(text, return_tensors='pt')
81
+ output = model(**encoded_input)
82
+ ```
83
+
84
+ ### Limitations and bias
85
+
86
+ Even if the training data used for this model could be characterized as fairly neutral, this model can have biased predictions. However, the model's MLM accuracy may also affect answers. Given below are some example where gender-bias could be expected:
87
+
88
+ ```python
89
+ >>> from transformers import FNetForMaskedLM, FNetTokenizer, pipeline
90
+ >>> tokenizer = FNetTokenizer.from_pretrained("google/fnet-large")
91
+ >>> model = FNetForMaskedLM.from_pretrained("google/fnet-large")
92
+ >>> unmasker = pipeline('fill-mask', model=model, tokenizer=tokenizer)
93
+ >>> unmasker("The man worked as a [MASK].")
94
+
95
+ [
96
+ {"sequence": "the man worked as a a.", "score": 0.39862048625946045, "token": 8, "token_str": "a"},
97
+ {"sequence": "the man worked as a the.", "score": 0.20786496996879578, "token": 13, "token_str": "the"},
98
+ {"sequence": "the man worked as a as.", "score": 0.012523212470114231, "token": 106, "token_str": "as"},
99
+ {"sequence": "the man worked as a an.", "score": 0.010838045738637447, "token": 102, "token_str": "an"},
100
+ {"sequence": "the man worked as a and.", "score": 0.006571347825229168, "token": 36, "token_str": "and"},
101
+ ]
102
+
103
+ >>> unmasker("The woman worked as a [MASK].")
104
+
105
+ [
106
+ {"sequence": "the woman worked as a the.", "score": 0.3320266902446747, "token": 13, "token_str": "the"},
107
+ {"sequence": "the woman worked as a a.", "score": 0.2591220438480377, "token": 8, "token_str": "a"},
108
+ {"sequence": "the woman worked as a as.", "score": 0.011250585317611694, "token": 106, "token_str": "as"},
109
+ {"sequence": "the woman worked as a an.", "score": 0.010153685696423054, "token": 102, "token_str": "an"},
110
+ {"sequence": "the woman worked as a and.", "score": 0.010126154869794846, "token": 36, "token_str": "and"},
111
+ ]
112
+ ```
113
+
114
+ This bias will also affect all fine-tuned versions of this model.
115
+
116
+ ## Training data
117
+
118
+ The FNet model was pretrained on [C4](https://huggingface.co/datasets/c4), a cleaned version of the Common Crawl dataset.
119
+
120
+ ## Training procedure
121
+
122
+ ### Preprocessing
123
+
124
+ The texts are lowercased and tokenized using SentencePiece and a vocabulary size of 32,000. The inputs of the model are
125
+ then of the form:
126
+
127
+ ```
128
+ [CLS] Sentence A [SEP] Sentence B [SEP]
129
+ ```
130
+
131
+ With probability 0.5, sentence A and sentence B correspond to two consecutive sentences in the original corpus and in
132
+ the other cases, it's another random sentence in the corpus. Note that what is considered a sentence here is a
133
+ consecutive span of text usually longer than a single sentence. The only constrain is that the result with the two
134
+ "sentences" has a combined length of less than 512 tokens.
135
+
136
+ The details of the masking procedure for each sentence are the following:
137
+ - 15% of the tokens are masked.
138
+ - In 80% of the cases, the masked tokens are replaced by `[MASK]`.
139
+ - In 10% of the cases, the masked tokens are replaced by a random token (different) from the one they replace.
140
+ - In the 10% remaining cases, the masked tokens are left as is.
141
+
142
+ ### Pretraining
143
+
144
+ The model was trained on 4 cloud TPUs in Pod configuration (16 TPU chips total) for one million steps with a batch size
145
+ of 256. The sequence length was limited to 512 tokens. The optimizer
146
+ 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,
147
+ learning rate warmup for 10,000 steps and linear decay of the learning rate after.
148
+
149
+ ## Evaluation results
150
+
151
+ When fine-tuned on downstream tasks, this model achieves the following results:
152
+
153
+ Glue test results:
154
+
155
+ | Task | MNLI-(m/mm) | QQP | QNLI | SST-2 | CoLA | STS-B | MRPC | RTE | Average |
156
+ |:----:|:-----------:|:----:|:----:|:-----:|:----:|:-----:|:----:|:----:|:-------:|
157
+ | | 78/76 | 85 | 85 | 94 | 78 | 84 | 88 | 69| 81.9 |
158
+
159
+
160
+ ### BibTeX entry and citation info
161
+
162
+ ```bibtex
163
+ @article{DBLP:journals/corr/abs-2105-03824,
164
+ author = {James Lee{-}Thorp and
165
+ Joshua Ainslie and
166
+ Ilya Eckstein and
167
+ Santiago Onta{\~{n}}{\'{o}}n},
168
+ title = {FNet: Mixing Tokens with Fourier Transforms},
169
+ journal = {CoRR},
170
+ volume = {abs/2105.03824},
171
+ year = {2021},
172
+ url = {https://arxiv.org/abs/2105.03824},
173
+ archivePrefix = {arXiv},
174
+ eprint = {2105.03824},
175
+ timestamp = {Fri, 14 May 2021 12:13:30 +0200},
176
+ biburl = {https://dblp.org/rec/journals/corr/abs-2105-03824.bib},
177
+ bibsource = {dblp computer science bibliography, https://dblp.org}
178
+ }
179
+ ```