readme: ---
  language:
  - fi
  license: apache-2.0
  tags:
  - finnish
  - gpt2
  datasets:
  - Finnish-NLP/mc4_fi_cleaned
  - wikipedia
  widget:
  - text: "Tekstiä tuottava tekoäly on"
  
  ---
  
  # GPT-2 large for Finnish
  
  Pretrained GPT-2 large model on Finnish language using a causal language modeling (CLM) objective. GPT-2 was introduced in
  [this paper](https://d4mucfpksywv.cloudfront.net/better-language-models/language_models_are_unsupervised_multitask_learners.pdf)
  and first released at [this page](https://openai.com/blog/better-language-models/).
  
  **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.
  
  ## Model description
  
  Finnish GPT-2 is a transformers model pretrained on a very 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 trained to guess the next word in sentences.
  
  More precisely, inputs are sequences of continuous text of a certain length and the targets are the same sequence,
  shifted one token (word or piece of word) to the right. The model uses internally a mask-mechanism to make sure the
  predictions for the token `i` only uses the inputs from `1` to `i` but not the future tokens.
  
  This way, the model learns an inner representation of the Finnish language that can then be used to extract features
  useful for downstream tasks. The model is best at what it was pretrained for however, which is generating texts from a
  prompt.
  
  ## Intended uses & limitations
  
  You can use the raw model for text generation or fine-tune it to a downstream task. See the
  [model hub](https://huggingface.co/models?filter=gpt2) to look for fine-tuned versions on a task that interests you.
  
  ### How to use
  
  You can use this model directly with a pipeline for text generation:
  
  ```python
  >>> from transformers import pipeline
  >>> generator = pipeline('text-generation', model='Finnish-NLP/gpt2-large-finnish')
  >>> generator("Tekstiä tuottava tekoäly on", max_length=30, num_return_sequences=5)
  
  [{'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'},
   {'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'},
   {'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ä'},
   {'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'},
   {'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ä'}]
  ```
  
  Here is how to use this model to get the features of a given text in PyTorch:
  
  ```python
  from transformers import GPT2Tokenizer, GPT2Model
  tokenizer = GPT2Tokenizer.from_pretrained('Finnish-NLP/gpt2-large-finnish')
  model = GPT2Model.from_pretrained('Finnish-NLP/gpt2-large-finnish')
  text = "Replace me by any text you'd like."
  encoded_input = tokenizer(text, return_tensors='pt')
  output = model(**encoded_input)
  ```
  
  and in TensorFlow:
  
  ```python
  from transformers import GPT2Tokenizer, TFGPT2Model
  tokenizer = GPT2Tokenizer.from_pretrained('Finnish-NLP/gpt2-large-finnish')
  model = TFGPT2Model.from_pretrained('Finnish-NLP/gpt2-large-finnish', from_pt=True)
  text = "Replace me by any text you'd like."
  encoded_input = tokenizer(text, return_tensors='tf')
  output = model(encoded_input)
  ```
  
  ### Limitations and bias
  
  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.
  
  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.
  
  ## Training data
  
  This Finnish GPT-2 model was pretrained on the combination of six datasets:
  - [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).
  - [wik