readme: ---
  language:
  - fi
  license: apache-2.0
  tags:
  - finnish
  - roberta
  datasets:
  - Finnish-NLP/mc4_fi_cleaned
  - wikipedia
  widget:
  - text: "Moikka olen <mask> kielimalli."
  
  ---
  
  # RoBERTa large model trained with WECHSEL method for Finnish
  
  Pretrained RoBERTa model on Finnish language using a masked language modeling (MLM) objective with WECHSEL method. RoBERTa was introduced in
  [this paper](https://arxiv.org/abs/1907.11692) and first released in
  [this repository](https://github.com/pytorch/fairseq/tree/master/examples/roberta).
  
  WECHSEL method (Effective initialization of subword embeddings for cross-lingual transfer of monolingual language models)  was introduced in [this paper](https://arxiv.org/abs/2112.06598) and first released in [this repository](https://github.com/CPJKU/wechsel).
  
  This model is case-sensitive: it makes a difference between finnish and Finnish.
  
  ## Model description
  
  Finnish RoBERTa is a transformers model pretrained on a large corpus of Finnish data in a self-supervised fashion. This means
  it was pretrained on the raw texts only, with no humans labelling them in any way (which is why it can use lots of
  publicly available data) with an automatic process to generate inputs and labels from those texts. 
  
  More precisely, it was pretrained with the Masked language modeling (MLM) objective. Taking a sentence, the model
  randomly masks 15% of the words in the input then run the entire masked sentence through the model and has to predict
  the masked words. This is different from traditional recurrent neural networks (RNNs) that usually see the words one
  after the other, or from autoregressive models like GPT which internally mask the future tokens. It allows the model to
  learn a bidirectional representation of the sentence.
  
  This way, the model learns an inner representation of the Finnish language that can then be used to extract features
  useful for downstream tasks: if you have a dataset of labeled sentences for instance, you can train a standard
  classifier using the features produced by the RoBERTa model as inputs.
  
  ## WECHSEL method
  
  Using the WECHSEL method, we first took the pretrained English [roberta-large](https://huggingface.co/roberta-large) model, changed its tokenizer with our Finnish tokenizer and initialized model's token embeddings such that they are close to semantically similar English tokens by utilizing multilingual static word embeddings (by fastText) covering English and Finnish. We were able to confirm the WECHSEL paper's findings that using this method you can save pretraining time and thus computing resources. To get idea of the WECHSEL method's training time savings you can check the table below illustrating the MLM evaluation accuracies during the pretraining compared to the [Finnish-NLP/roberta-large-finnish-v2](https://huggingface.co/Finnish-NLP/roberta-large-finnish-v2) which was trained from scratch:
  
  |                                          | 10k train steps  | 100k train steps | 200k train steps | 270k train steps |
  |------------------------------------------|------------------|------------------|------------------|------------------|
  |Finnish-NLP/roberta-large-wechsel-finnish |37.61 eval acc    |58.14 eval acc    |61.60 eval acc    |62.77 eval acc    |
  |Finnish-NLP/roberta-large-finnish-v2      |13.83 eval acc    |55.87 eval acc    |58.58 eval acc    |59.47 eval acc    |
  
  Downstream finetuning text classification tests can be found from the end but there this model trained with WECHSEL method didn't significantly improve the downstream performances. However, based on tens of qualitative fill-mask task example tests we noticed that for fill-mask task this WECHSEL model significantly outperforms our other models trained from scratch.
  
  ## Intended uses & limitations
  
  You can use the raw model for masked language modeling, but it's mostly intended to be fine-tuned on a downstream task.
  
  Note that this model is primarily aimed at being fine-tuned on tasks that use the whole sentence (potentially masked)
  to make decisions, such as sequence classification, token classification or question answering. For tasks such as text
  generation you should look at model like GPT2.
  
  ### How to use
  
  You can use this model directly with a pipeline for masked language modeling:
  
  ```python
  >>> from transformers import pipeline
  >>> unmasker = pipeline('fill-mask', model='Finnish-NLP/roberta-large-wechsel-finnish')
  >>> unmasker("Moikka olen <mask> kielimalli.")
  
  [{'sequence': 'Moikka olen hyvä kielimalli.',
    'score': 0.07757357507944107,
    'token': 763,
    'token_str': ' hyvä'},
   {'sequence': 'Moikka olen suomen kielimalli.',
    'score': 0.05297883599996567,
    'token': 3641,
    'token_str': ' suomen'},
   {'sequence': 'Moikka olen kuin kielimalli.',
    'score': 0.03747279942035675,
    'token': 523,
    'token_str': ' kuin'},
   {'sequence': 'Moikka olen suomalainen kielimalli.',
    'score': 0.031031042337417603,
    'token': 4966,
    'token_str': ' suomalainen'},
   {'sequence': 'Moikka olen myös kielimall