aapot commited on
Commit
d22c61d
1 Parent(s): 85fc898

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +131 -126
README.md CHANGED
@@ -1,127 +1,132 @@
1
- ---
2
- language:
3
- - fi
4
- license: apache-2.0
5
- tags:
6
- - finnish
7
- - gpt2
8
- datasets:
9
- - Finnish-NLP/mc4_fi_cleaned
10
- - wikipedia
11
- widget:
12
- - text: "Tekstiä tuottava tekoäly on"
13
-
14
- ---
15
-
16
- # GPT-2 large for Finnish
17
-
18
- Pretrained GPT-2 large 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 774M parameter variant as in Huggingface's [GPT-2-large config](https://huggingface.co/gpt2-large), 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-large-finnish')
51
- >>> generator("Tekstiä tuottava tekoäly on", max_length=30, num_return_sequences=5)
52
-
53
- [{'generated_text': 'Tekstiä tuottava tekoäly on valmis yhteistyöhön ihmisen kanssa: Tekoäly hoitaa ihmisen puolesta tekstin tuottamisen. Se myös ymmärtää, missä vaiheessa tekstiä voidaan alkaa kirjoittamaan'},
54
- {'generated_text': 'Tekstiä tuottava tekoäly on älykäs, mutta se ei ole vain älykkäisiin koneisiin kuuluva älykäs olento, vaan se on myös kone. Se ei'},
55
- {'generated_text': 'Tekstiä tuottava tekoäly on ehkä jo pian todellisuutta - se voisi tehdä myös vanhustenhoidosta nykyistä ä tuottava tekoäly on ehkä jo pian todellisuutta - se voisi tehdä'},
56
- {'generated_text': 'Tekstiä tuottava tekoäly on kehitetty ihmisen ja ihmisen aivoihin yhteistyössä neurotieteiden ja käyttäytymistieteen tutkijatiimin kanssa. Uusi teknologia avaa aivan uudenlaisia tutkimusi'},
57
- {'generated_text': 'Tekstiä tuottava tekoäly on kuin tietokone, jonka kanssa voi elää. Tekoälyn avulla voi kirjoittaa mitä tahansa, mistä tahansa ja miten paljon. Tässä'}]
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-large-finnish')
65
- model = GPT2Model.from_pretrained('Finnish-NLP/gpt2-large-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-large-finnish')
76
- model = TFGPT2Model.from_pretrained('Finnish-NLP/gpt2-large-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 six 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 640k steps (a bit over 1 epoch, 64 batch size). The optimizer used was a AdamW with learning rate 4e-5, 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 model variants.
115
-
116
- | | Perplexity |
117
- |------------------------------------------|------------|
118
- |Finnish-NLP/gpt2-large-finnish |**30.74** |
119
- |Finnish-NLP/gpt2-medium-finnish |34.08 |
120
- |Finnish-NLP/gpt2-finnish |44.19 |
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 🤗
 
1
+ ---
2
+ language:
3
+ - fi
4
+ license: apache-2.0
5
+ tags:
6
+ - finnish
7
+ - gpt2
8
+ datasets:
9
+ - Finnish-NLP/mc4_fi_cleaned
10
+ - wikipedia
11
+ widget:
12
+ - text: "Tekstiä tuottava tekoäly on"
13
+
14
+ ---
15
+
16
+ # GPT-2 large for Finnish
17
+
18
+ Pretrained GPT-2 large 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 774M parameter variant as in Huggingface's [GPT-2-large config](https://huggingface.co/gpt2-large), 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-large-finnish')
51
+ >>> generator("Tekstiä tuottava tekoäly on", max_length=30, num_return_sequences=5)
52
+
53
+ [{'generated_text': 'Tekstiä tuottava tekoäly on valmis yhteistyöhön ihmisen kanssa: Tekoäly hoitaa ihmisen puolesta tekstin tuottamisen. Se myös ymmärtää, missä vaiheessa tekstiä voidaan alkaa kirjoittamaan'},
54
+ {'generated_text': 'Tekstiä tuottava tekoäly on älykäs, mutta se ei ole vain älykkäisiin koneisiin kuuluva älykäs olento, vaan se on myös kone. Se ei'},
55
+ {'generated_text': 'Tekstiä tuottava tekoäly on ehkä jo pian todellisuutta - se voisi tehdä myös vanhustenhoidosta nykyistä ä tuottava tekoäly on ehkä jo pian todellisuutta - se voisi tehdä'},
56
+ {'generated_text': 'Tekstiä tuottava tekoäly on kehitetty ihmisen ja ihmisen aivoihin yhteistyössä neurotieteiden ja käyttäytymistieteen tutkijatiimin kanssa. Uusi teknologia avaa aivan uudenlaisia tutkimusi'},
57
+ {'generated_text': 'Tekstiä tuottava tekoäly on kuin tietokone, jonka kanssa voi elää. Tekoälyn avulla voi kirjoittaa mitä tahansa, mistä tahansa ja miten paljon. Tässä'}]
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-large-finnish')
65
+ model = GPT2Model.from_pretrained('Finnish-NLP/gpt2-large-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-large-finnish')
76
+ model = TFGPT2Model.from_pretrained('Finnish-NLP/gpt2-large-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 six 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 640k steps (a bit over 1 epoch, 64 batch size). The optimizer used was a AdamW with learning rate 4e-5, 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 model variants.
115
+
116
+ | | Perplexity |
117
+ |------------------------------------------|------------|
118
+ |Finnish-NLP/gpt2-large-finnish |**30.74** |
119
+ |Finnish-NLP/gpt2-medium-finnish |34.08 |
120
+ |Finnish-NLP/gpt2-finnish |44.19 |
121
+
122
+ ## Acknowledgements
123
+
124
+ This project would not have been possible without compute generously provided by Google through the
125
+ [TPU Research Cloud](https://sites.research.google/trc/).
126
+
127
+ ## Team Members
128
+
129
+ - Aapo Tanskanen, [Hugging Face profile](https://huggingface.co/aapot), [LinkedIn profile](https://www.linkedin.com/in/aapotanskanen/)
130
+ - Rasmus Toivanen, [Hugging Face profile](https://huggingface.co/RASMUS), [LinkedIn profile](https://www.linkedin.com/in/rasmustoivanen/)
131
+
132
  Feel free to contact us for more details 🤗