aapot commited on
Commit
e34232d
1 Parent(s): c5273eb

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +148 -5
README.md CHANGED
@@ -1,12 +1,155 @@
1
  ---
2
- language: fi
3
- license: CC-BY 4.0
 
4
  tags:
5
  - finnish
6
  - roberta
7
- pipeline_tag: fill-mask
 
8
  widget:
9
- - text: "Hän lähti ajamaan <mask> töihin."
 
10
  ---
11
 
12
- # Finnish roberta-large
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language:
3
+ - fi
4
+ license: apache-2.0
5
  tags:
6
  - finnish
7
  - roberta
8
+ datasets:
9
+ - mc4
10
  widget:
11
+ - text: "Moikka olen <mask> kielimalli."
12
+
13
  ---
14
 
15
+ # NOTE: We have trained newer and better Finnish RoBERTa large model which can be found from different repository: [https://huggingface.co/Finnish-NLP/roberta-large-finnish](https://huggingface.co/Finnish-NLP/roberta-large-finnish). Our future Finnish models will be available at the [Finnish-NLP](https://huggingface.co/Finnish-NLP) Hugging Face organization
16
+
17
+
18
+ # RoBERTa large model for Finnish
19
+
20
+ Pretrained model on Finnish language using a masked language modeling (MLM) objective. It 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
+ 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='flax-community/RoBERTa-large-finnish')
56
+ >>> unmasker("Moikka olen <mask> kielimalli.")
57
+
58
+ [{'sequence': 'Moikka olen uusi kielimalli.',
59
+ 'score': 0.05129234120249748,
60
+ 'token': 1825,
61
+ 'token_str': ' uusi'},
62
+ {'sequence': 'Moikka olen toinen kielimalli.',
63
+ 'score': 0.03112379088997841,
64
+ 'token': 2194,
65
+ 'token_str': ' toinen'},
66
+ {'sequence': 'Moikka olen myös kielimalli.',
67
+ 'score': 0.025534993037581444,
68
+ 'token': 491,
69
+ 'token_str': ' myös'},
70
+ {'sequence': 'Moikka olen ensimmäinen kielimalli.',
71
+ 'score': 0.020146571099758148,
72
+ 'token': 2832,
73
+ 'token_str': ' ensimmäinen'},
74
+ {'sequence': 'Moikka olen vapaa kielimalli.',
75
+ 'score': 0.018089469522237778,
76
+ 'token': 2257,
77
+ 'token_str': ' vapaa'}]
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('flax-community/RoBERTa-large-finnish')
85
+ model = RobertaModel.from_pretrained('flax-community/RoBERTa-large-finnish')
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('flax-community/RoBERTa-large-finnish')
96
+ model = TFRobertaModel.from_pretrained('flax-community/RoBERTa-large-finnish', 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 two datasets:
110
+ - [mc4](https://huggingface.co/datasets/mc4), 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
111
+ - [Yle Finnish News Archive](http://urn.fi/urn:nbn:fi:lb-2017070501)
112
+
113
+ Raw datasets were cleaned to filter out bad quality and non-Finnish examples. Together these cleaned datasets were around 51GB of text.
114
+
115
+ ## Training procedure
116
+
117
+ ### Preprocessing
118
+
119
+ The texts are tokenized using a byte version of Byte-Pair Encoding (BPE) and a vocabulary size of 50265. The inputs of
120
+ the model take pieces of 512 contiguous token that may span over documents. The beginning of a new document is marked
121
+ with `<s>` and the end of one by `</s>`
122
+
123
+ The details of the masking procedure for each sentence are the following:
124
+ - 15% of the tokens are masked.
125
+ - In 80% of the cases, the masked tokens are replaced by `<mask>`.
126
+
127
+ - In 10% of the cases, the masked tokens are replaced by a random token (different) from the one they replace.
128
+ - In the 10% remaining cases, the masked tokens are left as is.
129
+
130
+ Contrary to BERT, the masking is done dynamically during pretraining (e.g., it changes at each epoch and is not fixed).
131
+
132
+ ### Pretraining
133
+
134
+ The model was trained on TPUv3-8 VM, sponsored by the Hugging Face JAX/Flax community week event, for 2 epochs with a sequence length of 128 and continuing for one more epoch with a sequence length of 512. The optimizer used is Adafactor with a learning rate of 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.
135
+
136
+ ## Evaluation results
137
+
138
+ 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.
139
+ 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) and to our newer [Finnish RoBERTa-large](https://huggingface.co/Finnish-NLP/roberta-large-finnish) trained with larger dataset:
140
+
141
+ | | Average | Yle News 128 length | Yle News 512 length | Eduskunta 128 length |
142
+ |----------------------------------------|----------|---------------------|---------------------|----------------------|
143
+ |flax-community/RoBERTa-large-finnish |87.72 |94.42 |95.06 |73.67 |
144
+ |Finnish-NLP/roberta-large-finnish |88.02 |94.53 |95.23 |74.30 |
145
+ |TurkuNLP/bert-base-finnish-cased-v1 |**88.82** |**94.90** |**95.49** |**76.07** |
146
+
147
+ To conclude, this model slightly loses to our newer [Finnish RoBERTa-large](https://huggingface.co/Finnish-NLP/roberta-large-finnish) model trained with larger dataset and also slightly loses to the [FinBERT (Finnish BERT)](https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1) model.
148
+
149
+ ## Team Members
150
+
151
+ - Aapo Tanskanen, [Hugging Face profile](https://huggingface.co/aapot), [LinkedIn profile](https://www.linkedin.com/in/aapotanskanen/)
152
+ - Rasmus Toivanen [Hugging Face profile](https://huggingface.co/RASMUS), [LinkedIn profile](https://www.linkedin.com/in/rasmustoivanen/)
153
+ - Tommi Vehviläinen [Hugging Face profile](https://huggingface.co/Tommi)
154
+
155
+ Feel free to contact us for more details 🤗