File size: 10,248 Bytes
4efc66f
c1cb1f7
 
 
 
 
 
 
 
 
 
 
 
 
4efc66f
995f29d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4efc66f
 
29e4bd8
4efc66f
c1cb1f7
 
 
4efc66f
c527d4c
c1cb1f7
 
 
 
 
 
 
 
 
 
 
 
 
 
4efc66f
c1cb1f7
4efc66f
c1cb1f7
4efc66f
29e4bd8
c1cb1f7
4efc66f
9d25735
c1cb1f7
4efc66f
29e4bd8
c1cb1f7
4efc66f
c1cb1f7
 
 
 
4efc66f
c1cb1f7
4efc66f
29e4bd8
c1cb1f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4efc66f
c1cb1f7
 
4efc66f
c1cb1f7
4efc66f
c1cb1f7
4efc66f
c1cb1f7
4efc66f
 
c1cb1f7
4efc66f
 
c1cb1f7
4efc66f
c1cb1f7
4efc66f
c1cb1f7
 
 
 
 
 
4efc66f
 
c1cb1f7
4efc66f
c1cb1f7
 
 
 
 
 
 
 
 
 
 
 
4efc66f
c1cb1f7
 
4efc66f
 
5c4cf16
 
 
 
 
 
 
 
 
f7c66b7
5c4cf16
 
 
 
 
 
 
 
4efc66f
c1cb1f7
4efc66f
c1cb1f7
4efc66f
c1cb1f7
 
 
4efc66f
c1cb1f7
4efc66f
c1cb1f7
4efc66f
c1cb1f7
4efc66f
c1cb1f7
4efc66f
c1cb1f7
ecd364f
 
 
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
---
language:
- gl
- es
- en
- pt
licence:
- MIT
tags:
- Llama
license: llama3.1
base_model:
- meta-llama/Llama-3.1-8B
pipeline_tag: text-generation
library_name: transformers
model-index:
- name: Llama-Carvalho-PT-GL
  results:
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: ENEM Challenge (No Images)
      type: eduagarcia/enem_challenge
      split: train
      args:
        num_few_shot: 3
    metrics:
    - type: acc
      value: 19.38
      name: accuracy
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=Nos-PT/Llama-Carvalho-PT-GL
      name: Open Portuguese LLM Leaderboard
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: BLUEX (No Images)
      type: eduagarcia-temp/BLUEX_without_images
      split: train
      args:
        num_few_shot: 3
    metrics:
    - type: acc
      value: 18.92
      name: accuracy
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=Nos-PT/Llama-Carvalho-PT-GL
      name: Open Portuguese LLM Leaderboard
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: Assin2 RTE
      type: assin2
      split: test
      args:
        num_few_shot: 15
    metrics:
    - type: f1_macro
      value: 89.3
      name: f1-macro
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=Nos-PT/Llama-Carvalho-PT-GL
      name: Open Portuguese LLM Leaderboard
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: Assin2 STS
      type: eduagarcia/portuguese_benchmark
      split: test
      args:
        num_few_shot: 15
    metrics:
    - type: pearson
      value: 78.18
      name: pearson
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=Nos-PT/Llama-Carvalho-PT-GL
      name: Open Portuguese LLM Leaderboard
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: FaQuAD NLI
      type: ruanchaves/faquad-nli
      split: test
      args:
        num_few_shot: 15
    metrics:
    - type: f1_macro
      value: 65.88
      name: f1-macro
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=Nos-PT/Llama-Carvalho-PT-GL
      name: Open Portuguese LLM Leaderboard
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: HateBR Binary
      type: ruanchaves/hatebr
      split: test
      args:
        num_few_shot: 25
    metrics:
    - type: f1_macro
      value: 82.83
      name: f1-macro
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=Nos-PT/Llama-Carvalho-PT-GL
      name: Open Portuguese LLM Leaderboard
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: PT Hate Speech Binary
      type: hate_speech_portuguese
      split: test
      args:
        num_few_shot: 25
    metrics:
    - type: f1_macro
      value: 64.84
      name: f1-macro
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=Nos-PT/Llama-Carvalho-PT-GL
      name: Open Portuguese LLM Leaderboard
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: tweetSentBR
      type: eduagarcia/tweetsentbr_fewshot
      split: test
      args:
        num_few_shot: 25
    metrics:
    - type: f1_macro
      value: 61.15
      name: f1-macro
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=Nos-PT/Llama-Carvalho-PT-GL
      name: Open Portuguese LLM Leaderboard
