jarodrigues
commited on
Commit
•
be1b006
1
Parent(s):
c9e6a3a
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- pt
|
4 |
+
tags:
|
5 |
+
- albertina-pt-*
|
6 |
+
- albertina-pt-pt
|
7 |
+
- albertina-pt-br
|
8 |
+
- fill-mask
|
9 |
+
license: mit
|
10 |
+
datasets:
|
11 |
+
- oscar
|
12 |
+
- brwac
|
13 |
+
- europarl
|
14 |
+
widget:
|
15 |
+
- text: "Países como [MASK] falam a língua portuguesa."
|
16 |
+
---
|
17 |
+
|
18 |
+
|
19 |
+
# Albertina PT-* Model
|
20 |
+
|
21 |
+
To advance the neural encoding of Portuguese (PT), and a fortiori the technological preparation of this language for the digital age, we developed a Transformer-based foundation model that sets a **new state of the art** in this respect for two of its variants, namely **European Portuguese from Portugal (PT-PT) and American Portuguese from Brazil (PT-BR)**.
|
22 |
+
|
23 |
+
To develop this **encoder**, which we named **Albertina PT-***, a strong model was used as a starting point, DeBERTa, and its pre-training was done over data sets of Portuguese, namely over a data set we gathered for PT-PT and over the BrWaC corpus for PT-BR.
|
24 |
+
The performance of Albertina and competing models was assessed by evaluating them on prominent downstream language processing tasks adapted for Portuguese.
|
25 |
+
|
26 |
+
Both **Albertina PT-PT and PT-BR versions are distributed free of charge and under the most permissive license possible** and can be run on consumer-grade hardware, thus seeking to contribute to the advancement of research and innovation in language technology for Portuguese.
|
27 |
+
|
28 |
+
Please check the [Albertina PT-* article]() for more details.
|
29 |
+
|
30 |
+
|
31 |
+
## Model Description
|
32 |
+
|
33 |
+
**This model card is for the Albertina-PT-BR** model with a total of 900M parameters, 24 layers and a hidden size of 1536.
|
34 |
+
|
35 |
+
The Albertina-PT-BR is distributed free of charge under the same permissions established for the data set used for training it, the [BrWac](https://huggingface.co/datasets/brwac).
|
36 |
+
*It is available solely for academic research purposes and not for commercial use.*
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
# Training Data
|
41 |
+
|
42 |
+
The **Albertina PT-PT** resorted to a data set that resulted from gathering some openly available corpora of European Portuguese from the following sources:
|
43 |
+
|
44 |
+
- [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.
|
45 |
+
- [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.
|
46 |
+
- [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.
|
47 |
+
- [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.
|
48 |
+
|
49 |
+
|
50 |
+
The **Albertina PT-BR** resorted to the [BrWac](https://huggingface.co/datasets/brwac) data set.
|
51 |
+
|
52 |
+
|
53 |
+
## Preprocessing
|
54 |
+
|
55 |
+
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.
|
56 |
+
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.
|
57 |
+
|
58 |
+
# Training
|
59 |
+
|
60 |
+
As codebase, we resorted to the [DeBERTa V2 XLarge](https://huggingface.co/microsoft/deberta-v2-xlarge), for English.
|
61 |
+
|
62 |
+
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.
|
63 |
+
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).
|
64 |
+
We chose a learning rate of 1e-5 with linear decay and 10k warm-up steps based on the results of exploratory experiments.
|
65 |
+
In total, around 200k training steps were taken across 50 epochs.
|
66 |
+
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.
|
67 |
+
|
68 |
+
To train **Albertina-PT-PT**, the data set was tokenized with the original DeBERTa tokenizer with a 128 token sequence truncation and dynamic padding.
|
69 |
+
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).
|
70 |
+
Similarly to the PT-BR variant above, we opted for a learning rate of 1e-5 with linear decay and 10k warm-up steps.
|
71 |
+
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.
|
72 |
+
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.
|
73 |
+
|
74 |
+
# Evaluation
|
75 |
+
|
76 |
+
The models were evaluated on downstream tasks organized into two groups.
|
77 |
+
|
78 |
+
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).
|
79 |
+
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.
|
80 |
+
|
81 |
+
### ASSIN 2
|
82 |
+
|
83 |
+
[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.
|
84 |
+
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.
|
85 |
+
|
86 |
+
| Model | RTE (Accuracy) | STS (Pearson)|
|
87 |
+
|---------------------|----------------|--------------|
|
88 |
+
| **Albertina-PT-BR** | **0.9130** | **0.8676** |
|
89 |
+
| BERTimbau-large | 0.8913 | 0.8531 |
|
90 |
+
|
91 |
+
|
92 |
+
### GLUE tasks translated
|
93 |
+
|
94 |
+
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**.
|
95 |
+
We address four tasks from those in PLUE, namely:
|
96 |
+
- two similarity tasks: MRPC, for detecting whether two sentences are paraphrases of each other, and STS-B, for semantic textual similarity;
|
97 |
+
- and two inference tasks: RTE, for recognizing textual entailment and WNLI, for coreference and natural language inference.
|
98 |
+
|
99 |
+
|
100 |
+
| Model | RTE (Accuracy) | WNLI (Accuracy)| MRPC (F1) | STS-B (Pearson) |
|
101 |
+
|---------------------|----------------|----------------|-----------|-----------------|
|
102 |
+
| **Albertina-PT-BR** | 0.7545 | 0.4601 | 0.9071 | **0.8910** |
|
103 |
+
| BERTimbau-large | 0.6546 | **0.5634** | 0.887 | 0.8842 |
|
104 |
+
| | | | | |
|
105 |
+
| **Albertina-PT-PT** | **0.7960** | 0.4507 | **0.9151**| 0.8799 |
|
106 |
+
|
107 |
+
|
108 |
+
We resorted to [GLUE-PT](https://huggingface.co/datasets/PORTULAN/glueptpt), a **PT-PT version of the GLUE** benchmark.
|
109 |
+
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.
|
110 |
+
|
111 |
+
| Model | RTE (Accuracy) | WNLI (Accuracy)| MRPC (F1) | STS-B (Pearson) |
|
112 |
+
|---------------------|----------------|----------------|-----------|-----------------|
|
113 |
+
| **Albertina-PT-PT** | **0.8339** | **0.4225** | **0.9171**| 0.8801 |
|
114 |
+
| | | | | |
|
115 |
+
| **Albertina-PT-BR** | 0.7942 | 0.4085 | 0.9048 | **0.8847** |
|
116 |
+
|
117 |
+
|
118 |
+
# How to use
|
119 |
+
|
120 |
+
You can use this model directly with a pipeline for masked language modeling:
|
121 |
+
|
122 |
+
```python
|
123 |
+
>>> from transformers import pipeline
|
124 |
+
>>> unmasker = pipeline('fill-mask', model='PORTULAN/albertina-pt-br')
|
125 |
+
>>> unmasker("Países como [MASK] falam a língua portuguesa.")
|
126 |
+
|
127 |
+
[{'score': 0.5964823365211487, 'token': 34214, 'token_str': 'Angola', 'sequence': 'Países como Angola falam a língua portuguesa.'},
|
128 |
+
{'score': 0.12712880969047546, 'token': 9959, 'token_str': 'Portugal', 'sequence': 'Países como Portugal falam a língua portuguesa.'},
|
129 |
+
{'score': 0.07715518027544022, 'token': 30812, 'token_str': 'Macau', 'sequence': 'Países como Macau falam a língua portuguesa.'},
|
130 |
+
{'score': 0.05533565580844879, 'token': 41164, 'token_str': 'Timor', 'sequence': 'Países como Timor falam a língua portuguesa.'},
|
131 |
+
{'score': 0.02593935653567314, 'token': 9716, 'token_str': 'Cuba', 'sequence': 'Países como Cuba falam a língua portuguesa.'}]
|
132 |
+
|
133 |
+
```
|
134 |
+
|
135 |
+
The model can be used by fine-tuning it for a specific task:
|
136 |
+
|
137 |
+
```python
|
138 |
+
>>> from transformers import AutoTokenizer, AutoModelForSequenceClassification, TrainingArguments, Trainer
|
139 |
+
>>> from datasets import load_dataset
|
140 |
+
|
141 |
+
>>> model = AutoModelForSequenceClassification.from_pretrained("PORTULAN/albertina-pt-pt", num_labels=2)
|
142 |
+
>>> tokenizer = AutoTokenizer.from_pretrained("PORTULAN/albertina-pt-pt")
|
143 |
+
>>> dataset = load_dataset("PORTULAN/glueptpt", "rte")
|
144 |
+
|
145 |
+
>>> def tokenize_function(examples):
|
146 |
+
... return tokenizer(examples["sentence1"], examples["sentence2"], padding="max_length", truncation=True)
|
147 |
+
|
148 |
+
>>> tokenized_datasets = dataset.map(tokenize_function, batched=True)
|
149 |
+
|
150 |
+
>>> training_args = TrainingArguments(output_dir="albertina-pt-pt-rte", evaluation_strategy="epoch")
|
151 |
+
>>> trainer = Trainer(
|
152 |
+
... model=model,
|
153 |
+
... args=training_args,
|
154 |
+
... train_dataset=tokenized_datasets["train"],
|
155 |
+
... eval_dataset=tokenized_datasets["validation"],
|
156 |
+
... )
|
157 |
+
|
158 |
+
>>> trainer.train()
|
159 |
+
|
160 |
+
```
|
161 |
+
|
162 |
+
# Citation
|
163 |
+
|
164 |
+
If Albertina proves useful for your work, we kindly ask that you cite the following paper to acknowledge its contribution:
|
165 |
+
|
166 |
+
``` latex
|
167 |
+
@misc{albertina-pt,
|
168 |
+
title={Advancing Neural Encoding of Portuguese with Transformer Albertina PT-*},
|
169 |
+
author={João Rodrigues and Luís Gomes and João Silva and António Branco and Rodrigo Santos and Henrique Lopes and Tomás Osório},
|
170 |
+
year={2023},
|
171 |
+
eprint={?},
|
172 |
+
archivePrefix={arXiv},
|
173 |
+
primaryClass={cs.CL}
|
174 |
+
}
|
175 |
+
```
|
176 |
+
|
177 |
+
# Acknowledgments
|
178 |
+
|
179 |
+
TODO
|