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ptpt
|
7 |
+
- albertina-ptbr
|
8 |
+
- albertina-ptpt-base
|
9 |
+
- albertina-ptbr-base
|
10 |
+
- fill-mask
|
11 |
+
- bert
|
12 |
+
- deberta
|
13 |
+
- portuguese
|
14 |
+
- encoder
|
15 |
+
- foundation model
|
16 |
license: mit
|
17 |
+
datasets:
|
18 |
+
- dlb/plue
|
19 |
+
- oscar-corpus/OSCAR-2301
|
20 |
+
- PORTULAN/glue-ptpt
|
21 |
+
widget:
|
22 |
+
- text: >-
|
23 |
+
A culinária portuguesa é rica em sabores e [MASK], tornando-se um dos
|
24 |
+
maiores tesouros do país.
|
25 |
---
|
26 |
+
|
27 |
+
|
28 |
+
# Albertina PT-PT Base
|
29 |
+
|
30 |
+
|
31 |
+
**Albertina PT-*** is a foundation, large language model for the **Portuguese language**.
|
32 |
+
|
33 |
+
It is an **encoder** of the BERT family, based on the neural architecture Transformer and
|
34 |
+
developed over the DeBERTa model, with most competitive performance for this language.
|
35 |
+
It has different versions that were trained for different variants of Portuguese (PT),
|
36 |
+
namely the European variant from Portugal (**PT-PT**) and the American variant from Brazil (**PT-BR**),
|
37 |
+
and it is distributed free of charge and under a most permissible license.
|
38 |
+
|
39 |
+
**Albertina PT-PT** is the version for European **Portuguese** from **Portugal**,
|
40 |
+
and to the best of our knowledge, at the time of its initial distribution,
|
41 |
+
it is the first competitive encoder specifically for this language and variant
|
42 |
+
that is made publicly available and distributed for reuse.
|
43 |
+
|
44 |
+
It is developed by a joint team from the University of Lisbon and the University of Porto, Portugal.
|
45 |
+
For further details, check the respective [publication](https://arxiv.org/abs/2305.06721):
|
46 |
+
|
47 |
+
``` latex
|
48 |
+
@misc{albertina-pt,
|
49 |
+
title={Advancing Neural Encoding of Portuguese
|
50 |
+
with Transformer Albertina PT-*},
|
51 |
+
author={João Rodrigues and Luís Gomes and João Silva and
|
52 |
+
António Branco and Rodrigo Santos and
|
53 |
+
Henrique Lopes Cardoso and Tomás Osório},
|
54 |
+
year={2023},
|
55 |
+
eprint={2305.06721},
|
56 |
+
archivePrefix={arXiv},
|
57 |
+
primaryClass={cs.CL}
|
58 |
+
}
|
59 |
+
```
|
60 |
+
|
61 |
+
Please use the above cannonical reference when using or citing this model.
|
62 |
+
|
63 |
+
<br>
|
64 |
+
|
65 |
+
|
66 |
+
# Model Description
|
67 |
+
|
68 |
+
**This model card is for Albertina-PT-BR Base**, with 100M parameters, 12 layers and a hidden size of 768.
|
69 |
+
|
70 |
+
Albertina-PT-PT is distributed under an [MIT license](https://huggingface.co/PORTULAN/albertina-ptpt/blob/main/LICENSE).
|
71 |
+
|
72 |
+
DeBERTa is distributed under an [MIT license](https://github.com/microsoft/DeBERTa/blob/master/LICENSE).
|
73 |
+
|
74 |
+
|
75 |
+
<br>
|
76 |
+
|
77 |
+
# Training Data
|
78 |
+
|
79 |
+
**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:
|
80 |
+
|
81 |
+
- [OSCAR](https://huggingface.co/datasets/oscar-corpus/OSCAR-2301): 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](https://commoncrawl.org/) 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.
|
82 |
+
- [DCEP](https://joint-research-centre.ec.europa.eu/language-technology-resources/dcep-digital-corpus-european-parliament_en): 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.
|
83 |
+
- [Europarl](https://www.statmt.org/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.
|
84 |
+
- [ParlamentoPT](https://huggingface.co/datasets/PORTULAN/parlamento-pt): the ParlamentoPT is a data set we obtained by gathering the publicly available documents with the transcription of the debates in the Portuguese Parliament.
|
85 |
+
|
86 |
+
|
87 |
+
[**Albertina PT-BR Base**](https://huggingface.co/PORTULAN/albertina-ptbr), in turn, was trained over a 3.7 billion token curated selection of documents from the [OSCAR](https://huggingface.co/datasets/oscar-corpus/OSCAR-2301) data set, specifically filtered by the Internet country code top-level domain of Brazil.
|
88 |
+
|
89 |
+
|
90 |
+
## Preprocessing
|
91 |
+
|
92 |
+
We filtered the PT-PT and PT-BR corpora using the [BLOOM pre-processing](https://github.com/bigscience-workshop/data-preparation) pipeline.
|
93 |
+
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.
|
94 |
+
|
95 |
+
|
96 |
+
## Training
|
97 |
+
|
98 |
+
As codebase, we resorted to the [DeBERTa V1 Base](https://huggingface.co/microsoft/deberta-base), for English.
|
99 |
+
|
100 |
+
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.
|
101 |
+
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).
|
102 |
+
We opted for a learning rate of 1e-5 with linear decay and 10k warm-up steps.
|
103 |
+
A total of 200 training epochs were performed resulting in approximately 180k steps.
|
104 |
+
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.
|
105 |
+
|
106 |
+
To train [**Albertina PT-BR Base**](https://huggingface.co/PORTULAN/albertina-ptbr-base) we followed the same hyperparameterization as the Albertina-PT-PT Base model.
|
107 |
+
The model was trained with a total of 150 training epochs resulting in approximately 180k steps.
|
108 |
+
|
109 |
+
|
110 |
+
<br>
|
111 |
+
|
112 |
+
# Evaluation
|
113 |
+
|
114 |
+
The two base model versions were evaluated on downstream tasks, namely 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](https://huggingface.co/datasets/glue), which allowed us to test both Albertina-PT-* Base variants on a wider variety of downstream tasks.
|
115 |
+
|
116 |
+
|
117 |
+
## GLUE tasks translated
|
118 |
+
|
119 |
+
We resort to [PLUE](https://huggingface.co/datasets/dlb/plue) (Portuguese Language Understanding Evaluation), a data set that was obtained by automatically translating GLUE into **PT-BR**.
|
120 |
+
We address four tasks from those in PLUE, namely:
|
121 |
+
- two similarity tasks: MRPC, for detecting whether two sentences are paraphrases of each other, and STS-B, for semantic textual similarity;
|
122 |
+
- and two inference tasks: RTE, for recognizing textual entailment and WNLI, for coreference and natural language inference.
|
123 |
+
|
124 |
+
|
125 |
+
| Model | RTE (Accuracy) | WNLI (Accuracy)| MRPC (F1) | STS-B (Pearson) |
|
126 |
+
|--------------------------|----------------|----------------|-----------|-----------------|
|
127 |
+
| **Albertina-PT-BR Base** | 0.6462 | **0.5493** | 0.8779 | 0.8501 |
|
128 |
+
| **Albertina-PT-PT Base** | **0.6643** | 0.4366 | **0.8966** | **0.8608** |
|
129 |
+
|
130 |
+
|
131 |
+
We resorted to [GLUE-PT](https://huggingface.co/datasets/PORTULAN/glue-ptpt), a **PT-PT version of the GLUE** benchmark.
|
132 |
+
We automatically translated the same four tasks from GLUE using [DeepL Translate](https://www.deepl.com/), which specifically provides translation from English to PT-PT as an option.
|
133 |
+
|
134 |
+
| Model | RTE (Accuracy) | WNLI (Accuracy)| MRPC (F1) | STS-B (Pearson) |
|
135 |
+
|--------------------------|----------------|----------------|-----------|-----------------|
|
136 |
+
| **Albertina-PT-PT Base** | **0.6787** | 0.4507 | 0.8829 | **0.8581** |
|
137 |
+
| **Albertina-PT-BR Base** | 0.6570 | **0.5070** | **0.8900** | 0.8516 |
|
138 |
+
|
139 |
+
<br>
|
140 |
+
|
141 |
+
# How to use
|
142 |
+
|
143 |
+
You can use this model directly with a pipeline for masked language modeling:
|
144 |
+
|
145 |
+
```python
|
146 |
+
>>> from transformers import pipeline
|
147 |
+
>>> unmasker = pipeline('fill-mask', model='PORTULAN/albertina-ptbr-base')
|
148 |
+
>>> unmasker("A culinária portuguesa é rica em sabores e [MASK], tornando-se um dos maiores tesouros do país.")
|
149 |
+
|
150 |
+
[{'score': 0.8070242404937744, 'token': 14690, 'token_str': ' costumes', 'sequence': 'A culinária portuguesa é rica em sabores e costumes, tornando-se um dos maiores tesouros do país.'},
|
151 |
+
{'score': 0.142287477850914, 'token': 29829, 'token_str': ' cores', 'sequence': 'A culinária portuguesa é rica em sabores e cores, tornando-se um dos maiores tesouros do país.'},
|
152 |
+
{'score': 0.014665354043245316, 'token': 6696, 'token_str': ' drinks', 'sequence': 'A culinária portuguesa é rica em sabores e drinks, tornando-se um dos maiores tesouros do país.'},
|
153 |
+
{'score': 0.0035127566661685705, 'token': 606, 'token_str': ' comes', 'sequence': 'A culinária portuguesa é rica em sabores e comes, tornando-se um dos maiores tesouros do país.'},
|
154 |
+
{'score': 0.0034212609753012657, 'token': 37410, 'token_str': ' aroma', 'sequence': 'A culinária portuguesa é rica em sabores e aroma, tornando-se um dos maiores tesouros do país.'}]
|
155 |
+
|
156 |
+
|
157 |
+
|
158 |
+
```
|
159 |
+
|
160 |
+
The model can be used by fine-tuning it for a specific task:
|
161 |
+
|
162 |
+
```python
|
163 |
+
>>> from transformers import AutoTokenizer, AutoModelForSequenceClassification, TrainingArguments, Trainer
|
164 |
+
>>> from datasets import load_dataset
|
165 |
+
|
166 |
+
>>> model = AutoModelForSequenceClassification.from_pretrained("PORTULAN/albertina-ptbr-base", num_labels=2)
|
167 |
+
>>> tokenizer = AutoTokenizer.from_pretrained("PORTULAN/albertina-ptpt-base")
|
168 |
+
>>> dataset = load_dataset("PORTULAN/glue-ptpt", "rte")
|
169 |
+
|
170 |
+
>>> def tokenize_function(examples):
|
171 |
+
... return tokenizer(examples["sentence1"], examples["sentence2"], padding="max_length", truncation=True)
|
172 |
+
|
173 |
+
>>> tokenized_datasets = dataset.map(tokenize_function, batched=True)
|
174 |
+
|
175 |
+
>>> training_args = TrainingArguments(output_dir="albertina-ptpt-rte", evaluation_strategy="epoch")
|
176 |
+
>>> trainer = Trainer(
|
177 |
+
... model=model,
|
178 |
+
... args=training_args,
|
179 |
+
... train_dataset=tokenized_datasets["train"],
|
180 |
+
... eval_dataset=tokenized_datasets["validation"],
|
181 |
+
... )
|
182 |
+
|
183 |
+
>>> trainer.train()
|
184 |
+
|
185 |
+
```
|
186 |
+
|
187 |
+
<br>
|
188 |
+
|
189 |
+
# Citation
|
190 |
+
|
191 |
+
When using or citing this model, kindly cite the following [publication](https://arxiv.org/abs/2305.06721):
|
192 |
+
|
193 |
+
``` latex
|
194 |
+
@misc{albertina-pt,
|
195 |
+
title={Advancing Neural Encoding of Portuguese
|
196 |
+
with Transformer Albertina PT-*},
|
197 |
+
author={João Rodrigues and Luís Gomes and João Silva and
|
198 |
+
António Branco and Rodrigo Santos and
|
199 |
+
Henrique Lopes Cardoso and Tomás Osório},
|
200 |
+
year={2023},
|
201 |
+
eprint={2305.06721},
|
202 |
+
archivePrefix={arXiv},
|
203 |
+
primaryClass={cs.CL}
|
204 |
+
}
|
205 |
+
```
|
206 |
+
|
207 |
+
<br>
|
208 |
+
|
209 |
+
# Acknowledgments
|
210 |
+
|
211 |
+
The research reported here was partially supported by: PORTULAN CLARIN—Research Infrastructure for the Science and Technology of Language,
|
212 |
+
funded by Lisboa 2020, Alentejo 2020 and FCT—Fundação para a Ciência e Tecnologia under the
|
213 |
+
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
|
214 |
+
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.
|