---

# Llama-Carvalho-PT-GL

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

- [Llama-Carvalho-PT-GL](#llama-carvalho-pt-gl)
  - [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)
    - [Training data](#training-data)
    - [Training hyperparameters](#training-hyperparameters)
    - [Framework](#framework)
  - [Evaluation](#evaluation)
  - [Additional information](#additional-information)
    - [Contact](#contact)
    - [License](#license)
    - [Funding](#funding)

</details>

## Model description

**Llama-Carvalho-PT-GL** is a 8B-parameter transformer-based causal language model for Galician, Portuguese, Spanish and English. 
It is the result of a continual pretraining of [meta-llama/Llama-3.1-8B](https://huggingface.co/meta-llama/Llama-3.1-8B) with a multilingual corpus consisting of 540M tokens of plain text and 72M tokens of instructions (formated as plain text)

This model is part of the **Carvalho familily**, a family of LLMs specialized in Portuguese and Galician which can be found [here](https://huggingface.co/collections/Nos-PT/carvalho-family-67e423bf209c732396377b61).
## Intended uses and limitations

The **Llama-Carvalho-PT-GL** 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  = "Nos-PT/Llama-Carvalho-PT-GL"
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). We also use [DeepSpeed](https://github.com/microsoft/DeepSpeed) to deal with the huge size of the model.


### Training data


The training corpus consists of texts in 4 languages, with an emphasis on Portuguese and Galician. The main aim of this is to ensure that the model learns to work with this language perfectly, while maintaining knowledge of languages already known (Spanish, English), learning others (Galician) or adapting existing language varieties (Portuguese-PT instead of Portuguese-BR).

The corpus is composed as follows:

| **Corpus**                 |                                               | **gl** | **pt** | **es** | **en** |
|----------------------------|-----------------------------------------------|--------|--------|--------|--------|
| **Base plain text corpus** | Tokens                                        | 232M   | 250M   | 29M    | 29M    |
|                            | Percentage (of the total base corpus)         | 42,96% | 46,29% | 5,37%  | 5,37%  |
| **Instructions**           | Tokens                                        | 26,7M  | 44M    | 804K   | 623K   |
|                            | Percentage (of the total instructions corpus) | 37,01% | 61,00% | 1,11%  | 0,86%  |                              


### Training hyperparameters

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

### Framework
The training was conducted on the MareNostrum V in the Barcelona Supercomputing Center ([BSC](https://www.bsc.es/ca/marenostrum/marenostrum-5)), using 10 nodes with 4 GPUs NVIDIA H100 64GB each one.

## Evaluation

### Galician and European Portuguese
Soon...
### American Portuguese: Open Portuguese LLM Leaderboard Evaluation Results  

Detailed results can be found [here](https://huggingface.co/datasets/eduagarcia-temp/llm_pt_leaderboard_raw_results/tree/main/Nos-PT/Llama-Carvalho-PT-GL) and on the [🚀 Open Portuguese LLM Leaderboard](https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard)

|          Metric          |  Value  |
|--------------------------|---------|
|Average                   |**60.06**|
|ENEM Challenge (No Images)|    19.38|
|BLUEX (No Images)         |    18.92|
|Assin2 RTE                |    89.30|
|Assin2 STS                |    78.18|
|FaQuAD NLI                |    65.88|
|HateBR Binary             |    82.83|
|PT Hate Speech Binary     |    64.84|
|tweetSentBR               |    61.15|

## Additional information

### Contact

For further information, please send an email to 
### License
MIT License

Copyright (c) 2024 

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 model was developed within the projects:
- Nós, funded by the Ministerio para la Transformación Digital y de la Función Pública - Funded by EU – NextGenerationEU within the framework of the [project ILENIA](https://proyectoilenia.es/) with reference 2022/TL22/00215336.
- AiBERTA, funded by the Portuguese Foundation for Science and Technology with reference 2022.03882.PTDC