File size: 10,086 Bytes
288670d
3a562ab
 
 
c661549
3a562ab
 
 
 
c661549
2e8dc47
 
0113bf9
2b3f74c
09ede22
2e8dc47
6070c18
 
 
 
 
 
 
 
 
 
 
 
 
8dca82d
 
 
 
 
 
 
 
 
 
 
 
 
d184531
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32425b6
d184531
 
f0c7cd8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d184531
2b3f74c
2e8dc47
f0c7cd8
2e8dc47
288670d
3a562ab
2633116
3a562ab
 
 
 
 
2633116
3a562ab
 
 
 
 
959d19d
3a562ab
 
 
 
 
 
 
 
 
 
959d19d
3a562ab
 
 
 
 
2633116
f4d7257
3a562ab
 
 
2633116
3a562ab
 
 
 
 
 
 
4756dc2
3a562ab
2633116
3a562ab
4756dc2
3a562ab
 
4756dc2
3a562ab
 
 
 
 
 
 
 
 
1332d4e
3a562ab
 
 
 
 
 
 
959d19d
3a562ab
959d19d
3a562ab
 
 
2633116
3a562ab
 
2633116
3a562ab
 
 
 
 
f4d7257
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3a562ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
959d19d
3a562ab
959d19d
3a562ab
 
897f1d0
3a562ab
 
 
 
312bef8
897f1d0
3a562ab
959d19d
 
 
 
 
 
 
 
 
3a562ab
 
716bc85
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
224
225
226
227
228
229
230
231
232
---
language:
- gl
licence:
- MIT
tags:
- galician
- FLOR
- bloom
license: mit
inference:
  parameters:
    top_k: 10
    do_sample: true
    temperature: 0.4
widget:
- text: |-
    Traduce ao galego esta frase en inglés:
    Inglés: "my sister is studying Biology at the university."
    Galego: "a miña irmá está a estudar bioloxía na universidade."
    ----
    Traduce ao galego esta frase en inglés:
    Inglés: "You are working with my mother on a very interesting project."
    Galego: "Estás a traballar coa miña nai nun proxecto moi interesante"
    ----
    Traduce ao galego esta frase en inglés:
    Inglés: "You have to fix the computer now"
    Galego:
  example_title: Translation
- text: |-
    Responde á seguinte pregunta.
    Pregunta: "Cal é a capital de Noruega?"
    Resposta: "A capital de Noruega é Oslo."
    ----
    Responde á seguinte pregunta.
    Pregunta: "Cal é a moeda de Portugal"
    Resposta: "A moeda de Portugal é o euro."
    ----
    Responde á seguinte pregunta.
    Pregunta: "Cal é a capital de Suecia?"
    Resposta:
  example_title: Question&Answering
- text: |-
    Cualifica como Positivo ou Negativo o sentimento da seguinte frase:
    Texto: "Estou moi feliz"
    Polaridade: Positivo
    ----
    Cualifica como Positivo ou Negativo o sentimento da seguinte frase:
    Texto: "Non me gusta beber cervexa"
    Polaridade: Negativo
    ----
    Cualifica como Positivo ou Negativo o sentimento da seguinte frase:
    Texto: "O meu pai detesta o seu traballo"
    Polaridade: Negativo
    ----
    Cualifica como Positivo ou Negativo  o sentimento da seguinte frase:
    Texto: "Uxía desfruta xogando ao fútbol"
    Polaridade: Positivo
    ----
    Cualifica como Positivo ou Negativo  o sentimento da seguinte frase:
    Texto: "O neno non está contento coas notas"
    Polaridade:
  example_title: Sentiment Analysis
- text: |-
    Extrae as entidades nomeadas do seguinte texto:
    Texto: "Chámome Wolfgang e vivo en Berlin"
    Entidades: Wolfgang:PER, Berlin:LOC
    ----
    Extrae as entidades nomeadas do seguinte texto:
    Texto: "María e Miguel non teñen ningún problema"
    Entidades: María:PER, Miguel:PER
    ----
    Extrae as entidades nomeadas do seguinte texto:
    Texto: "O mellor de Barcelona é o bar do meu amigo Pablo"
    Entidades: Pablo:PER, Barcelona:LOC
    ----
    Extrae as entidades nomeadas do seguinte texto:
    Texto: "Carlos comparte cuarto con Marc"
    Entidades:
  example_title: Name Entity Recognition (NER)
- text: A receita tradicional das filloas é
  example_title: Filloas
- text: O neno vivía preto de
  example_title: O neno
---

# Carballo-bloom-1.3B

## Table of Contents
<details>
<summary>Click to expand</summary>

