language:
- pt
tags:
- albertina-pt*
- albertina-ptpt
- albertina-ptbr
- albertina-ptpt-base
- albertina-ptbr-base
- fill-mask
- bert
- deberta
- portuguese
- encoder
- foundation model
license: mit
datasets:
- dlb/plue
- oscar-corpus/OSCAR-2301
- PORTULAN/glue-ptpt
widget:
- text: >-
A culinária portuguesa é rica em sabores e [MASK], tornando-se um dos
maiores tesouros do país.
Albertina PT-PT Base
Albertina PT-* is a foundation, large language model for the Portuguese language.
It is an encoder of the BERT family, based on the neural architecture Transformer and developed over the DeBERTa model, with most competitive performance for this language. It has different versions that were trained for different variants of Portuguese (PT), namely the European variant from Portugal (PT-PT) and the American variant from Brazil (PT-BR), and it is distributed free of charge and under a most permissible license.
Albertina PT-PT is the version for European Portuguese from Portugal, and to the best of our knowledge, at the time of its initial distribution, it is the first competitive encoder specifically for this language and variant that is made publicly available and distributed for reuse.
It is developed by a joint team from the University of Lisbon and the University of Porto, Portugal. For further details, check the respective publication:
@misc{albertina-pt,
title={Advancing Neural Encoding of Portuguese
with Transformer Albertina PT-*},
author={João Rodrigues and Luís Gomes and João Silva and
António Branco and Rodrigo Santos and
Henrique Lopes Cardoso and Tomás Osório},
year={2023},
eprint={2305.06721},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
Please use the above cannonical reference when using or citing this model.
Model Description
This model card is for Albertina-PT-PT Base, with 100M parameters, 12 layers and a hidden size of 768.
Albertina-PT-PT is distributed under an MIT license.
DeBERTa is distributed under an MIT license.
Training Data
Albertina PT-PT Base was trained over a 2.2 billion token data set that resulted from gathering some openly available corpora of European Portuguese from the following sources:
- OSCAR: the OSCAR data set includes documents in more than one hundred languages, including Portuguese, and it is widely used in the literature. It is the result of a selection performed over the Common Crawl data set, crawled from the Web, that retains only pages whose metadata indicates permission to be crawled, that performs deduplication, and that removes some boilerplate, among other filters. Given that it does not discriminate between the Portuguese variants, we performed extra filtering by retaining only documents whose meta-data indicate the Internet country code top-level domain of Portugal. We used the January 2023 version of OSCAR, which is based on the November/December 2022 version of Common Crawl.
- DCEP: the Digital Corpus of the European Parliament is a multilingual corpus including documents in all official EU languages published on the European Parliament's official website. We retained its European Portuguese portion.
- Europarl: the European Parliament Proceedings Parallel Corpus is extracted from the proceedings of the European Parliament from 1996 to 2011. We retained its European Portuguese portion.
- ParlamentoPT: the ParlamentoPT is a data set we obtained by gathering the publicly available documents with the transcription of the debates in the Portuguese Parliament.
Albertina PT-BR Base, in turn, was trained over a 3.7 billion token curated selection of documents from the OSCAR data set, specifically filtered by the Internet country code top-level domain of Brazil.
Preprocessing
We filtered the PT-PT and PT-BR corpora using the BLOOM pre-processing pipeline. We skipped the default filtering of stopwords since it would disrupt the syntactic structure, and also the filtering for language identification given the corpus was pre-selected as Portuguese.
Training
As codebase, we resorted to the DeBERTa V1 Base, for English.
To train Albertina-PT-PT Base, the data set was tokenized with the original DeBERTa tokenizer with a 128 token sequence truncation and dynamic padding. The model was trained using the maximum available memory capacity resulting in a batch size of 3072 samples (192 samples per GPU and applying gradient accumulation in order to approximate the batch size of the PT-BR model). We opted for a learning rate of 1e-5 with linear decay and 10k warm-up steps. A total of 200 training epochs were performed resulting in approximately 180k steps. The model was trained for one day on a2-megagpu-16gb Google Cloud A2 VMs with 16 GPUs, 96 vCPUs and 1.360 GB of RAM.
To train Albertina PT-BR Base we followed the same hyperparameterization as the Albertina-PT-PT Base model. The model was trained with a total of 150 training epochs resulting in approximately 180k steps.
Evaluation
The two base model versions were evaluated on downstream tasks_ The translations into PT-BR and PT-PT of the English data sets used for a few of the tasks in the widely-used GLUE benchmark, which allowed us to test both Albertina-PT-* variants on a wider variety of downstream tasks.
GLUE tasks translated
We resort to PLUE (Portuguese Language Understanding Evaluation), a data set that was obtained by automatically translating GLUE into PT-BR. We address four tasks from those in PLUE, namely:
- two similarity tasks: MRPC, for detecting whether two sentences are paraphrases of each other, and STS-B, for semantic textual similarity;
- and two inference tasks: RTE, for recognizing textual entailment and WNLI, for coreference and natural language inference.
Model | RTE (Accuracy) | WNLI (Accuracy) | MRPC (F1) | STS-B (Pearson) |
---|---|---|---|---|
Albertina-PT-BR Base | 0.6462 | 0.5493 | 0.8779 | 0.8501 |
Albertina-PT-PT Base | 0.6643 | 0.4366 | 0.8966 | 0.8608 |
We resorted to GLUE-PT, a PT-PT version of the GLUE benchmark. We automatically translated the same four tasks from GLUE using DeepL Translate, which specifically provides translation from English to PT-PT as an option.
Model | RTE (Accuracy) | WNLI (Accuracy) | MRPC (F1) | STS-B (Pearson) |
---|---|---|---|---|
Albertina-PT-PT Base | 0.6787 | 0.4507 | 0.8829 | 0.8581 |
Albertina-PT-BR Base | 0.6570 | 0.5070 | 0.8900 | 0.8516 |
How to use
You can use this model directly with a pipeline for masked language modeling:
>>> from transformers import pipeline
>>> unmasker = pipeline('fill-mask', model='PORTULAN/albertina-ptpt-base')
>>> unmasker("A culinária portuguesa é rica em sabores e [MASK], tornando-se um dos maiores tesouros do país.")
[{'score': 0.8332648277282715, 'token': 14690, 'token_str': ' costumes', 'sequence': 'A culinária portuguesa é rica em sabores e costumes, tornando-se um dos maiores tesouros do país.'},
{'score': 0.07860890030860901, 'token': 29829, 'token_str': ' cores', 'sequence': 'A culinária portuguesa é rica em sabores e cores, tornando-se um dos maiores tesouros do país.'},
{'score': 0.03278181701898575, 'token': 35277, 'token_str': ' arte', 'sequence': 'A culinária portuguesa é rica em sabores e arte, tornando-se um dos maiores tesouros do país.'},
{'score': 0.009515956044197083, 'token': 9240, 'token_str': ' cor', 'sequence': 'A culinária portuguesa é rica em sabores e cor, tornando-se um dos maiores tesouros do país.'},
{'score': 0.009381960146129131, 'token': 33455, 'token_str': ' nuances', 'sequence': 'A culinária portuguesa é rica em sabores e nuances, tornando-se um dos maiores tesouros do país.'}]
The model can be used by fine-tuning it for a specific task:
>>> from transformers import AutoTokenizer, AutoModelForSequenceClassification, TrainingArguments, Trainer
>>> from datasets import load_dataset
>>> model = AutoModelForSequenceClassification.from_pretrained("PORTULAN/albertina-ptpt-base", num_labels=2)
>>> tokenizer = AutoTokenizer.from_pretrained("PORTULAN/albertina-ptpt-base")
>>> dataset = load_dataset("PORTULAN/glue-ptpt", "rte")
>>> def tokenize_function(examples):
... return tokenizer(examples["sentence1"], examples["sentence2"], padding="max_length", truncation=True)
>>> tokenized_datasets = dataset.map(tokenize_function, batched=True)
>>> training_args = TrainingArguments(output_dir="albertina-ptpt-rte", evaluation_strategy="epoch")
>>> trainer = Trainer(
... model=model,
... args=training_args,
... train_dataset=tokenized_datasets["train"],
... eval_dataset=tokenized_datasets["validation"],
... )
>>> trainer.train()
Citation
When using or citing this model, kindly cite the following publication:
@misc{albertina-pt,
title={Advancing Neural Encoding of Portuguese
with Transformer Albertina PT-*},
author={João Rodrigues and Luís Gomes and João Silva and
António Branco and Rodrigo Santos and
Henrique Lopes Cardoso and Tomás Osório},
year={2023},
eprint={2305.06721},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
Acknowledgments
The research reported here was partially supported by: PORTULAN CLARIN—Research Infrastructure for the Science and Technology of Language, funded by Lisboa 2020, Alentejo 2020 and FCT—Fundação para a Ciência e Tecnologia under the grant PINFRA/22117/2016; research project ALBERTINA - Foundation Encoder Model for Portuguese and AI, funded by FCT—Fundação para a Ciência e Tecnologia under the grant CPCA-IAC/AV/478394/2022; innovation project ACCELERAT.AI - Multilingual Intelligent Contact Centers, funded by IAPMEI, I.P. - Agência para a Competitividade e Inovação under the grant C625734525-00462629, of Plano de Recuperação e Resiliência, call RE-C05-i01.01 – Agendas/Alianças Mobilizadoras para a Reindustrialização; and LIACC - Laboratory for AI and Computer Science, funded by FCT—Fundação para a Ciência e Tecnologia under the grant FCT/UID/CEC/0027/2020.