File size: 12,541 Bytes
3ddd435
13d2dee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3ddd435
13d2dee
 
 
 
 
 
3ddd435
13d2dee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c7ea3e1
13d2dee
 
 
c7ea3e1
 
 
 
 
 
13d2dee
c7ea3e1
13d2dee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c7ea3e1
13d2dee
 
 
c7ea3e1
 
 
 
 
 
13d2dee
c7ea3e1
13d2dee
 
 
 
 
 
 
 
 
 
 
 
 
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
222
223
---
language:
- pt
tags:
- albertina-pt*
- albertina-100m-portuguese-ptpt
- albertina-100m-portuguese-ptbr
- albertina-900m-portuguese-ptpt
- albertina-900m-portuguese-ptbr
- albertina-1b5-portuguese-ptpt
- albertina-1b5-portuguese-ptbr
- fill-mask
- bert
- deberta
- portuguese
- encoder
- foundation model
license: mit
datasets:
- PORTULAN/glue-ptpt
widget:
- text: >-
    A culinária portuguesa é rica em sabores e [MASK], tornando-se um dos
    maiores tesouros do país.
---
---
<img align="left" width="40" height="40" src="https://github.githubassets.com/images/icons/emoji/unicode/1f917.png">
<p style="text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;This is the model card for Albertina 1.5B PTBR. 
  You may be interested in some of the other models in the <a href="https://huggingface.co/PORTULAN">Albertina (encoders) and Gervásio (decoders) families</a>.
</p>

---

# Albertina 1.5B PTBR


**Albertina 1.5B PTBR** is a foundation, large language model for the **American variant of Portuguese**.

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, spoken in Portugal (**PTPT**) and the American variant, spoken in Brazil (**PTBR**), 
and it is openly distributed free of charge under an open license.