- [Carballo-bloom-1.3B](#carballo-bloom-13)
  - [Table of Contents](#table-of-contents)
  - [Model description](#model-description)
  - [Intended uses and limitations](#intended-uses-and-limitations)
  - [How to use](#how-to-use)
  - [Training](#training)
    - [Tools](#tools)
    - [Language adaptation and training](#language-adaptation-and-training)
    - [Training data](#training-data)
    - [Training hyperparameters](#training-hyperparameters)
    - [Framework](#framework)
  - [Evaluation](#evaluation)
  - [Additional information](#additional-information)
    - [Contact](#contact)
    - [Copyright](#copyright)
    - [License](#license)
    - [Funding](#funding)
  - [Citation information](#citation-information)

</details>

## Model description

**Carballo-bloom-1.3B** is a 1.3B-parameter transformer-based causal language model for Galician. 
It is the result of a continual pretraining of [FLOR-1.3B](https://huggingface.co/projecte-aina/FLOR-1.3B) (developed by [AINA Project](https://projecteaina.cat/) and based in [BLOOM-1.7B](https://huggingface.co/bigscience/bloom-1b7)) with the galician corpus [CorpusNos](https://zenodo.org/records/10687642).

## Intended uses and limitations

The **Carballo-bloom-1.3B** model is ready-to-use only for causal language modeling. 
It can perform text-generation tasks and be fine-tuned for specific scenarios.

## How to use
```python
import torch
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM

input_text = "Hoxe fai un bo día. O sol  "

model_id  = "proxectonos/Carballo-bloom-1.3B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)
generator = pipeline(
    "text-generation",
    model=model,
    tokenizer=tokenizer,
    torch_dtype=torch.bfloat16,
    trust_remote_code=True,
    device_map="auto",
)
generation = generator(
    input_text,
    do_sample=True,
    top_k=10,
    eos_token_id=tokenizer.eos_token_id
)

print(f"Result: {generation[0]['generated_text']}")
```

## Training

### Tools

It was trained using HuggingFace Transformers and Pytorch, using the [Causal Modeling Language script](https://github.com/huggingface/transformers/blob/main/examples/pytorch/language-modeling/run_clm.py)

### Language adaptation and training

The language adaptation technique used to train Carballo-bloom-1.3B is based in the used to train FLOR-1.3B, which is explained by their authors in this [Medium Post](https://medium.com/@mpamies247/flor-6-3b-a-chinchilla-compliant-model-for-catalan-spanish-and-english-7cdb389a9aac). In summary, we proceeded as follows:
1) We trained our own BPE tokenizer for galician and replaced the original FLOR-1.3B tokenizer and vocabulary with it. 
2) The embeddings corresponding to tokens that are present in both the original and the target vocabulary (matching tokens) were used for initialization.
3) The embeddings from tokens not present in Carballo-bloom-1.3B's original vocabulary were initialized as the average of all embeddings.
4) The model was initialized with the weights from FLOR-1.3B and with our adapted tokenizer (step 1) and embeddings (steps 2-3).
5) The model was then trained on a galician corpus.

### Training data

[CorpusNÓS](https://zenodo.org/records/10687642	) is a massive Galician corpus made up of 2.1B words primarily devised for training large language models. The corpus sources are varied and represent a relatively wide range of genres.

The corpus is structured as follows:

| Subcorpus                             | Genre               | Nº tokens      | Nº documents |
|---------------------------------------|---------------------|----------------|--------------|
| Data obtained via transfer agreement  | Books               | 7,255,784      | 104          |
|                                       | Research articles   | 2,665,351      | 664          |
|                                       | Press               | 124,253,084    | 224,419      |
|                                       | Governmental        | 245,897,880    | 654,505      |
|                                       | Web contents        | 15,946,686     | 44,165       |
|                                       | Encyclopedic        | 4,799,214      | 47,396       |
|                                       | Subtotal            | 400,817,999    | 971,253      |

| Subcorpus                             | Genre               | Nº tokens      | Nº documents |
|---------------------------------------|---------------------|----------------|--------------|
| Public data                           | Press and blogs     | 153,497,883    | 665,265      |
|                                       | Encyclopedic        | 57,164,848     | 184,628      |
|                                       | Web crawls          | 1,384,015,664  | 3,366,449    |
|                                       | Translation corpora | 133,726,004    | 4,745,799    |
|                                       | Subtotal            | 1,728,404,399  | 8,777,514    |
|                                       | Total               | 2,129,222,398  | 9,748,767    |
| Download (Zenodo)                     | https://zenodo.org/records/10687642                 |                                    


### Training hyperparameters

- seed: 42
- num_devices: 1
- train_batch_size: 2
- eval_batch_size:  2
- gradient_acummulation: 4
- optimizer: AdamW
- betas: (0.9,0.999)
- epsilon: 1e-08
- weight_decay_rate: 0.1
- scheduler: "Linear" 
- learning_rate: 5e-05
- num_epochs: 1.2

### Framework
The traininf was conducted in the Galicia Supercomputing Center ([CESGA](https://www.cesga.es/en/home-2/)), using 1 node with 5 GPUs NVIDIA A100.

## Evaluation
TO-DO

## Additional information

### Contact

For further information, please send an email to <[email protected]>
### License
MIT License

Copyright (c) 2024 Proxecto Nós

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

### Funding
This research was funded by “The Nós project: Galician in the society and economy of Artificial Intelligence”, resulting from the agreement 2021-CP080 between the Xunta de Galicia and the University of Santiago de Compostela, and thanks to the Investigo program, within the National Recovery, Transformation and Resilience Plan, within the framework of the European Recovery Fund (NextGenerationEU).