Commit
•
28246a4
1
Parent(s):
9ddff5b
Update README (#2)
Browse files- Update README (cbd36a5f3a8cb33770308b50f1c7ff8810406051)
Co-authored-by: Eduardo Muñoz Sala <[email protected]>
README.md
CHANGED
@@ -8,94 +8,104 @@ tags:
|
|
8 |
- sft
|
9 |
- generated_from_trainer
|
10 |
base_model: google/gemma-7b
|
|
|
|
|
11 |
---
|
12 |
|
13 |
-
|
|
|
14 |
|
15 |
-
|
16 |
|
|
|
|
|
17 |
|
|
|
18 |
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
|
|
|
|
|
|
21 |
|
22 |
### Model Description
|
23 |
|
24 |
-
<!--
|
25 |
-
|
26 |
|
27 |
-
This
|
28 |
|
29 |
-
|
30 |
|
31 |
-
- **Language(s) (NLP):** [Spanish]
|
32 |
-
- **Finetuned from model [optional]:** [google/gemma-7b](https://huggingface.co/google/gemma-7b)
|
33 |
|
34 |
-
|
|
|
|
|
|
|
35 |
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
38 |
|
|
|
39 |
|
40 |
-
|
|
|
|
|
41 |
|
42 |
-
|
43 |
|
|
|
|
|
44 |
|
45 |
-
##
|
46 |
|
47 |
-
|
48 |
|
|
|
49 |
|
50 |
-
|
51 |
|
52 |
-
|
53 |
|
54 |
-
|
55 |
-
We wanted to make a conversation model so we investigated the base model prompt in order to make conversational base on [chatml format](https://github.com/MicrosoftDocs/azure-docs/blob/main/articles/ai-services/openai/includes/chat-markup-language.md#working-with-chat-markup-language-chatml)
|
56 |
|
57 |
-
|
58 |
|
59 |
-
|
60 |
-
```
|
61 |
-
<bos><|im_start|>system
|
62 |
-
You are Gemma.<|im_end|>
|
63 |
-
<|im_start|>user
|
64 |
-
Hello, how are you?<|im_end|>
|
65 |
-
<|im_start|>assistant
|
66 |
-
I'm doing great. How can I help you today?<|im_end|>\n<eos>
|
67 |
-
```
|
68 |
|
69 |
-
|
70 |
|
71 |
-
|
72 |
-
The training was done using RTX 4090 from Vast.ai with PeRF and Lora
|
73 |
|
74 |
-
|
75 |
|
76 |
-
|
77 |
-
- learning_rate: 5e-05
|
78 |
-
- train_batch_size: 2
|
79 |
-
- eval_batch_size: 8
|
80 |
-
- seed: 66
|
81 |
-
- gradient_accumulation_steps: 2
|
82 |
-
- total_train_batch_size: 4
|
83 |
-
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
|
84 |
-
- lr_scheduler_type: constant
|
85 |
-
- lr_scheduler_warmup_ratio: 0.03
|
86 |
-
- num_epochs: 3
|
87 |
|
88 |
-
|
89 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact/#compute) presented in Lacoste et al. (2019).
|
90 |
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
|
|
96 |
|
|
|
97 |
|
98 |
-
|
99 |
|
100 |
```python
|
101 |
import torch
|
@@ -107,8 +117,8 @@ from transformers import (
|
|
107 |
pipeline
|
108 |
)
|
109 |
|
110 |
-
model_id = "somosnlp/gemma-7b-it-legal-
|
111 |
-
tokenizer_id = "somosnlp/gemma-7b-it-legal-
|
112 |
|
113 |
tokenizer = AutoTokenizer.from_pretrained(tokenizer_id)
|
114 |
# Cargamos el modelo en 4 bits para agilizar la inferencia
|
@@ -143,4 +153,189 @@ input = "b) Hechos que motivan la incoación del procedimiento sucintamente expu
|
|
143 |
|
144 |
response = test_inference(instruction, input, 0.3)
|
145 |
print(f"Response:\n{response}")
|
146 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
- sft
|
9 |
- generated_from_trainer
|
10 |
base_model: google/gemma-7b
|
11 |
+
datasets:
|
12 |
+
- somosnlp/instruct-legal-refugiados-es
|
13 |
---
|
14 |
|
15 |
+
<!--
|
16 |
+
Esta plantilla de Model Card es una adaptación de la de Hugging Face: https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/modelcard_template.md
|
17 |
|
18 |
+
¿Cómo utilizar esta plantilla? Copia el contenido en el README.md del repo de tu modelo en el Hub de Hugging Face y rellena cada sección.
|
19 |
|
20 |
+
Para más información sobre cómo rellenar cada sección ver las docs: https://huggingface.co/docs/hub/model-cards
|
21 |
+
-->
|
22 |
|
23 |
+
# Model Card for gemma-7b-it-legal-refugiados-es
|
24 |
|
25 |
+
<!-- Suele haber un nombre corto ("pretty name") para las URLs, tablas y demás y uno largo más descriptivo. Para crear el pretty name podéis utilizar acrónimos. -->
|
26 |
+
|
27 |
+
<!-- Resumen del modelo y motivación del proyecto (inc. los ODS relacionados). Esta sección es como el abstract. También se puede incluir aquí el logo del proyecto. -->
|
28 |
+
|
29 |
+
<!-- Si queréis incluir una versión de la Dataset Card en español, enlazarla aquí al principio (e.g. `README_es.md`).-->
|
30 |
+
|
31 |
+
Spain is the third country with the highest number of asylum applications, receiving each year approximately more than 100,000 applications, and the third with the lowest number of approvals within the EU.
|
32 |
+
|
33 |
+
The main objective of this project is to facilitate the tasks of NGOs in this field and other institutions and help them to obtain answers to questions (QA) related to refugee legislation in Spanish. With its refined understanding of the nuances and complexities of this legal field.
|
34 |
|
35 |
+
The objective of this model is to facilitate question answering (QA) tasks pertaining to Spanish refugee legislation. With its refined understanding of the nuances and intricacies of this legal domain
|
36 |
+
|
37 |
+
## Model Details
|
38 |
|
39 |
### Model Description
|
40 |
|
41 |
+
<!-- Resumen del modelo. -->
|
42 |
+
The objective of this model is to facilitate question answering (QA) tasks pertaining to Spanish refugee legislation. With its refined understanding of the nuances and intricacies of this legal domain.
|
43 |
|
44 |
+
This model is a fine-tuned version of [google/gemma-7b](https://huggingface.co/google/gemma-7b) on the dataset [AsistenciaRefugiados](https://huggingface.co/datasets/somosnlp/instruct-legal-refugiados-es).
|
45 |
|
46 |
+
This is the model card of a 🤗 transformers model that has been pushed on the Hub to allow public access.
|
47 |
|
|
|
|
|
48 |
|
49 |
+
- **Developed by:** <!-- Nombre de los miembros del equipo -->
|
50 |
+
[Alvaro Hidalgo](https://huggingface.co/hacendado)
|
51 |
+
[Eduardo Muñoz](https://huggingface.co/edumunozsala)
|
52 |
+
[Teresa Martin](https://huggingface.co/narhim)
|
53 |
|
54 |
+
- **Funded by:** SomosNLP, HuggingFace <!-- Si contasteis con apoyo de otra entidad (e.g. vuestra universidad), añadidla aquí -->
|
55 |
+
- **Model type:** Language model, instruction tuned
|
56 |
+
- **Language(s):** es-ES, es-MX, es-VE <!-- Enumerar las lenguas en las que se ha entrenado el modelo, especificando el país de origen. Utilizar códigos ISO. Por ejemplo: Spanish (`es-CL`, `es-ES`, `es-MX`), Catalan (`ca`), Quechua (`qu`). -->
|
57 |
+
- **License:** apache-2.0 <!-- Elegid una licencia lo más permisiva posible teniendo en cuenta la licencia del model pre-entrenado y los datasets utilizados -->
|
58 |
+
- **Fine-tuned from model:** [google/gemma-7b](https://huggingface.co/google/ <!-- Enlace al modelo pre-entrenado que habéis utilizado como base -->
|
59 |
+
- **Dataset used:** [AsistenciaRefugiados](https://huggingface.co/datasets/somosnlp/instruct-legal-refugiados-es) <!-- Enlace al dataset utilizado para el ajuste -->
|
60 |
|
61 |
+
### Model Sources
|
62 |
|
63 |
+
- **Repository:** Notebook in [This repo](https://huggingface.co/somosnlp/gemma-7b-it-legal-refugee-v0.1.1) <!-- Enlace al `main` del repo donde tengáis los scripts, i.e.: o del mismo repo del modelo en HuggingFace o a GitHub. -->
|
64 |
+
- **Demo:** [Demo Space](https://huggingface.co/spaces/somosnlp/QA-legal-refugiados) <!-- Enlace a la demo -->
|
65 |
+
- **Video presentation:** [Youtube Video](https://www.youtube.com/watch?v=1OqHDE5LKMI&list=PLTA-KAy8nxaASMwEUWkkTfMaDxWBxn-8J&index=3) <!-- Enlace a vuestro vídeo de presentación en YouTube (están todos subidos aquí: https://www.youtube.com/playlist?list=PLTA-KAy8nxaASMwEUWkkTfMaDxWBxn-8J) -->
|
66 |
|
67 |
+
### Model Family
|
68 |
|
69 |
+
<!-- Si habéis entrenado varios modelos similares podéis enumerarlos aquí. -->
|
70 |
+
This model is a fine-tuned version of [google/gemma-7b](https://huggingface.co/google/gemma-7b).
|
71 |
|
72 |
+
## Uses
|
73 |
|
74 |
+
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
75 |
|
76 |
+
### Direct Use
|
77 |
|
78 |
+
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
79 |
|
80 |
+
The primary objective of this model is to facilitate question answering (QA) tasks pertaining to Spanish refugee legislation. With its refined understanding of the nuances and intricacies of this legal domain.
|
81 |
|
82 |
+
### Downstream Use
|
|
|
83 |
|
84 |
+
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
85 |
|
86 |
+
Intented to be use in question-answering with a context and text generation.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
+
### Out-of-Scope Use
|
89 |
|
90 |
+
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
|
|
91 |
|
92 |
+
Misuse includes any application that promotes unethical practices, misinterprets refugee law, or uses the model for malicious purposes. The model is not designed to replace professional legal advice.
|
93 |
|
94 |
+
## Bias, Risks, and Limitations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
+
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
|
|
97 |
|
98 |
+
The model, while powerful, has limitations inherent to AI, including biases present in the training data. It may not cover all nuances of refugee regulations or adapt to changes in law without updates.
|
99 |
+
|
100 |
+
### Recommendations
|
101 |
+
|
102 |
+
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
103 |
+
|
104 |
+
<!-- Example: Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations. -->
|
105 |
|
106 |
+
## How to Get Started with the Model
|
107 |
|
108 |
+
Use the code below to get started with the model.
|
109 |
|
110 |
```python
|
111 |
import torch
|
|
|
117 |
pipeline
|
118 |
)
|
119 |
|
120 |
+
model_id = "somosnlp/gemma-7b-it-legal-refugiados-es"
|
121 |
+
tokenizer_id = "somosnlp/gemma-7b-it-legal-refugiados-es"
|
122 |
|
123 |
tokenizer = AutoTokenizer.from_pretrained(tokenizer_id)
|
124 |
# Cargamos el modelo en 4 bits para agilizar la inferencia
|
|
|
153 |
|
154 |
response = test_inference(instruction, input, 0.3)
|
155 |
print(f"Response:\n{response}")
|
156 |
+
```
|
157 |
+
## Training Details
|
158 |
+
|
159 |
+
### Training Data
|
160 |
+
|
161 |
+
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
162 |
+
The dataset used was [instruct-legal-refugiados-es](https://huggingface.co/datasets/somosnlp/instruct-legal-refugiados-es) but we adapted the dataset to a ChatML format, described in the next section.
|
163 |
+
|
164 |
+
### Training Procedure
|
165 |
+
|
166 |
+
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
167 |
+
|
168 |
+
<!-- Detallar la técnica de entrenamiento utilizada y enlazar los scripts/notebooks. -->
|
169 |
+
The training was done using RTX 4090 from Vast.ai with PeRF and Lora
|
170 |
+
|
171 |
+
#### Preprocessing
|
172 |
+
|
173 |
+
We wanted to make a conversation model so we investigated the base model prompt in order to make conversational base on [chatml format](https://github.com/MicrosoftDocs/azure-docs/blob/main/articles/ai-services/openai/includes/chat-markup-language.md#working-with-chat-markup-language-chatml)
|
174 |
+
|
175 |
+
we identified the special tokens so the model could understand the different roles in the conversation
|
176 |
+
|
177 |
+
Example
|
178 |
+
```
|
179 |
+
<bos><|im_start|>system
|
180 |
+
You are Gemma.<|im_end|>
|
181 |
+
<|im_start|>user
|
182 |
+
Hello, how are you?<|im_end|>
|
183 |
+
<|im_start|>assistant
|
184 |
+
I'm doing great. How can I help you today?<|im_end|>\n<eos>
|
185 |
+
```
|
186 |
+
So we used [Phil Schmid's gemma chatml tokenizer](https://huggingface.co/philschmid/gemma-tokenizer-chatml) to adapt our dataset for training
|
187 |
+
|
188 |
+
#### Training Hyperparameters
|
189 |
+
|
190 |
+
<!-- Enumerar los valores de los hiperparámetros de entrenamiento. -->
|
191 |
+
The following hyperparameters were used during training:
|
192 |
+
- learning_rate: 5e-05
|
193 |
+
- train_batch_size: 2
|
194 |
+
- eval_batch_size: 8
|
195 |
+
- seed: 66
|
196 |
+
- gradient_accumulation_steps: 2
|
197 |
+
- total_train_batch_size: 4
|
198 |
+
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
|
199 |
+
- lr_scheduler_type: constant
|
200 |
+
- lr_scheduler_warmup_ratio: 0.03
|
201 |
+
- num_epochs: 3
|
202 |
+
|
203 |
+
|
204 |
+
- **Training regime:** <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
205 |
+
|
206 |
+
## Evaluation
|
207 |
+
|
208 |
+
<!-- This section describes the evaluation protocols and provides the results. -->
|
209 |
+
|
210 |
+
### Testing Data, Factors & Metrics
|
211 |
+
|
212 |
+
#### Testing Data
|
213 |
+
|
214 |
+
<!-- This should link to a Dataset Card. -->
|
215 |
+
|
216 |
+
[More Information Needed]
|
217 |
+
|
218 |
+
#### Factors
|
219 |
+
|
220 |
+
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
221 |
+
|
222 |
+
[More Information Needed]
|
223 |
+
|
224 |
+
#### Metrics
|
225 |
+
|
226 |
+
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
227 |
+
|
228 |
+
[More Information Needed]
|
229 |
+
|
230 |
+
### Results
|
231 |
+
|
232 |
+
<!-- Enlazar aquí los scripts/notebooks de evaluación y especificar los resultados. -->
|
233 |
+
|
234 |
+
[More Information Needed]
|
235 |
+
|
236 |
+
## Environmental Impact
|
237 |
+
|
238 |
+
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly. -->
|
239 |
+
|
240 |
+
<!-- Rellenar la información de la lista y calcular las emisiones con la página mencionada. -->
|
241 |
+
|
242 |
+
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
243 |
+
|
244 |
+
- **Hardware Type**: 1 X RTX4090
|
245 |
+
- **Hours used**: 4
|
246 |
+
- **Cloud Provider**: Vast.ai
|
247 |
+
- **Compute Region**: West Europe
|
248 |
+
- **Carbon Emitted**: 350W x 4h = 1.4 kWh x 0.57 kg eq. CO2/kWh = 0.8 kg eq. CO2
|
249 |
+
|
250 |
+
## Technical Specifications
|
251 |
+
|
252 |
+
<!-- Esta sección es opcional porque seguramente ya habéis mencionado estos detalles más arriba, igualmente está bien incluirlos aquí de nuevo como bullet points a modo de resumen. -->
|
253 |
+
|
254 |
+
### Model Architecture and Objective
|
255 |
+
|
256 |
+
The base model is [google/gemma-7b](https://huggingface.co/google/gemma-7b) finetuned in 4-bit.
|
257 |
+
|
258 |
+
### Compute Infrastructure
|
259 |
+
|
260 |
+
#### Hardware
|
261 |
+
|
262 |
+
<!-- Indicar el hardware utilizado, podéis agradecer aquí a quien lo patrocinó. -->
|
263 |
+
1 x RTX4090 GPU by Vast.ai.
|
264 |
+
|
265 |
+
#### Software
|
266 |
+
|
267 |
+
<!-- Enumerar las librerías utilizadas (e.g. transformers, distilabel). -->
|
268 |
+
|
269 |
+
Libraries:
|
270 |
+
- transformers
|
271 |
+
- bitsandbytes
|
272 |
+
- accelerate
|
273 |
+
- xformers
|
274 |
+
- trl
|
275 |
+
- peft
|
276 |
+
- wandb
|
277 |
+
|
278 |
+
## License
|
279 |
+
|
280 |
+
<!-- Indicar bajo qué licencia se libera el modelo explicando, si no es apache 2.0, a qué se debe la licencia más restrictiva (i.e. herencia de las licencias del modelo pre-entrenado o de los datos utilizados). -->
|
281 |
+
|
282 |
+
This model is under the license of the Gemma models by Google.
|
283 |
+
Link to consent: https://www.kaggle.com/models/google/gemma/license/consent
|
284 |
+
|
285 |
+
|
286 |
+
## Citation
|
287 |
+
|
288 |
+
**BibTeX:**
|
289 |
+
|
290 |
+
[More Information Needed]
|
291 |
+
|
292 |
+
<!--
|
293 |
+
|
294 |
+
Aquí tenéis un ejemplo de cita de un dataset que podéis adaptar:
|
295 |
+
|
296 |
+
```
|
297 |
+
@software{benallal2024cosmopedia,
|
298 |
+
author = {Ben Allal, Loubna and Lozhkov, Anton and Penedo, Guilherme and Wolf, Thomas and von Werra, Leandro},
|
299 |
+
title = {Cosmopedia},
|
300 |
+
month = February,
|
301 |
+
year = 2024,
|
302 |
+
url = {https://huggingface.co/datasets/HuggingFaceTB/cosmopedia}
|
303 |
+
}
|
304 |
+
```
|
305 |
+
|
306 |
+
- benallal2024cosmopedia -> nombre + año + nombre del modelo
|
307 |
+
- author: lista de miembros del equipo
|
308 |
+
- title: nombre del modelo
|
309 |
+
- year: año
|
310 |
+
- url: enlace al modelo
|
311 |
+
|
312 |
+
-->
|
313 |
+
```
|
314 |
+
@software{somosnlp2024asistenciarefugiados,
|
315 |
+
author = {Alvaro Hidalgo, Eduardo Muñoz, Teresa Martín},
|
316 |
+
title = {gemma-7b-it-legal-refugiados-es},
|
317 |
+
month = April,
|
318 |
+
year = 2024,
|
319 |
+
url = {somosnlp/gemma-7b-it-legal-refugee-v0.1.1}
|
320 |
+
}
|
321 |
+
```
|
322 |
+
## More Information
|
323 |
+
|
324 |
+
<!-- Indicar aquí que el marco en el que se desarrolló el proyecto, en esta sección podéis incluir agradecimientos y más información sobre los miembros del equipo. Podéis adaptar el ejemplo a vuestro gusto. -->
|
325 |
+
|
326 |
+
This project was developed during the [Hackathon #Somos600M](https://somosnlp.org/hackathon) organized by SomosNLP. The model was trained using GPUs sponsored by HuggingFace.
|
327 |
+
|
328 |
+
**Team:**
|
329 |
+
|
330 |
+
[Alvaro Hidalgo](https://huggingface.co/hacendado)
|
331 |
+
[Eduardo Muñoz](https://huggingface.co/edumunozsala)
|
332 |
+
[Teresa Martin](https://huggingface.co/narhim)
|
333 |
+
|
334 |
+
<!--
|
335 |
+
- [Name 1](Link to Hugging Face profile)
|
336 |
+
- [Name 2](Link to Hugging Face profile)
|
337 |
+
-->
|
338 |
+
|
339 |
+
## Contact [optional]
|
340 |
+
|
341 |
+
<!-- Email de contacto para´posibles preguntas sobre el modelo. -->
|