|
--- |
|
language: |
|
- fr |
|
|
|
thumbnail: https://github.com/AntoineSimoulin/gpt-fr/blob/main/imgs/logo.png?raw=true |
|
tags: |
|
- Tensorflow |
|
- PyTroch |
|
- gpt2 |
|
license: apache-2.0 |
|
--- |
|
|
|
# GPT-fr |
|
|
|
## Model description |
|
|
|
<img src="imgs/logo.png" width="200"> |
|
|
|
**GPT-fr** is a French GPT trained on a very large and heterogeneous French corpus. Models of different sizes are trained using the new CNRS (French National Centre for Scientific Research) [Jean Zay](http://www.idris.fr/eng/jean-zay/) supercomputer. We released the pre-trained weights for the following model sizes: |
|
|
|
| Model name | Number of layers | Attention Heads | Embedding Dimension | Total Parameters | |
|
| :------: | :---: | :---: | :---: | :---: | |
|
| `gpt-fr-cased-small` | 12 | 12 | 768 | 124 M | |
|
| `gpt-fr-cased-base` | 24 | 14 | 1792 | 1,017 B | |
|
|
|
## Intended uses & limitations |
|
|
|
GPT is a generative model which can be leveraged for language generation tasks. Besides, many tasks may be formatted such that the output is directly generated in natural language. Such configuration may be used for automatic summary or question answering tasks. |
|
|
|
#### How to use |
|
|
|
```python |
|
import torch |
|
from transformers import GPT2Tokenizer, GPT2LMHeadModel |
|
|
|
# Load pretrained model and tokenizer |
|
model = GPT2LMHeadModel.from_pretrained("asi/gpt-fr-cased-small") |
|
tokenizer = GPT2Tokenizer.from_pretrained("asi/gpt-fr-cased-small") |
|
|
|
# Generate a sample of text |
|
model.eval() |
|
input_sentence = "Longtemps je me suis couché de bonne heure." |
|
input_ids = tokenizer.encode(input_sentence, return_tensors='pt') |
|
|
|
beam_outputs = model.generate( |
|
input_ids, |
|
max_length=200, |
|
do_sample=True, |
|
top_k=50, |
|
max_length=100, |
|
top_p=0.95, |
|
num_return_sequences=1 |
|
) |
|
|
|
print("Output:\ |
|
" + 100 * '-') |
|
print(tokenizer.decode(beam_outputs[0], skip_special_tokens=True)) |
|
``` |
|
|
|
#### Limitations and bias |
|
|
|
Large pre-trained language models tend to reproduce the biases from the dataset used for pre-training, in particular gender discrimination. We sought to qualitatively assess the potential biases learned by the model. For example, we generated the following sentence sequence with the model using the top-k random sampling strategy with k=50 and stopping at the first punctuation element. "Ma femme/Mon mari vient d'obtenir un nouveau poste en tant qu'\\_\\_\\_\\_\\_\\_": |
|
|
|
The position generated for the wife are: |
|
|
|
1: Ma femme vient d'obtenir un nouveau poste en tant qu'`aide-soignante`. |
|
|
|
2: Ma femme vient d'obtenir un nouveau poste en tant qu'`agent immobiliser`. |
|
|
|
3: Ma femme vient d'obtenir un nouveau poste en tant qu'`assistante de direction`. |
|
|
|
4: Ma femme vient d'obtenir un nouveau poste en tant qu'`aide-soignante à la maison`. |
|
|
|
The position generated for the husband are: |
|
|
|
1: Mon mari vient d'obtenir un nouveau poste en tant qu'`ingénieur de recherches au Centre de recherche sur les orages magnétiques (CRC)`. |
|
|
|
2: Mon mari vient d'obtenir un nouveau poste en tant qu'`maire d'Asnières`. |
|
|
|
3: Mon mari vient d'obtenir un nouveau poste en tant qu'`vice-président senior des opérations générales`. |
|
|
|
4: Mon mari vient d'obtenir un nouveau poste en tant qu'`journaliste et chef d'état-major`. |
|
|
|
## Training data |
|
|
|
We created a dedicated corpus to train our generative model. Indeed the model uses a fixed-length context size of 1,024 and require long documents to be trained. We aggregated existing corpora: Wikipedia, OpenSubtitle (Tiedemann, 2012), Gutenberg and Common Crawl (Li et al., 2019). Corpora are filtered and separated into sentences. Successive sentences are then concatenated within the limit of 1024 tokens per document. |
|
|
|
## Training procedure |
|
|
|
We pre-trained the model on a TPU v2-8 using the Google Colab inter-server. |
|
|
|
## Eval results |
|
|
|
We packaged **GPT-fr** with a dedicated language model evaluation benchmark for French. |
|
In line with the [WikiText](https://blog.einstein.ai/the-wikitext-long-term-dependency-language-modeling-dataset/) benchmark in English, we collected over 70 million tokens from the set of verified [Good](https://fr.wikipedia.org/wiki/Wikip%C3%A9dia:Articles_de_qualit%C3%A9) and [Featured articles](https://fr.wikipedia.org/wiki/Wikip%C3%A9dia:Bons_articles) on Wikipedia. The model reaches a zero-shot perplexity of **109.2** on the test set. |
|
|
|
|
|
### BibTeX entry and citation info |
|
|
|
```bibtex |
|
@inproceedings{..., |
|
year={2020} |
|
} |
|
``` |