aapot commited on
Commit
192092c
1 Parent(s): 1c732cf

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +157 -0
README.md ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - fi
4
+ license: apache-2.0
5
+ tags:
6
+ - finnish
7
+ - roberta
8
+ datasets:
9
+ - mc4
10
+ - wikipedia
11
+ widget:
12
+ - text: "Moikka olen <mask> kielimalli."
13
+
14
+ ---
15
+
16
+ # RoBERTa large model for Finnish
17
+
18
+ This **Finnish-NLP/roberta-large-finnish-v2** model is a new version of the previously trained [Finnish-NLP/roberta-large-finnish](https://huggingface.co/Finnish-NLP/roberta-large-finnish) model. Training hyperparameters were same but the training dataset was cleaned better with the goal to get better performing language model through the better cleaned data. Based on the model evaluations (check the table at the end), slightly better cleaned data didn't seem to produce better performing model.
19
+
20
+ Pretrained RoBERTa model on Finnish language using a masked language modeling (MLM) objective. RoBERTa was introduced in
21
+ [this paper](https://arxiv.org/abs/1907.11692) and first released in
22
+ [this repository](https://github.com/pytorch/fairseq/tree/master/examples/roberta). This model is case-sensitive: it
23
+ makes a difference between finnish and Finnish.
24
+
25
+ ## Model description
26
+
27
+ Finnish RoBERTa is a transformers model pretrained on a large corpus of Finnish data in a self-supervised fashion. This means
28
+ it was pretrained on the raw texts only, with no humans labelling them in any way (which is why it can use lots of
29
+ publicly available data) with an automatic process to generate inputs and labels from those texts.
30
+
31
+ More precisely, it was pretrained with the Masked language modeling (MLM) objective. Taking a sentence, the model
32
+ randomly masks 15% of the words in the input then run the entire masked sentence through the model and has to predict
33
+ the masked words. This is different from traditional recurrent neural networks (RNNs) that usually see the words one
34
+ after the other, or from autoregressive models like GPT which internally mask the future tokens. It allows the model to
35
+ learn a bidirectional representation of the sentence.
36
+
37
+ This way, the model learns an inner representation of the Finnish language that can then be used to extract features
38
+ useful for downstream tasks: if you have a dataset of labeled sentences for instance, you can train a standard
39
+ classifier using the features produced by the RoBERTa model as inputs.
40
+
41
+ ## Intended uses & limitations
42
+
43
+ You can use the raw model for masked language modeling, but it's mostly intended to be fine-tuned on a downstream task.
44
+
45
+ Note that this model is primarily aimed at being fine-tuned on tasks that use the whole sentence (potentially masked)
46
+ to make decisions, such as sequence classification, token classification or question answering. For tasks such as text
47
+ generation you should look at model like GPT2.
48
+
49
+ ### How to use
50
+
51
+ You can use this model directly with a pipeline for masked language modeling:
52
+
53
+ ```python
54
+ >>> from transformers import pipeline
55
+ >>> unmasker = pipeline('fill-mask', model='Finnish-NLP/roberta-large-finnish-v2')
56
+ >>> unmasker("Moikka olen <mask> kielimalli.")
57
+
58
+ [{'score': 0.04741518571972847,
59
+ 'token': 763,
60
+ 'token_str': ' hyvä',
61
+ 'sequence': 'Moikka olen hyvä kielimalli.'},
62
+ {'score': 0.036977022886276245,
63
+ 'token': 505,
64
+ 'token_str': ' myös',
65
+ 'sequence': 'Moikka olen myös kielimalli.'},
66
+ {'score': 0.025283709168434143,
67
+ 'token': 3089,
68
+ 'token_str': ' huono',
69
+ 'sequence': 'Moikka olen huono kielimalli.'},
70
+ {'score': 0.022848006337881088,
71
+ 'token': 1852,
72
+ 'token_str': ' toinen',
73
+ 'sequence': 'Moikka olen toinen kielimalli.'},
74
+ {'score': 0.019232941791415215,
75
+ 'token': 1029,
76
+ 'token_str': ' siis',
77
+ 'sequence': 'Moikka olen siis kielimalli.'}]
78
+ ```
79
+
80
+ Here is how to use this model to get the features of a given text in PyTorch:
81
+
82
+ ```python
83
+ from transformers import RobertaTokenizer, RobertaModel
84
+ tokenizer = RobertaTokenizer.from_pretrained('Finnish-NLP/roberta-large-finnish-v2')
85
+ model = RobertaModel.from_pretrained('Finnish-NLP/roberta-large-finnish-v2')
86
+ text = "Replace me by any text you'd like."
87
+ encoded_input = tokenizer(text, return_tensors='pt')
88
+ output = model(**encoded_input)
89
+ ```
90
+
91
+ and in TensorFlow:
92
+
93
+ ```python
94
+ from transformers import RobertaTokenizer, TFRobertaModel
95
+ tokenizer = RobertaTokenizer.from_pretrained('Finnish-NLP/roberta-large-finnish-v2')
96
+ model = TFRobertaModel.from_pretrained('Finnish-NLP/roberta-large-finnish-v2', from_pt=True)
97
+ text = "Replace me by any text you'd like."
98
+ encoded_input = tokenizer(text, return_tensors='tf')
99
+ output = model(encoded_input)
100
+ ```
101
+
102
+ ### Limitations and bias
103
+
104
+ The training data used for this model contains a lot of unfiltered content from the internet, which is far from
105
+ neutral. Therefore, the model can have biased predictions.
106
+
107
+ ## Training data
108
+
109
+ This Finnish RoBERTa model was pretrained on the combination of five datasets:
110
+ - [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).
111
+ - [wikipedia](https://huggingface.co/datasets/wikipedia) We used the Finnish subset of the wikipedia (August 2021) dataset
112
+ - [Yle Finnish News Archive](http://urn.fi/urn:nbn:fi:lb-2017070501)
113
+ - [Finnish News Agency Archive (STT)](http://urn.fi/urn:nbn:fi:lb-2018121001)
114
+ - [The Suomi24 Sentences Corpus](http://urn.fi/urn:nbn:fi:lb-2020021803)
115
+
116
+ Raw datasets were cleaned to filter out bad quality and non-Finnish examples. Together these cleaned datasets were around 84GB of text.
117
+
118
+ ## Training procedure
119
+
120
+ ### Preprocessing
121
+
122
+ The texts are tokenized using a byte version of Byte-Pair Encoding (BPE) and a vocabulary size of 50265. The inputs of
123
+ the model take pieces of 512 contiguous token that may span over documents. The beginning of a new document is marked
124
+ with `<s>` and the end of one by `</s>`
125
+
126
+ The details of the masking procedure for each sentence are the following:
127
+ - 15% of the tokens are masked.
128
+ - In 80% of the cases, the masked tokens are replaced by `<mask>`.
129
+
130
+ - In 10% of the cases, the masked tokens are replaced by a random token (different) from the one they replace.
131
+ - In the 10% remaining cases, the masked tokens are left as is.
132
+
133
+ Contrary to BERT, the masking is done dynamically during pretraining (e.g., it changes at each epoch and is not fixed).
134
+
135
+ ### Pretraining
136
+
137
+ The model was trained on TPUv3-8 VM, sponsored by the [Google TPU Research Cloud](https://sites.research.google/trc/about/), for 2 epochs with a sequence length of 128 and continuing for one more epoch with a sequence length of 512. The optimizer used for the 128 sequence training was AdamW, and for the 512 sequence training it was Adafactor (to save memory). Learning rate was 2e-4, \\(\beta_{1} = 0.9\\), \\(\beta_{2} = 0.98\\) and \\(\epsilon = 1e-6\\), learning rate warmup for 1500 steps and linear decay of the learning rate after.
138
+
139
+ ## Evaluation results
140
+
141
+ Evaluation was done by fine-tuning the model on downstream text classification task with two different labeled datasets: [Yle News](https://github.com/spyysalo/yle-corpus) and [Eduskunta](https://github.com/aajanki/eduskunta-vkk). Yle News classification fine-tuning was done with two different sequence lengths: 128 and 512 but Eduskunta only with 128 sequence length.
142
+ When fine-tuned on those datasets, this model (the first row of the table) achieves the following accuracy results compared to the [FinBERT (Finnish BERT)](https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1) model and to our previous [Finnish-NLP/roberta-large-finnish](https://huggingface.co/Finnish-NLP/roberta-large-finnish) model:
143
+
144
+ | | Average | Yle News 128 length | Yle News 512 length | Eduskunta 128 length |
145
+ |----------------------------------------|----------|---------------------|---------------------|----------------------|
146
+ |Finnish-NLP/roberta-large-finnish-v2 |88.17 |94.46 |95.22 |74.83 |
147
+ |Finnish-NLP/roberta-large-finnish |88.02 |94.53 |95.23 |74.30 |
148
+ |TurkuNLP/bert-base-finnish-cased-v1 |**88.82** |**94.90** |**95.49** |**76.07** |
149
+
150
+ To conclude, this model didn't improve significantly compared to our previous [Finnish-NLP/roberta-large-finnish](https://huggingface.co/Finnish-NLP/roberta-large-finnish) model. This model is also slightly (~ 1%) losing to the [FinBERT (Finnish BERT)](https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1) model.
151
+
152
+ ## Team Members
153
+
154
+ - Aapo Tanskanen, [Hugging Face profile](https://huggingface.co/aapot), [LinkedIn profile](https://www.linkedin.com/in/aapotanskanen/)
155
+ - Rasmus Toivanen [Hugging Face profile](https://huggingface.co/RASMUS), [LinkedIn profile](https://www.linkedin.com/in/rasmustoivanen/)
156
+
157
+ Feel free to contact us for more details 🤗