File size: 12,697 Bytes
fa503e1
 
 
 
e49d249
fc787a4
 
fa503e1
 
 
 
 
 
fd3794c
0c887cb
fa503e1
 
 
467135f
fa503e1
467135f
 
6fc488b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
080b631
 
 
 
 
6fc488b
 
 
 
 
 
467135f
 
fa503e1
6fc488b
fa503e1
 
09b38d4
fa503e1
403de65
 
 
 
fa503e1
09b38d4
fa503e1
 
 
403de65
fa503e1
 
 
 
 
 
 
403de65
 
 
fa503e1
 
403de65
fa503e1
 
403de65
09b38d4
fa503e1
 
 
403de65
 
 
 
 
 
fa503e1
5bbdd69
fa503e1
 
5bbdd69
fa503e1
403de65
09b38d4
fa503e1
 
 
403de65
fa503e1
 
 
 
403de65
09b38d4
fa503e1
ec25a92
15e9c85
fa503e1
 
 
 
 
 
 
09b38d4
fa503e1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
09b38d4
fa503e1
84a991a
fa503e1
 
 
 
 
3d5f085
0c887cb
 
 
 
 
 
 
fa503e1
 
 
 
7c17f88
 
 
 
 
 
3d5f085
 
7c17f88
 
 
5ae56f3
 
7c17f88
 
3d5f085
7c17f88
 
 
 
 
 
5ae56f3
7c17f88
 
 
fa503e1
09b38d4
 
fa503e1
 
7f3fc66
fa503e1
 
 
df2cfd6
 
 
 
 
fa503e1
 
 
 
 
 
 
09b38d4
 
5bbdd69
 
79a5b5b
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
---
language: 
  - pt
tags: 
  - albertina-pt*
  - albertina-ptpt
  - albertina-ptbr
  - fill-mask
license: mit
datasets:
- oscar
- brwac
- europarl
widget:
 - text: "A culinária portuguesa é rica em sabores e [MASK], tornando-se um dos maiores tesouros do país."
---


# Albertina PT-PT

**Albertina PT-*** is a foundation, large language model for the **Portuguese language**.

It is an **encoder** of the BERT family, based on a Transformer architecture, 
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 was the first competitive encoder for this language and variant 
that had been made publicly available and distributed for reuse.

It was developped by a joint team from the University of Lisbon and the University of Porto, Portugal. 
For further details, check the respective publication:

``` latex
@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={?},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}
```

Please use the above cannonical reference when using or citing this model.

<br>


# Model Description

**This model card is for Albertina-PT-PT**, with 900M parameters, 24 layers and a hidden size of 1536.

