hf_mirrors/gpt2-small-portuguese
Model Introduction
Files & versions
Analysis
You are visiting the mirror address of https://modelers.cn/SY_AICC/gpt2-small-portuguese. The repo is synchronized in real-time and is only for mirror acceleration access.

GPorTuguese-2: a Language Model for Portuguese text generation (and more NLP tasks...)

Modification

  • Modify example and add npu support
  • Add denpendencies

Introduction

GPorTuguese-2 (Portuguese GPT-2 small) is a state-of-the-art language model for Portuguese based on the GPT-2 small model.

It was trained on Portuguese Wikipedia using Transfer Learning and Fine-tuning techniques in just over a day. It is a proof-of-concept that it is possible to get a state-of-the-art language model in any language with low ressources.

It was fine-tuned from the English pre-trained GPT-2 small using the openmind libraries wrapped into the fastai v2 Deep Learning framework. All the fine-tuning fastai v2 techniques were used.

It is now available on Hugging Face. For further information or requests, please go to "Faster than training from scratch — Fine-tuning the English GPT-2 in any language with Hugging Face and fastai v2 (practical case with Portuguese)".

Model

Model#paramsModel file (pt/tf)Arch.Training /Validation data (text)
gpt2-small-portuguese124M487M / 475MGPT-2 smallPortuguese Wikipedia (1.28 GB / 0.32 GB)

Evaluation results

In a little more than a day, we got a loss of 3.17, an accuracy of 37.99% and a perplexity of 23.76 (see the validation results table below).

after ... epochslossaccuracy (%)perplexitytime by epochcumulative time
09.959.9020950.9400:00:0000:00:00
13.6432.5238.125:48:315:48:31
23.3036.2927.165:38:1811:26:49
33.2137.4624.716:20:5117:47:40
43.1937.7424.216:06:2923:54:09
53.1737.9923.766:16:2230:10:31

GPT-2

Note: information copied/pasted from Model: gpt2 >> GPT-2

Pretrained model on English language using a causal language modeling (CLM) objective. It was first released at this page (February 14, 2019).

Disclaimer: The team releasing GPT-2 also wrote a model card for their model. Content from this model card has been written by the Hugging Face team to complete the information they provided and give specific examples of bias.

Model description

Note: information copied/pasted from Model: gpt2 >> Model description

GPT-2 is a transformers model pretrained on a very large corpus of English 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 English 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.

Dependencies

  • transformers==4.44.2
  • psutil==6.0.0

How to use GPorTuguese-2 with HuggingFace (PyTorch)

The following code use PyTorch.

from openmind import pipeline, is_torch_npu_available
from openmind_hub import snapshot_download

if is_torch_npu_available():
	device = "npu:0"
else:
	device = "cpu"
generator = pipeline(
	'text-generation', 
	model="SY_AICC/gpt2-small-portuguese",
	device=device
)
output = generator(
	"Quem era Jim Henson? Jim Henson era um",
	max_length=30, 
	num_return_sequences=1
)
print(f">>>output={output}", flush=True)

Limitations and bias

The training data used for this model come from Portuguese Wikipedia. We know it contains a lot of unfiltered content from the internet, which is far from neutral. As the openAI team themselves point out in their model card:

Because large-scale language models like GPT-2 do not distinguish fact from fiction, we don’t support use-cases that require the generated text to be true. Additionally, language models like GPT-2 reflect the biases inherent to the systems they were trained on, so we do not recommend that they be deployed into systems that interact with humans > unless the deployers first carry out a study of biases relevant to the intended use-case. We found no statistically significant difference in gender, race, and religious bias probes between 774M and 1.5B, implying all versions of GPT-2 should be approached with similar levels of caution around use cases that are sensitive to biases around human attributes.

Author

Portuguese GPT-2 small was trained and evaluated by Pierre GUILLOU thanks to the computing power of the GPU (GPU NVIDIA V100 32 Go) of the AI Lab (University of Brasilia) to which I am attached as an Associate Researcher in NLP and the participation of its directors in the definition of NLP strategy, Professors Fabricio Ataides Braz and Nilton Correia da Silva.

Citation

If you use our work, please cite:

@inproceedings{pierre2020gpt2smallportuguese,
  title={GPorTuguese-2 (Portuguese GPT-2 small): a Language Model for Portuguese text generation (and more NLP tasks...)},
  author={Pierre Guillou},
  year={2020}
}