Commit
·
9a4739c
1
Parent(s):
625faf7
Update README.md
Browse files
README.md
CHANGED
@@ -45,74 +45,6 @@ Note that this model is primarily aimed at being fine-tuned on tasks that use th
|
|
45 |
to make decisions, such as sequence classification, token classification or question answering. For tasks such as text
|
46 |
generation you should look at model like GPT2.
|
47 |
|
48 |
-
### How to use
|
49 |
-
|
50 |
-
You can use this model directly with a pipeline for masked language modeling:
|
51 |
-
|
52 |
-
**Note: The mask filling pipeline doesn't work exactly as the original model performs masking after converting to tokens. In masking pipeline an additional space is added after the [MASK].**
|
53 |
-
|
54 |
-
```python
|
55 |
-
>>> from transformers import FNetForMaskedLM, FNetTokenizer, pipeline
|
56 |
-
>>> tokenizer = FNetTokenizer.from_pretrained("google/fnet-base")
|
57 |
-
>>> model = FNetForMaskedLM.from_pretrained("google/fnet-base")
|
58 |
-
>>> unmasker = pipeline('fill-mask', model=model, tokenizer=tokenizer)
|
59 |
-
>>> unmasker("Hello I'm a [MASK] model.")
|
60 |
-
|
61 |
-
[
|
62 |
-
{"sequence": "hello i'm a new model.", "score": 0.12073223292827606, "token": 351, "token_str": "new"},
|
63 |
-
{"sequence": "hello i'm a first model.", "score": 0.08501081168651581, "token": 478, "token_str": "first"},
|
64 |
-
{"sequence": "hello i'm a next model.", "score": 0.060546260327100754, "token": 1037, "token_str": "next"},
|
65 |
-
{"sequence": "hello i'm a last model.", "score": 0.038265593349933624, "token": 813, "token_str": "last"},
|
66 |
-
{"sequence": "hello i'm a sister model.", "score": 0.033868927508592606, "token": 6232, "token_str": "sister"},
|
67 |
-
]
|
68 |
-
|
69 |
-
```
|
70 |
-
|
71 |
-
Here is how to use this model to get the features of a given text in PyTorch:
|
72 |
-
|
73 |
-
**Note: You must specify the maximum sequence length to be 512 and truncate/pad to the same length because the original model has no attention mask and considers all the hidden states during forward pass.**
|
74 |
-
|
75 |
-
```python
|
76 |
-
from transformers import FNetTokenizer, FNetModel
|
77 |
-
tokenizer = FNetTokenizer.from_pretrained("google/fnet-base")
|
78 |
-
model = FNetModel.from_pretrained("google/fnet-base")
|
79 |
-
text = "Replace me by any text you'd like."
|
80 |
-
encoded_input = tokenizer(text, return_tensors='pt', padding='max_length', truncation=True, max_length=512)
|
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-base")
|
91 |
-
>>> model = FNetForMaskedLM.from_pretrained("google/fnet-base")
|
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 man.", "score": 0.07003913819789886, "token": 283, "token_str": "man"},
|
97 |
-
{"sequence": "the man worked as a..", "score": 0.06601415574550629, "token": 16678, "token_str": "."},
|
98 |
-
{"sequence": "the man worked as a reason.", "score": 0.020491471514105797, "token": 1612, "token_str": "reason"},
|
99 |
-
{"sequence": "the man worked as a use.", "score": 0.017683615908026695, "token": 443, "token_str": "use"},
|
100 |
-
{"sequence": "the man worked as a..", "score": 0.015186904929578304, "token": 845, "token_str": "."},
|
101 |
-
]
|
102 |
-
|
103 |
-
>>> unmasker("The woman worked as a [MASK].")
|
104 |
-
|
105 |
-
[
|
106 |
-
{"sequence": "the woman worked as a..", "score": 0.12459157407283783, "token": 16678, "token_str": "."},
|
107 |
-
{"sequence": "the woman worked as a man.", "score": 0.022601796314120293, "token": 283, "token_str": "man"},
|
108 |
-
{"sequence": "the woman worked as a..", "score": 0.0209997296333313, "token": 845, "token_str": "."},
|
109 |
-
{"sequence": "the woman worked as a woman.", "score": 0.01911095529794693, "token": 3806, "token_str": "woman"},
|
110 |
-
{"sequence": "the woman worked as a one.", "score": 0.01739976927638054, "token": 276, "token_str": "one"},
|
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.
|
@@ -171,6 +103,42 @@ For more details, please refer to the checkpoints linked with the scores. On ove
|
|
171 |
|
172 |
We can see that FNet-base achieves around 93% of BERT-base's performance while it requires *ca.* 30% less time to fine-tune on the downstream tasks.
|
173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
### BibTeX entry and citation info
|
175 |
|
176 |
```bibtex
|
|
|
45 |
to make decisions, such as sequence classification, token classification or question answering. For tasks such as text
|
46 |
generation you should look at model like GPT2.
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
## Training data
|
49 |
|
50 |
The FNet model was pretrained on [C4](https://huggingface.co/datasets/c4), a cleaned version of the Common Crawl dataset.
|
|
|
103 |
|
104 |
We can see that FNet-base achieves around 93% of BERT-base's performance while it requires *ca.* 30% less time to fine-tune on the downstream tasks.
|
105 |
|
106 |
+
### How to use
|
107 |
+
|
108 |
+
You can use this model directly with a pipeline for masked language modeling:
|
109 |
+
|
110 |
+
**Note: The mask filling pipeline doesn't work exactly as the original model performs masking after converting to tokens. In masking pipeline an additional space is added after the [MASK].**
|
111 |
+
|
112 |
+
```python
|
113 |
+
>>> from transformers import FNetForMaskedLM, FNetTokenizer, pipeline
|
114 |
+
>>> tokenizer = FNetTokenizer.from_pretrained("google/fnet-base")
|
115 |
+
>>> model = FNetForMaskedLM.from_pretrained("google/fnet-base")
|
116 |
+
>>> unmasker = pipeline('fill-mask', model=model, tokenizer=tokenizer)
|
117 |
+
>>> unmasker("Hello I'm a [MASK] model.")
|
118 |
+
|
119 |
+
[
|
120 |
+
{"sequence": "hello i'm a new model.", "score": 0.12073223292827606, "token": 351, "token_str": "new"},
|
121 |
+
{"sequence": "hello i'm a first model.", "score": 0.08501081168651581, "token": 478, "token_str": "first"},
|
122 |
+
{"sequence": "hello i'm a next model.", "score": 0.060546260327100754, "token": 1037, "token_str": "next"},
|
123 |
+
{"sequence": "hello i'm a last model.", "score": 0.038265593349933624, "token": 813, "token_str": "last"},
|
124 |
+
{"sequence": "hello i'm a sister model.", "score": 0.033868927508592606, "token": 6232, "token_str": "sister"},
|
125 |
+
]
|
126 |
+
|
127 |
+
```
|
128 |
+
|
129 |
+
Here is how to use this model to get the features of a given text in PyTorch:
|
130 |
+
|
131 |
+
**Note: You must specify the maximum sequence length to be 512 and truncate/pad to the same length because the original model has no attention mask and considers all the hidden states during forward pass.**
|
132 |
+
|
133 |
+
```python
|
134 |
+
from transformers import FNetTokenizer, FNetModel
|
135 |
+
tokenizer = FNetTokenizer.from_pretrained("google/fnet-base")
|
136 |
+
model = FNetModel.from_pretrained("google/fnet-base")
|
137 |
+
text = "Replace me by any text you'd like."
|
138 |
+
encoded_input = tokenizer(text, return_tensors='pt', padding='max_length', truncation=True, max_length=512)
|
139 |
+
output = model(**encoded_input)
|
140 |
+
```
|
141 |
+
|
142 |
### BibTeX entry and citation info
|
143 |
|
144 |
```bibtex
|