Model Overview
Model Features
Model Capabilities
Use Cases
🚀 GPT-2 medium for Finnish
A pretrained GPT-2 medium model for the Finnish language, trained using a causal language modeling (CLM) objective.
This model is a 345M parameter variant, similar to Huggingface's GPT-2-medium config, not the well - known 1.5B parameter variant by OpenAI. We also offer a larger 774M parameter variant, gpt2-large-finnish, which performs better than this model.
🚀 Quick Start
You can use the raw model for text generation or fine - tune it for downstream tasks. Check the model hub for fine - tuned versions related to your task.
💻 Usage Examples
Basic Usage
>>> from transformers import pipeline
>>> generator = pipeline('text-generation', model='Finnish-NLP/gpt2-medium-finnish')
>>> generator("Teksti√§ tuottava teko√§ly on", max_length=30, num_return_sequences=5)
[{'generated_text': 'Tekstiä tuottava tekoäly on tullut ihmisten arkeen viime vuosina. Se auttaa hahmottamaan ja tulkitsemaan monimutkaisia kokonaisuuksia ja ilmiöitä, joita ihmiset tekevät esimerkiksi ruokakaupassa'},
{'generated_text': 'Tekstiä tuottava tekoäly on jo ottanut haltuunsa myös ihmisten käyttämiä sovelluksia ja esimerkiksi pankkipalveluita. Sen vuoksi tekoäly on tärkeä kumppani etenkin yritysten liiketoiminnan kehittämisessä.-'},
{'generated_text': 'Teksti√§ tuottava teko√§ly on teko√§lylle luonnollinen valinta, sill√§ sen avulla voi kommunikoida ihmisten kanssa hyvin pitk√§lle samalla tavalla kuin tietokoneiden kanssa. Se on kehittynyt muun'},
{'generated_text': 'Teksti√§ tuottava teko√§ly on ihmisen kehitt√§m√§ teko√§ly, jota ei viel√§ ole pystytty rakentamaan. Teko√§ly kykenee toimimaan esimerkiksi matemaattisissa, tilastollisissa ja sosiaalisissa'},
{'generated_text': 'Tekstiä tuottava tekoäly on jo niin iso juttu ettei sitä kannata rajoittaakaan. Ja jos se saadaan käyttöön, niin se voi jo pian syrjäyttää perinteisen'}]
Advanced Usage
Here is how to use this model to get the features of a given text in PyTorch:
from transformers import GPT2Tokenizer, GPT2Model
tokenizer = GPT2Tokenizer.from_pretrained('Finnish-NLP/gpt2-medium-finnish')
model = GPT2Model.from_pretrained('Finnish-NLP/gpt2-medium-finnish')
text = "Replace me by any text you'd like."
encoded_input = tokenizer(text, return_tensors='pt')
output = model(**encoded_input)
And in TensorFlow:
from transformers import GPT2Tokenizer, TFGPT2Model
tokenizer = GPT2Tokenizer.from_pretrained('Finnish-NLP/gpt2-medium-finnish')
model = TFGPT2Model.from_pretrained('Finnish-NLP/gpt2-medium-finnish', from_pt=True)
text = "Replace me by any text you'd like."
encoded_input = tokenizer(text, return_tensors='tf')
output = model(encoded_input)
✨ Features
- Self - Supervised Learning: Pretrained on a large Finnish corpus in a self - supervised manner, learning from raw texts without human labeling.
- Text Generation: Specialized in generating Finnish text from a given prompt.
- Feature Extraction: Can extract useful features for downstream tasks.
📚 Documentation
Model description
The Finnish GPT - 2 is a transformers model pretrained on a vast Finnish corpus in a self - supervised way. It was trained to predict the next word in sentences. Inputs are sequences of continuous text, and targets are the same sequences shifted one token to the right. The model uses a mask - mechanism to ensure predictions only rely on previous tokens. This allows the model to learn an internal representation of the Finnish language, which can be used for feature extraction and text generation.
Intended uses & limitations
- Intended Uses: Text generation and fine - tuning for downstream tasks.
- Limitations and bias: The training data contains unfiltered internet content, leading to potential biased predictions. This bias affects all fine - tuned versions of the model. Also, like all language models, it's hard to predict the model's response to specific prompts, and offensive content may appear unexpectedly. We recommend human curation or filtering of outputs.
Training data
This model was pretrained on a combination of six datasets:
- mc4_fi_cleaned: A cleaned Finnish subset of the mC4 dataset, further processed with custom cleaning codes.
- wikipedia: The Finnish subset of the August 2021 Wikipedia dataset.
- Yle Finnish News Archive 2011 - 2018
- Yle Finnish News Archive 2019 - 2020
- Finnish News Agency Archive (STT)
- The Suomi24 Sentences Corpus
The raw datasets were cleaned to remove low - quality and non - Finnish examples, resulting in around 84GB of text.
Training procedure
Preprocessing
Texts are tokenized using a byte - level Byte Pair Encoding (BPE) for unicode characters, with a vocabulary size of 50,257. Inputs are sequences of 512 consecutive tokens.
Pretraining
The model was trained on a TPUv3 - 8 VM, sponsored by the Google TPU Research Cloud, for 360k steps (a bit over 1 epoch, 128 batch size). The optimizer was AdamW with a learning rate of 1e - 4, a 4000 - step learning rate warmup, and cosine decay of the learning rate afterward.
Evaluation results
Evaluation was conducted using the validation split of the mc4_fi_cleaned dataset, with Perplexity as the metric (lower score is better). As shown in the table below, this model outperforms the smaller gpt2 - finnish but is inferior to the larger gpt2 - large - finnish.
Property | Details |
---|---|
Model Type | Pretrained GPT - 2 medium for Finnish |
Training Data | Combination of six datasets: mc4_fi_cleaned, wikipedia, Yle Finnish News Archive 2011 - 2018, Yle Finnish News Archive 2019 - 2020, Finnish News Agency Archive (STT), The Suomi24 Sentences Corpus |
Perplexity | |
---|---|
Finnish-NLP/gpt2-medium-finnish | 34.08 |
Finnish-NLP/gpt2-finnish | 44.19 |
Finnish-NLP/gpt2-large-finnish | 30.74 |
🔧 Technical Details
- Tokenization: Byte - level Byte Pair Encoding (BPE) with a vocabulary size of 50,257.
- Input Sequences: Sequences of 512 consecutive tokens.
- Training Hardware: TPUv3 - 8 VM.
- Optimizer: AdamW with learning rate 1e - 4, 4000 - step warmup, and cosine decay.
📄 License
This project is licensed under the Apache - 2.0 license.
Acknowledgements
This project was made possible thanks to the generous computing resources provided by Google through the TPU Research Cloud.
Team Members
- Aapo Tanskanen, Hugging Face profile, LinkedIn profile
- Rasmus Toivanen, Hugging Face profile, LinkedIn profile
Feel free to contact us for more details.
⚠️ Important Note
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.
💡 Usage Tip
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.

