aapot commited on
Commit
84a9528
1 Parent(s): df72baf

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +111 -2
README.md CHANGED
@@ -13,6 +13,115 @@ widget:
13
 
14
  ---
15
 
16
- # GPT2 Finnish
17
 
18
- Readme coming soon
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  ---
15
 
16
+ # GPT-2 for Finnish
17
 
18
+ Pretrained GPT-2 model on Finnish language using a causal language modeling (CLM) objective. GPT-2 was introduced in
19
+ [this paper](https://d4mucfpksywv.cloudfront.net/better-language-models/language_models_are_unsupervised_multitask_learners.pdf)
20
+ and first released at [this page](https://openai.com/blog/better-language-models/).
21
+
22
+ **Note**: this model is quite small 117M parameter variant as in Huggingface's [GPT-2 config](https://huggingface.co/gpt2), so not the famous big 1.5B parameter variant by OpenAI. We also have bigger 345M parameter variant [gpt2-medium-finnish](https://huggingface.co/Finnish-NLP/gpt2-medium-finnish) available which performs better compared to this model.
23
+
24
+ ## Model description
25
+
26
+ Finnish GPT-2 is a transformers model pretrained on a very large corpus of Finnish data in a self-supervised fashion. This
27
+ means it was pretrained on the raw texts only, with no humans labelling them in any way (which is why it can use lots
28
+ of publicly available data) with an automatic process to generate inputs and labels from those texts. More precisely,
29
+ it was trained to guess the next word in sentences.
30
+
31
+ More precisely, inputs are sequences of continuous text of a certain length and the targets are the same sequence,
32
+ shifted one token (word or piece of word) to the right. The model uses internally a mask-mechanism to make sure the
33
+ predictions for the token `i` only uses the inputs from `1` to `i` but not the future tokens.
34
+
35
+ This way, the model learns an inner representation of the Finnish language that can then be used to extract features
36
+ useful for downstream tasks. The model is best at what it was pretrained for however, which is generating texts from a
37
+ prompt.
38
+
39
+ ## Intended uses & limitations
40
+
41
+ You can use the raw model for text generation or fine-tune it to a downstream task. See the
42
+ [model hub](https://huggingface.co/models?filter=gpt2) to look for fine-tuned versions on a task that interests you.
43
+
44
+ ### How to use
45
+
46
+ You can use this model directly with a pipeline for text generation:
47
+
48
+ ```python
49
+ >>> from transformers import pipeline
50
+ >>> generator = pipeline('text-generation', model='Finnish-NLP/gpt2-finnish')
51
+ >>> generator("Tekstiä tuottava tekoäly on", max_length=30, num_return_sequences=5)
52
+
53
+ [{'generated_text': 'Tekstiä tuottava tekoäly on kuin onkin hyvin pieni. Sitä voi käyttää myös hyvin nopeasti ja myös täysin automatisoituna, eikä sitä tarvitse käydä läpi. Se'},
54
+ {'generated_text': 'Tekstiä tuottava tekoäly on saanut jalansijaa, mutta Suomessa se on jo ehtinyt hajota käsiin, koska sen avulla ei pystytä tuottamaan täysin ajantasaisia'},
55
+ {'generated_text': 'Tekstiä tuottava tekoäly on tehnyt työtä kymmenien vuosien ajan ja ottanut käyttöön jo yli kahden vuosikymmenen ajan tekoälyn ratkaisuja. Tekoäly on jo pitkään tehnyt työtä'},
56
+ {'generated_text': 'Tekstiä tuottava tekoäly on tekoälyn sovellus, jota käytetään esimerkiksi liiketoiminnan ja päätöksenteon tukena. Työhön liittyy data-analyysin ohella tekoälyn avulla esimerkiksi tekoäl'},
57
+ {'generated_text': 'Tekstiä tuottava tekoäly on juuri nyt erityisen hyödyllinen, koska se tunnistaa käyttäjän tietokoneen ruudulla olevat ilmoitukset, kuten näytön värin ja osoittimet ilman välkyn'}]
58
+ ```
59
+
60
+ Here is how to use this model to get the features of a given text in PyTorch:
61
+
62
+ ```python
63
+ from transformers import GPT2Tokenizer, GPT2Model
64
+ tokenizer = GPT2Tokenizer.from_pretrained('Finnish-NLP/gpt2-finnish')
65
+ model = GPT2Model.from_pretrained('Finnish-NLP/gpt2-finnish')
66
+ text = "Replace me by any text you'd like."
67
+ encoded_input = tokenizer(text, return_tensors='pt')
68
+ output = model(**encoded_input)
69
+ ```
70
+
71
+ and in TensorFlow:
72
+
73
+ ```python
74
+ from transformers import GPT2Tokenizer, TFGPT2Model
75
+ tokenizer = GPT2Tokenizer.from_pretrained('Finnish-NLP/gpt2-finnish')
76
+ model = TFGPT2Model.from_pretrained('Finnish-NLP/gpt2-finnish', from_pt=True)
77
+ text = "Replace me by any text you'd like."
78
+ encoded_input = tokenizer(text, return_tensors='tf')
79
+ output = model(encoded_input)
80
+ ```
81
+
82
+ ### Limitations and bias
83
+
84
+ 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.
85
+
86
+ As with all language models, it is hard to predict in advance how the Finnish GPT-2 will respond to particular prompts and offensive content may occur without warning. We recommend having a human curate or filter the outputs before releasing them, both to censor undesirable content and to improve the quality of the results.
87
+
88
+ ## Training data
89
+
90
+ This Finnish GPT-2 model was pretrained on the combination of five datasets:
91
+ - [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).
92
+ - [wikipedia](https://huggingface.co/datasets/wikipedia) We used the Finnish subset of the wikipedia (August 2021) dataset
93
+ - [Yle Finnish News Archive 2011-2018](http://urn.fi/urn:nbn:fi:lb-2017070501)
94
+ - [Yle Finnish News Archive 2019-2020](http://urn.fi/urn:nbn:fi:lb-2021050401)
95
+ - [Finnish News Agency Archive (STT)](http://urn.fi/urn:nbn:fi:lb-2018121001)
96
+ - [The Suomi24 Sentences Corpus](http://urn.fi/urn:nbn:fi:lb-2020021803)
97
+
98
+ Raw datasets were cleaned to filter out bad quality and non-Finnish examples. Together these cleaned datasets were around 84GB of text.
99
+
100
+ ## Training procedure
101
+
102
+ ### Preprocessing
103
+
104
+ The texts are tokenized using a byte-level version of Byte Pair Encoding (BPE) (for unicode characters) and a
105
+ vocabulary size of 50,257. The inputs are sequences of 512 consecutive tokens.
106
+
107
+ ### Pretraining
108
+
109
+ The model was trained on TPUv3-8 VM, sponsored by the [Google TPU Research Cloud](https://sites.research.google/trc/about/), for 300k steps. The optimizer used was a second-order optimization method called [Distributed Shampoo](https://github.com/google-research/google-research/tree/master/scalable_shampoo) with learning rate 1e-4, learning rate warmup for 4000 steps and cosine decay of the learning rate after.
110
+
111
+ At first, commonly used Adam optimizer was tried but there were significant issues getting the model to converge even with multiple different learning rate trials so then Adam optimizer was replaced with the Distributed Shampoo which worked a lot better.
112
+
113
+ ## Evaluation results
114
+
115
+ Evaluation was done using the *validation* split of the [mc4_fi_cleaned](https://huggingface.co/datasets/Finnish-NLP/mc4_fi_cleaned) dataset with [Perplexity](https://huggingface.co/course/chapter7/3#perplexity-for-language-models) (smaller score the better) as the evaluation metric. As seen from the table below, this model (the first row of the table) loses to our bigger [gpt2-medium-finnish](https://huggingface.co/Finnish-NLP/gpt2-medium-finnish) model variant.
116
+
117
+ | | Perplexity |
118
+ |------------------------------------------|------------|
119
+ |Finnish-NLP/gpt2-finnish |44.19 |
120
+ |Finnish-NLP/gpt2-medium-finnish |**34.08** |
121
+
122
+ ## Team Members
123
+
124
+ - Aapo Tanskanen, [Hugging Face profile](https://huggingface.co/aapot), [LinkedIn profile](https://www.linkedin.com/in/aapotanskanen/)
125
+ - Rasmus Toivanen [Hugging Face profile](https://huggingface.co/RASMUS), [LinkedIn profile](https://www.linkedin.com/in/rasmustoivanen/)
126
+
127
+ Feel free to contact us for more details 🤗