This model is distributed free of charge under the [MIT](https://choosealicense.com/licenses/mit/) license (permits commercial use, distribution, modification and private use).


<br>

# Training Data

**Albertina PT-PT** was trained over a data set that resulted from gathering some openly available corpora of European Portuguese from the following sources:

- [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.
- [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&#39;s official website. We retained its European Portuguese portion.
- [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.
- [ParlamentoPT](https://www.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.


**Albertina PT-BR**, in turn, was trained over the [BrWac](https://huggingface.co/datasets/brwac) data set.


## Preprocessing

We filtered the PT-PT corpora using the [BLOOM pre-processing](https://github.com/bigscience-workshop/data-preparation) pipeline, resulting in a data set of 8 million documents, containing around 2.2 billion tokens.
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 V2 XLarge](https://huggingface.co/microsoft/deberta-v2-xlarge), for English.

To train **Albertina-PT-PT**, 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 832 samples (52 samples per GPU and applying gradient accumulation in order to approximate the batch size of the PT-BR model).
Similarly to the PT-BR variant above, we opted for a learning rate of 1e-5 with linear decay and 10k warm-up steps.
However, since the number of training examples is approximately twice of that in the PT-BR variant, we reduced the number of training epochs to half and completed only 25 epochs, which resulted in approximately 245k steps.
The model was trained for 3 days on a2-highgpu-8gb Google Cloud A2 VMs with 8 GPUs, 96 vCPUs and 680 GB of RAM.

To train **Albertina-PT-BR** the BrWac 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 896 samples (56 samples per GPU without gradient accumulation steps).
We chose a learning rate of 1e-5 with linear decay and 10k warm-up steps based on the results of exploratory experiments. 
In total, around 200k training steps were taken across 50 epochs.
The model was trained for 1 day and 11 hours on a2-megagpu-16gb Google Cloud A2 VMs with 16 GPUs, 96 vCPUs and 1.360 GB of RAM.


<br>

# Evaluation

The two model versions were evaluated on downstream tasks organized into two groups.

In one group, we have the two data sets from the [ASSIN 2 benchmark](https://huggingface.co/datasets/assin2), namely STS and RTE, that were used to evaluate the previous state-of-the-art model [BERTimbau Large](https://huggingface.co/neuralmind/bert-large-portuguese-cased).
In the other group of data sets, we have 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-* variants on a wider variety of downstream tasks.


## ASSIN 2

[ASSIN 2](https://huggingface.co/datasets/assin2) is a **PT-BR data** set of approximately 10.000 sentence pairs, split into 6.500 for training, 500 for validation, and 2.448 for testing, annotated with semantic relatedness scores (range 1 to 5) and with binary entailment judgments.
This data set supports the task of semantic textual similarity (STS), which consists of assigning a score of how semantically related two sentences are; and the task of recognizing textual entailment (RTE), which given a pair of sentences, consists of determining whether the first entails the second.

| Model               | RTE (Accuracy) | STS (Pearson)|
|---------------------|----------------|--------------|
| **Albertina-PT-BR** | **0.9130**     | **0.8676**   |
| BERTimbau-large     | 0.8913         | 0.8531       |


## GLUE tasks translated

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**.
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** | 0.7545         | 0.4601         | 0.9071    | **0.8910**      | 
| BERTimbau-large     | 0.6546         | **0.5634**     | 0.887     | 0.8842          |
| |   |      |  |           |
| **Albertina-PT-PT** | **0.7960**     | 0.4507         | **0.9151**| 0.8799          |


We resorted to [GLUE-PT](https://huggingface.co/datasets/PORTULAN/glueptpt), a **PT-PT version of the GLUE** benchmark. 
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.

| Model               | RTE (Accuracy) | WNLI (Accuracy)| MRPC (F1) | STS-B (Pearson) |
|---------------------|----------------|----------------|-----------|-----------------|
| **Albertina-PT-PT** | **0.8339**     | **0.4225**     | **0.9171**| 0.8801          | 
| |   |      |  |           |
| **Albertina-PT-BR** | 0.7942         | 0.4085         | 0.9048    | **0.8847**      |

<br>

# How to use

You can use this model directly with a pipeline for masked language modeling:

```python
>>> from transformers import pipeline
>>> unmasker = pipeline('fill-mask', model='PORTULAN/albertina-ptpt')
>>> unmasker("A culinária portuguesa é rica em sabores e [MASK], tornando-se um dos maiores tesouros do país.")

[{'score': 0.9166129231452942, 'token': 23395, 'token_str': 'aromas', 'sequence': 'A culinária portuguesa é rica em sabores e aromas, tornando-se um dos maiores tesouros do país.'}, 
{'score': 0.022932516410946846, 'token': 10392, 'token_str': 'costumes', 'sequence': 'A culinária portuguesa é rica em sabores e costumes, tornando-se um dos maiores tesouros do país.'}, 
{'score': 0.013932268135249615, 'token': 21925, 'token_str': 'cores', 'sequence': 'A culinária portuguesa é rica em sabores e cores, tornando-se um dos maiores tesouros do país.'}, 
{'score': 0.009870869107544422, 'token': 22647, 'token_str': 'nuances', 'sequence': 'A culinária portuguesa é rica em sabores e nuances, tornando-se um dos maiores tesouros do país.'}, 
{'score': 0.007260020822286606, 'token': 12881, 'token_str': 'aroma', 'sequence': 'A culinária portuguesa é rica em sabores e aroma, tornando-se um dos maiores tesouros do país.'}]


```

The model can be used by fine-tuning it for a specific task:

```python
>>> from transformers import AutoTokenizer, AutoModelForSequenceClassification, TrainingArguments, Trainer
>>> from datasets import load_dataset

>>> model = AutoModelForSequenceClassification.from_pretrained("PORTULAN/albertina-ptpt", num_labels=2)
>>> tokenizer = AutoTokenizer.from_pretrained("PORTULAN/albertina-ptpt")
>>> dataset = load_dataset("PORTULAN/glueptpt", "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()

```

<br>

# Citation

When using or citing this model, kindly cite the following publication:

``` latex
@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={?},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}
```

<br>

# 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; and 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.