| Albertina's Family of Models                                                                             | 
|----------------------------------------------------------------------------------------------------------|
| [**Albertina 1.5B PTPT**](https://huggingface.co/PORTULAN/albertina-1b5-portuguese-ptpt-encoder)        |
| [**Albertina 1.5B PTBR**](https://huggingface.co/PORTULAN/albertina-1b5-portuguese-ptbr-encoder)        |
| [**Albertina 1.5B PTPT 256**](https://huggingface.co/PORTULAN/albertina-1b5-portuguese-ptpt-encoder-256)|
| [**Albertina 1.5B PTBR 256**](https://huggingface.co/PORTULAN/albertina-1b5-portuguese-ptbr-encoder-256)|
| [**Albertina 900M PTPT**](https://huggingface.co/PORTULAN/albertina-900m-portuguese-ptpt-encoder)       |
| [**Albertina 900M PTBR**](https://huggingface.co/PORTULAN/albertina-900m-portuguese-ptbr-encoder)       |
| [**Albertina 100M PTPT**](https://huggingface.co/PORTULAN/albertina-100m-portuguese-ptpt-encoder)       |
| [**Albertina 100M PTBR**](https://huggingface.co/PORTULAN/albertina-100m-portuguese-ptbr-encoder)       |

**Albertina 1.5B PTBR** is a version for the **American variant of Portuguese**, 
and to the best of our knowledge, this is an encoder specifically for this language and variant 
that,  at the time of its initial distribution, with its 1.5 billion parameters and performance scores sets a new state of the art for it, 
and is made publicly available and distributed for reuse.

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 is distributed free of charge and under a most permissible license.


**Albertina 1.5B PTBR** is developed by a joint team from the University of Lisbon and the University of Porto, Portugal. 
For a fully detailed description, check the respective [publication](https://arxiv.org/abs/2403.01897):

``` latex
@misc{albertina-pt-fostering,
      title={Fostering the Ecosystem of Open Neural Encoders
            for Portuguese with Albertina PT-* family}, 
      author={Rodrigo Santos and João Rodrigues and Luís Gomes
              and João Silva and António Branco
              and Henrique Lopes Cardoso and Tomás Freitas Osório
              and Bernardo Leite},
      year={2024},
      eprint={2403.01897},
      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 1.5B PTBR**, with 1.5 billion parameters, 48 layers and a hidden size of 1536.

Albertina 1.5B PTBR is distributed under an [MIT license](https://huggingface.co/PORTULAN/albertina-ptpt/blob/main/LICENSE).

DeBERTa is distributed under an [MIT license](https://github.com/microsoft/DeBERTa/blob/master/LICENSE).


<br>

# Training Data

[**Albertina 1.5B PTBR**](https://huggingface.co/PORTULAN/albertina-1b5-portuguese-ptbr-encoder) was trained over a 36 billion token data set that resulted from gathering some openly available corpora of American Portuguese from the following sources:

- [CulturaX](https://huggingface.co/datasets/uonlp/CulturaX): the CulturaX is a multilingual corpus, freely available for research and AI development, created by combining and extensively cleaning two other large datasets, mC4 and OSCAR. 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.

## Preprocessing

We filtered the PTBR corpora using the [BLOOM pre-processing](https://github.com/bigscience-workshop/data-preparation) 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 V2 xxlarge](https://huggingface.co/microsoft/deberta-v2-xxlarge), for English.

To train **Albertina 1.5B PTBR**, the data set was tokenized with the original DeBERTa tokenizer with a 128-token sequence 
truncation and dynamic padding for 250k steps, 
a 256-token sequence-truncation for 80k steps 
([**Albertina 1.5B PTBR 256**](https://huggingface.co/PORTULAN/albertina-1b5-portuguese-ptbr-encoder-256)) and finally a 512-token sequence-truncation for 60k steps.
These steps correspond to the equivalent setup of 48 hours on a2-megagpu-16gb Google Cloud A2 node for the 128-token input sequences, 24 hours of computation for the 256-token 
input sequences and 24 hours of computation for the 512-token input sequences.
We opted for a learning rate of 1e-5 with linear decay and 10k warm-up steps. 

<br>

# Performance


We resorted to [extraGLUE](https://huggingface.co/datasets/PORTULAN/extraglue), a **PTBR version of the GLUE and SUPERGLUE** benchmark.
We automatically translated the tasks from GLUE and SUPERGLUE using [DeepL Translate](https://www.deepl.com/), which specifically 
provides translation from English to PTPT or PTBR as possible options.


| Model                         | RTE (Accuracy) | WNLI (Accuracy)| MRPC (F1) | STS-B (Pearson) | COPA (Accuracy) | CB (F1)    | MultiRC (F1) | BoolQ (Accuracy) |
|-------------------------------|----------------|----------------|-----------|-----------------|-----------------|------------|--------------|------------------|
| [**Albertina 1.5B PTBR**](https://huggingface.co/PORTULAN/albertina-1b5-portuguese-ptbr-encoder)      | **0.8676**     | 0.4742         | 0.8622    | **0.9007**      | 0.7767          | 0.6372     | **0.7667**   | **0.8654**       | 
| [**Albertina 1.5B PTBR 256**](https://huggingface.co/PORTULAN/albertina-1b5-portuguese-ptbr-encoder-256)  |  0.8123        | 0.4225         | 0.8638    | 0.8968          | **0.8533**      | **0.6884** | 0.6799       | 0.8509           |
| [**Albertina 900M PTBR**](https://huggingface.co/PORTULAN/albertina-900m-portuguese-ptbr-encoder)      |  0.7545        | 0.4601         | **0.9071**| 0.8910          | 0.7767          | 0.5799     | 0.6731       | 0.8385           |
| **BERTimbau (335M)**          |  0.6446        | **0.5634**     | 0.8873    | 0.8842          | 0.6933          | 0.5438     | 0.6787       | 0.7783           |
| [**Albertina 100M PTBR**](https://huggingface.co/PORTULAN/albertina-100m-portuguese-ptbr-encoder)      |  0.6582        | **0.5634**     | 0.8149    | 0.8489          | n.a.            | 0.4771     | 0.6469       | 0.7537           |
||||||||||
| **DeBERTa 1.5B (English)**           |  0.7112        | **0.5634**     | 0.8545    | 0.0123          | 0.5700          | 0.4307     | 0.3639       | 0.6217           |
| **DeBERTa 100M (English)**           |  0.5716        | 0.5587         | 0.8060    | 0.8266          | n.a.            | 0.4739     | 0.6391       | 0.6838           |


<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-1b5-portuguese-ptbr-encoder')
>>> 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:

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

>>> model = AutoModelForSequenceClassification.from_pretrained("PORTULAN/albertina-1b5-portuguese-ptbr-encoder", num_labels=2)
>>> tokenizer = AutoTokenizer.from_pretrained("PORTULAN/albertina-1b5-portuguese-ptbr-encoder")
>>> dataset = load_dataset("PORTULAN/glue-ptbr", "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-ptbr-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](https://arxiv.org/abs/2403.01897):

``` latex
@misc{albertina-pt-fostering,
      title={Fostering the Ecosystem of Open Neural Encoders
            for Portuguese with Albertina PT-* family}, 
      author={Rodrigo Santos and João Rodrigues and Luís Gomes
              and João Silva and António Branco
              and Henrique Lopes Cardoso and Tomás Freitas Osório
              and Bernardo Leite},
      year={2024},
      eprint={2403.01897},
      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; 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.