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
+
BERTa is a transformer-based masked language model for the Catalan language.
|
14 |
+
It is based on the [RoBERTA](https://github.com/pytorch/fairseq/tree/master/examples/roberta) base model
|
15 |
+
and has been trained on a medium-size corpus collected from publicly available corpora and crawlers.
|
16 |
+
|
17 |
+
## Training corpora and preprocessing
|
18 |
+
|
19 |
+
The training corpus consists of several corpora gathered from web crawling and public corpora.
|
20 |
+
|
21 |
+
The publicly available corpora are:
|
22 |
+
|
23 |
+
1. the Catalan part of the [DOGC](http://opus.nlpl.eu/DOGC-v2.php) corpus, a set of documents from the Official Gazette of the Catalan Government
|
24 |
+
|
25 |
+
2. the [Catalan Open Subtitles](http://opus.nlpl.eu/download.php?f=OpenSubtitles/v2018/mono/OpenSubtitles.raw.ca.gz), a collection of translated movie subtitles
|
26 |
+
|
27 |
+
3. the non-shuffled version of the Catalan part of the [OSCAR](https://traces1.inria.fr/oscar/) corpus \cite{suarez2019asynchronous},
|
28 |
+
a collection of monolingual corpora, filtered from [Common Crawl](https://commoncrawl.org/about/)
|
29 |
+
|
30 |
+
4. The [CaWac](http://nlp.ffzg.hr/resources/corpora/cawac/) corpus, a web corpus of Catalan built from the .cat top-level-domain in late 2013
|
31 |
+
the non-deduplicated version
|
32 |
+
|
33 |
+
5. the [Catalan Wikipedia articles](https://ftp.acc.umu.se/mirror/wikimedia.org/dumps/cawiki/20200801/) downloaded on 18-08-2020.
|
34 |
+
|
35 |
+
The crawled corpora are:
|
36 |
+
|
37 |
+
6. The Catalan General Crawling, obtained by crawling the 500 most popular .cat and .ad domains
|
38 |
+
7. the Catalan Government Crawling, obtained by crawling the .gencat domain and subdomains, belonging to the Catalan Government
|
39 |
+
|
40 |
+
8. the ACN corpus with 220k news items from March 2015 until October 2020, crawled from the [Catalan News Agency](https://www.acn.cat/)
|
41 |
+
|
42 |
+
To obtain a high-quality training corpus, each corpus have preprocessed with a pipeline of operations, including among the others,
|
43 |
+
sentence splitting, language detection, filtering of bad-formed sentences and deduplication of repetitive contents.
|
44 |
+
During the process, we keep document boundaries are kept.
|
45 |
+
Finally, the corpora are concatenated and further global deduplication among the corpora is applied.
|
46 |
+
The final training corpus consists of about 1,8B tokens.
|
47 |
+
|
48 |
+
|
49 |
+
## Tokenization and pretraining
|
50 |
+
|
51 |
+
The training corpus has been tokenized using a byte version of [Byte-Pair Encoding (BPE)](https://github.com/openai/gpt-2)
|
52 |
+
used in the original [RoBERTA](https://github.com/pytorch/fairseq/tree/master/examples/roberta) model with a vocabulary size of 52,000 tokens.
|
53 |
+
The BERTa pretraining consists of a masked language model training that follows the approach employed for the RoBERTa base model
|
54 |
+
with the same hyperparameters as in the original work.
|
55 |
+
The training lasted a total of 48 hours with 16 NVIDIA V100 GPUs of 16GB DDRAM.
|
56 |
+
|
57 |
+
## Evaluation
|
58 |
+
|
59 |
+
## CLUB benchmark
|
60 |
+
|
61 |
+
The BERTa model has been fine-tuned on the downstream tasks of the Catalan Language Understanding Evaluation benchmark (CLUB),
|
62 |
+
that has been created along with the model.
|
63 |
+
|
64 |
+
It contains the following tasks and their related datasets:
|
65 |
+
|
66 |
+
1. Part-of-Speech Tagging (POS)
|
67 |
+
|
68 |
+
**Catalan-Ancora**: from the [Universal Dependencies treebank](https://github.com/UniversalDependencies/UD_Catalan-AnCora) of the well-known Ancora corpus
|
69 |
+
|
70 |
+
2. Named Entity Recognition (NER)
|
71 |
+
|
72 |
+
**[AnCora Catalan 2.0.0](https://zenodo.org/record/4762031#.YKaFjqGxWUk)**: extracted named entities from the original [Ancora](https://doi.org/10.5281/zenodo.4762030) version,
|
73 |
+
filtering out some unconventional ones, like book titles, and transcribed them into a standard CONLL-IOB format
|
74 |
+
|
75 |
+
3. Text Classification (TC)
|
76 |
+
|
77 |
+
**[TeCla](https://doi.org/10.5281/zenodo.4627197)**: consisting of 137k news pieces from the Catalan News Agency ([ACN](https://www.acn.cat/)) corpus
|
78 |
+
|
79 |
+
4. Semantic Texual Similarity (STS)
|
80 |
+
|
81 |
+
**[Catalan semantic texual similarity](https://doi.org/10.5281/zenodo.4529183)**: consting of more than 3000 sentence pairs, annotated with the semantic similarity between them,
|
82 |
+
scraped from the [Catalan Textual Corpus](https://doi.org/10.5281/zenodo.4519349)
|
83 |
+
|
84 |
+
5. Question Answering (QA):
|
85 |
+
|
86 |
+
**[ViquiQuAD](https://doi.org/10.5281/zenodo.4562344)**: consisting of more than 15,000 questions outsourced from Catalan Wikipedia randomly chosen from a set of 596 articles which were
|
87 |
+
originally written in Catalan.
|
88 |
+
|
89 |
+
**[XQuAD](https://doi.org/10.5281/zenodo.4526223)**: the Catalan translation of XQuAD, a multilingual collection of manual translations of 1,190
|
90 |
+
question-answer pairs from English Wikipedia used only as test set
|
91 |
+
|
92 |
+
## Results
|
93 |
+
|
94 |
+
Below the evaluation results on the CLUB tasks compared with the multilingual mBERT, XLM-RoBERTa models and
|
95 |
+
the Catalan WikiBERT-ca model
|
96 |
+
|
97 |
+
|
98 |
+
| Task | NER (F1) | POS (F1) | STS (Pearson) | TC (accuracy) | QA (ViquiQuAD) (F1/EM) | QA (XQuAD) (F1/EM) |
|
99 |
+
| ------------|:-------------:| -----:|:------|:-------|:------|:----|
|
100 |
+
| BERTa | **88.13** | **98.97** | **79.73** | **74.16** | **86.97/72.29** | **68.89/48.87** |
|
101 |
+
| mBERT | 86.38 | 98.82 | 76.34 | 70.56 | 86.97/72.22 | 67.15/46.51 |
|
102 |
+
| XLM-RoBERTa | 87.66 | 98.89 | 75.40 | 71.68 | 85.50/70.47 | 67.10/46.42 |
|
103 |
+
| WikiBERT-ca | 77.66 | 97.60 | 77.18 | 73.22 | 85.45/70.75 | 65.21/36.60 |
|
104 |
+
|
105 |
+
|
106 |
+
## Intended uses & limitations
|
107 |
+
The model is ready-to-use only for masked language modelling to perform the Fill Mask task (try the inference API or read the next section)
|
108 |
+
However, the is intended to be fine-tuned on non-generative downstream tasks such as Question Answering, Text Classification or Named Entity Recognition.
|
109 |
+
|
110 |
+
---
|
111 |
+
|
112 |
+
## Using BERTa
|
113 |
+
## Load model and tokenizer
|
114 |
+
|
115 |
+
``` python
|
116 |
+
from transformers import AutoTokenizer, AutoModelForMaskedLM
|
117 |
+
|
118 |
+
tokenizer = AutoTokenizer.from_pretrained("bsc/roberta-base-ca-cased")
|
119 |
+
|
120 |
+
model = AutoModelForMaskedLM.from_pretrained("bsc/roberta-base-ca-cased")
|
121 |
+
```
|
122 |
+
|
123 |
+
## Fill Mask task
|
124 |
+
|
125 |
+
Below, an example of how to use the masked language modeling task with a pipeline.
|
126 |
+
|
127 |
+
```python
|
128 |
+
>>> from transformers import pipeline
|
129 |
+
>>> unmasker = pipeline('fill-mask', model='bsc/roberta-base')
|
130 |
+
>>> unmasker("Situada a la costa de la mar Mediterrània, <mask> s'assenta en una plana formada "
|
131 |
+
"entre els deltes de les desembocadures dels rius Llobregat, al sud-oest, "
|
132 |
+
"i Besòs, al nord-est, i limitada pel sud-est per la línia de costa,"
|
133 |
+
"i pel nord-oest per la serralada de Collserola "
|
134 |
+
"(amb el cim del Tibidabo, 516,2 m, com a punt més alt) que segueix paral·lela "
|
135 |
+
"la línia de costa encaixant la ciutat en un perímetre molt definit.")
|
136 |
+
|
137 |
+
[
|
138 |
+
{
|
139 |
+
"sequence": " Situada a la costa de la mar Mediterrània, <mask> s'assenta en una plana formada "
|
140 |
+
"entre els deltes de les desembocadures dels rius Llobregat, al sud-oest, "
|
141 |
+
"i Besòs, al nord-est, i limitada pel sud-est per la línia de costa,"
|
142 |
+
"i pel nord-oest per la serralada de Collserola "
|
143 |
+
"(amb el cim del Tibidabo, 516,2 m, com a punt més alt) que segueix paral·lela "
|
144 |
+
"la línia de costa encaixant la ciutat en un perímetre molt definit.",
|
145 |
+
"score": 0.4177263379096985,
|
146 |
+
"token": 734,
|
147 |
+
"token_str": " Barcelona"
|
148 |
+
},
|
149 |
+
{
|
150 |
+
"sequence": " Situada a la costa de la mar Mediterrània, <mask> s'assenta en una plana formada "
|
151 |
+
"entre els deltes de les desembocadures dels rius Llobregat, al sud-oest, "
|
152 |
+
"i Besòs, al nord-est, i limitada pel sud-est per la línia de costa,"
|
153 |
+
"i pel nord-oest per la serralada de Collserola "
|
154 |
+
"(amb el cim del Tibidabo, 516,2 m, com a punt més alt) que segueix paral·lela "
|
155 |
+
"la línia de costa encaixant la ciutat en un perímetre molt definit.",
|
156 |
+
"score": 0.10696165263652802,
|
157 |
+
"token": 3849,
|
158 |
+
"token_str": " Badalona"
|
159 |
+
},
|
160 |
+
{
|
161 |
+
"sequence": " Situada a la costa de la mar Mediterrània, <mask> s'assenta en una plana formada "
|
162 |
+
"entre els deltes de les desembocadures dels rius Llobregat, al sud-oest, "
|
163 |
+
"i Besòs, al nord-est, i limitada pel sud-est per la línia de costa,"
|
164 |
+
"i pel nord-oest per la serralada de Collserola "
|
165 |
+
"(amb el cim del Tibidabo, 516,2 m, com a punt més alt) que segueix paral·lela "
|
166 |
+
"la línia de costa encaixant la ciutat en un perímetre molt definit.",
|
167 |
+
"score": 0.08135009557008743,
|
168 |
+
"token": 19349,
|
169 |
+
"token_str": " Collserola"
|
170 |
+
},
|
171 |
+
{
|
172 |
+
"sequence": " Situada a la costa de la mar Mediterrània, <mask> s'assenta en una plana formada "
|
173 |
+
"entre els deltes de les desembocadures dels rius Llobregat, al sud-oest, "
|
174 |
+
"i Besòs, al nord-est, i limitada pel sud-est per la línia de costa,"
|
175 |
+
"i pel nord-oest per la serralada de Collserola "
|
176 |
+
"(amb el cim del Tibidabo, 516,2 m, com a punt més alt) que segueix paral·lela "
|
177 |
+
"la línia de costa encaixant la ciutat en un perímetre molt definit.",
|
178 |
+
"score": 0.07330769300460815,
|
179 |
+
"token": 4974,
|
180 |
+
"token_str": " Terrassa"
|
181 |
+
},
|
182 |
+
{
|
183 |
+
"sequence": " Situada a la costa de la mar Mediterrània, <mask> s'assenta en una plana formada "
|
184 |
+
"entre els deltes de les desembocadures dels rius Llobregat, al sud-oest, "
|
185 |
+
"i Besòs, al nord-est, i limitada pel sud-est per la línia de costa,"
|
186 |
+
"i pel nord-oest per la serralada de Collserola "
|
187 |
+
"(amb el cim del Tibidabo, 516,2 m, com a punt més alt) que segueix paral·lela "
|
188 |
+
"la línia de costa encaixant la ciutat en un perímetre molt definit.",
|
189 |
+
"score": 0.03317456692457199,
|
190 |
+
"token": 14333,
|
191 |
+
"token_str": " Gavà"
|
192 |
+
}
|
193 |
+
]
|
194 |
+
```
|
195 |
+
|
196 |
+
|
197 |
+
|
198 |
+
### BibTeX citation
|
199 |
+
|
200 |
+
```bibtex
|
201 |
+
Armengol-Estapé J., Carrino CP., Rodriguez-Penagos C.,
|
202 |
+
de Gibert Bonet O., Armentano-Oller C., Gonzalez-Agirre A., Melero M.
|
203 |
+
and Villegas M., "Are Multilingual Models the Best Choice for Moderately
|
204 |
+
Under-resourced Languages? A Comprehensive Assessment for Catalan".
|
205 |
+
Findings of ACL 2021 (ACL-IJCNLP 2021)
|
206 |
+
```
|