aapot commited on
Commit
18c21fd
1 Parent(s): 7703143

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +128 -0
README.md CHANGED
@@ -1,3 +1,131 @@
1
  ---
 
 
2
  license: apache-2.0
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language:
3
+ - fi
4
  license: apache-2.0
5
+ tags:
6
+ - finnish
7
+ - t5
8
+ - t5x
9
+ - seq2seq
10
+ datasets:
11
+ - Finnish-NLP/mc4_fi_cleaned
12
+ - wikipedia
13
+ inference: false
14
+
15
  ---
16
+
17
+ # T5-large-nl36 for Finnish
18
+
19
+ Pretrained T5 model on Finnish language using a span-based masked language modeling (MLM) objective. T5 was introduced in
20
+ [this paper](https://arxiv.org/abs/1910.10683)
21
+ and first released at [this page](https://github.com/google-research/text-to-text-transfer-transformer).
22
+
23
+ **Note:** The Hugging Face inference widget is deactivated because this model needs a text-to-text fine-tuning on a specific downstream task to be useful in practice. As an example of a fine-tuned Finnish T5 model, you can check [Finnish-NLP/t5-small-nl24-casing-punctuation-correction](https://huggingface.co/Finnish-NLP/t5-small-nl24-casing-punctuation-correction) which has been fine-tuned to correct missing casing and punctuation for Finnish text.
24
+
25
+ ## Model description
26
+
27
+ T5 is an encoder-decoder model and treats all NLP problems in a text-to-text format.
28
+
29
+ Finnish T5 is a transformers model pretrained on a very large corpus of Finnish data in a self-supervised fashion. This means it was pretrained on the raw texts only, with no humans labelling them in any way (which is why it can use lots of publicly available data) with an automatic process to generate inputs and outputs from those texts.
30
+
31
+ More precisely, it was pretrained with the span-based masked language modeling (MLM) objective. Spans of the input sequence are masked by so-called sentinel tokens (a.k.a unique mask tokens) and the output sequence is formed as a concatenation of the same sentinel tokens and the real masked tokens. This way, the model learns an inner representation of the Finnish language.
32
+
33
+ This model used the [T5 v1.1](https://github.com/google-research/text-to-text-transfer-transformer/blob/main/released_checkpoints.md#t511) improvements compared to the original T5 model during the pretraining:
34
+ - GEGLU activation in feed-forward hidden layer, rather than ReLU - see [here](https://arxiv.org/abs/2002.05202)
35
+ - Dropout was turned off in pretraining (quality win). Dropout should be re-enabled during fine-tuning
36
+ - Pretrained on span-based masked language modeling (MLM) objective only without mixing in the downstream tasks
37
+ - No parameter sharing between embedding and classifier layer
38
+
39
+ This model also used the "efficient" T5 architecture findings presented in [this paper](https://arxiv.org/abs/2109.10686). In a nutshell, the paper indicates that a Deep-Narrow model architecture is favorable for downstream performance compared to other model architectures of similar parameter count. To be more precise, model depth is defined as the number of transformer blocks that are stacked sequentially.
40
+
41
+ This model uses the [t5-efficient-large-nl36](https://huggingface.co/google/t5-efficient-large-nl36) architecture's layer depth which means both the encoder and the decoder have 36 transformer layers compared to the original T5 "large" model's architecture of 24 transformer layers.
42
+
43
+ In total, this model has 1425 million parameters.
44
+
45
+ ## Intended uses & limitations
46
+
47
+ This model was only pretrained in a self-supervised way excluding any supervised training. Therefore, this model has to be fine-tuned before it is usable on a downstream task, like text classification, unlike the Google's original T5 model. **Note:** You most likely need to fine-tune these T5 models without mixed precision so fine-tune them with full fp32 precision. You can also find more fine-tuning tips from [here](https://discuss.huggingface.co/t/t5-finetuning-tips), for example.
48
+
49
+ ### How to use
50
+
51
+ Here is how to use this model in PyTorch:
52
+
53
+ ```python
54
+ from transformers import T5Tokenizer, T5ForConditionalGeneration
55
+
56
+ tokenizer = T5Tokenizer.from_pretrained("Finnish-NLP/t5-large-nl36-finnish")
57
+ model = T5ForConditionalGeneration.from_pretrained("Finnish-NLP/t5-large-nl36-finnish")
58
+ ```
59
+
60
+ and in TensorFlow:
61
+
62
+ ```python
63
+ from transformers import T5Tokenizer, TFT5ForConditionalGeneration
64
+
65
+ tokenizer = T5Tokenizer.from_pretrained("Finnish-NLP/t5-large-nl36-finnish")
66
+ model = T5ForConditionalGeneration.from_pretrained("Finnish-NLP/t5-large-nl36-finnish", from_pt=True)
67
+ ```
68
+
69
+ ### Limitations and bias
70
+
71
+ The training data used for this model contains a lot of unfiltered content from the internet, which is far from neutral. Therefore, the model can have biased predictions. This bias will also affect all fine-tuned versions of this model.
72
+
73
+ ## Training data
74
+
75
+ This Finnish T5 model was pretrained on the combination of six datasets:
76
+ - [mc4_fi_cleaned](https://huggingface.co/datasets/Finnish-NLP/mc4_fi_cleaned), the dataset mC4 is a multilingual colossal, cleaned version of Common Crawl's web crawl corpus. We used the Finnish subset of the mC4 dataset and further cleaned it with our own text data cleaning codes (check the dataset repo).
77
+ - [wikipedia](https://huggingface.co/datasets/wikipedia) We used the Finnish subset of the wikipedia (August 2021) dataset
78
+ - [Yle Finnish News Archive 2011-2018](http://urn.fi/urn:nbn:fi:lb-2017070501)
79
+ - [Yle Finnish News Archive 2019-2020](http://urn.fi/urn:nbn:fi:lb-2021050401)
80
+ - [Finnish News Agency Archive (STT)](http://urn.fi/urn:nbn:fi:lb-2018121001)
81
+ - [The Suomi24 Sentences Corpus](http://urn.fi/urn:nbn:fi:lb-2020021803)
82
+
83
+ Raw datasets were automatically cleaned to filter out bad quality and non-Finnish examples. Also, a [perplexity](https://huggingface.co/course/chapter7/3#perplexity-for-language-models) score was calculated for all texts with a KenLM model which was trained with very clean Finnish texts only. This perplexity score can then be used to determine how "clean" Finnish language the text contains. Lastly, all datasets were concatenated and the top 90% perplexity score was used as a filtering threshold to filter out the worst quality 10% of texts. Together these cleaned datasets were around 76GB of text.
84
+
85
+ ## Training procedure
86
+
87
+ ### Preprocessing
88
+
89
+ The texts are tokenized using WordPiece and a vocabulary size of 32000. The inputs and the outputs are sequences of 512 consecutive tokens. Texts are not lower cased so this model is case-sensitive: it makes a difference between finnish and Finnish.
90
+
91
+ ### Pretraining
92
+
93
+ The model was trained on TPUv3-8 VM, sponsored by the [Google TPU Research Cloud](https://sites.research.google/trc/about/), for 1.87M steps with a batch size of 32 (in total 31B tokens). The optimizer used was a AdaFactor with learning rate warmup for 10K steps with a constant learning rate of 1e-3, and then an inverse square root decay (exponential decay) of the learning rate after.
94
+
95
+ Training code was from the Google's Jax/Flax based [t5x framework](https://github.com/google-research/t5x) and also some t5x task definitions were adapted from [Per's t5x work](https://huggingface.co/pere).
96
+
97
+ ## Evaluation results
98
+
99
+ Evaluation was done by fine-tuning the model on a downstream text classification task with two different labeled Finnish datasets: [Yle News](https://github.com/spyysalo/yle-corpus) and [Eduskunta](https://github.com/aajanki/eduskunta-vkk). Classification fine-tuning was done with a sequence length of 128 tokens.
100
+
101
+ When fine-tuned on those datasets, this model (the sixth row of the table) achieves the following accuracy results compared to our other T5 models and their parameter counts:
102
+
103
+ | | Model parameters | Yle News accuracy | Eduskunta accuracy |
104
+ |-------------------------------------------------------|------------------|---------------------|----------------------|
105
+ |Finnish-NLP/t5-tiny-nl6-finnish | 31 million |92.80 |69.07 |
106
+ |Finnish-NLP/t5-mini-nl8-finnish | 72 million |93.89 |71.43 |
107
+ |Finnish-NLP/t5-small-nl24-finnish | 260 million |**94.68** |74.90 |
108
+ |Finnish-NLP/byt5-base-finnish | 582 million |92.33 |73.13 |
109
+ |Finnish-NLP/t5-base-nl36-finnish | 814 million |94.40 |**75.97** |
110
+ |Finnish-NLP/t5-large-nl36-finnish | 1425 million |TBA |TBA |
111
+
112
+
113
+ Fine-tuning Google's multilingual mT5 models on the same datasets we can clearly see that our monolingual Finnish T5 models achieve much better results on Finnish text classification:
114
+
115
+ | | Model parameters | Yle News accuracy | Eduskunta accuracy |
116
+ |-------------------------------------------------------|------------------|---------------------|----------------------|
117
+ |google/mt5-small | 301 million |91.51 |64.10 |
118
+ |google/mt5-base | 583 million |92.71 |68.40 |
119
+
120
+
121
+ ## Acknowledgements
122
+
123
+ This project would not have been possible without compute generously provided by Google through the
124
+ [TPU Research Cloud](https://sites.research.google/trc/).
125
+
126
+ ## Team Members
127
+
128
+ - Aapo Tanskanen, [Hugging Face profile](https://huggingface.co/aapot), [LinkedIn profile](https://www.linkedin.com/in/aapotanskanen/)
129
+ - Rasmus Toivanen, [Hugging Face profile](https://huggingface.co/RASMUS), [LinkedIn profile](https://www.linkedin.com/in/rasmustoivanen/)
130
+
131
+ Feel free to contact us for more details 🤗