aapot commited on
Commit
a8d8150
1 Parent(s): 2bb537f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +110 -2
README.md CHANGED
@@ -13,6 +13,114 @@ widget:
13
 
14
  ---
15
 
16
- # GPT2-medium Finnish
17
 
18
- Readme coming soon
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  ---
15
 
16
+ # GPT-2 medium for Finnish
17
 
18
+ Pretrained GPT-2 medium 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 345M parameter variant as in Huggingface's [GPT-2-medium config](https://huggingface.co/gpt2-medium), so not the famous big 1.5B parameter variant by OpenAI.
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-medium-finnish')
51
+ >>> generator("Tekstiä tuottava tekoäly on", max_length=30, num_return_sequences=5)
52
+
53
+ [{'generated_text': 'Tekstiä tuottava tekoäly on tullut ihmisten arkeen viime vuosina. Se auttaa hahmottamaan ja tulkitsemaan monimutkaisia kokonaisuuksia ja ilmiöitä, joita ihmiset tekevät esimerkiksi ruokakaupassa'},
54
+ {'generated_text': 'Tekstiä tuottava tekoäly on jo ottanut haltuunsa myös ihmisten käyttämiä sovelluksia ja esimerkiksi pankkipalveluita. Sen vuoksi tekoäly on tärkeä kumppani etenkin yritysten liiketoiminnan kehittämisessä.-'},
55
+ {'generated_text': 'Tekstiä tuottava tekoäly on tekoälylle luonnollinen valinta, sillä sen avulla voi kommunikoida ihmisten kanssa hyvin pitkälle samalla tavalla kuin tietokoneiden kanssa. Se on kehittynyt muun'},
56
+ {'generated_text': 'Tekstiä tuottava tekoäly on ihmisen kehittämä tekoäly, jota ei vielä ole pystytty rakentamaan. Tekoäly kykenee toimimaan esimerkiksi matemaattisissa, tilastollisissa ja sosiaalisissa'},
57
+ {'generated_text': 'Tekstiä tuottava tekoäly on jo niin iso juttu ettei sitä kannata rajoittaakaan. Ja jos se saadaan käyttöön, niin se voi jo pian syrjäyttää perinteisen'}]
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-medium-finnish')
65
+ model = GPT2Model.from_pretrained('Finnish-NLP/gpt2-medium-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-medium-finnish')
76
+ model = TFGPT2Model.from_pretrained('Finnish-NLP/gpt2-medium-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 360k steps. The optimizer used was a AdamW with learning rate 1e-4, learning rate warmup for 4000 steps and cosine decay of the learning rate after.
110
+
111
+
112
+ ## Evaluation results
113
+
114
+ 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) performs better than our smaller [gpt2-finnish](https://huggingface.co/Finnish-NLP/gpt2-finnish) model variant.
115
+
116
+ | | Perplexity |
117
+ |------------------------------------------|------------|
118
+ |Finnish-NLP/gpt2-medium-finnish |**34.08** |
119
+ |Finnish-NLP/gpt2-finnish |44.19 |
120
+
121
+ ## Team Members
122
+
123
+ - Aapo Tanskanen, [Hugging Face profile](https://huggingface.co/aapot), [LinkedIn profile](https://www.linkedin.com/in/aapotanskanen/)
124
+ - Rasmus Toivanen [Hugging Face profile](https://huggingface.co/RASMUS), [LinkedIn profile](https://www.linkedin.com/in/rasmustoivanen/)
125
+
126
+ Feel free to contact us for more details 🤗