silviapasuarez commited on
Commit
0eb2a92
·
verified ·
1 Parent(s): 8bebb60

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +242 -40
README.md CHANGED
@@ -1,63 +1,265 @@
1
  ---
 
 
 
2
  base_model: carvalho-nos/CarvalhoChat_v4
3
  library_name: peft
4
- model_name: rq1_carvalhochat_gl_gec_lora
5
  tags:
6
- - base_model:adapter:carvalho-nos/CarvalhoChat_v4
 
 
 
 
 
7
  - lora
8
- - sft
9
- - transformers
10
- - trl
11
- - unsloth
12
- licence: license
13
- pipeline_tag: text-generation
14
  ---
15
 
16
- # Model Card for rq1_carvalhochat_gl_gec_lora
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
- This model is a fine-tuned version of [carvalho-nos/CarvalhoChat_v4](https://huggingface.co/carvalho-nos/CarvalhoChat_v4).
19
- It has been trained using [TRL](https://github.com/huggingface/trl).
20
 
21
- ## Quick start
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  ```python
24
- from transformers import pipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
- question = "If you had a time machine, but could only go to the past or the future once and never return, which would you choose and why?"
27
- generator = pipeline("text-generation", model="None", device="cuda")
28
- output = generator([{"role": "user", "content": question}], max_new_tokens=128, return_full_text=False)[0]
29
- print(output["generated_text"])
30
  ```
31
 
32
- ## Training procedure
33
 
34
-
35
 
 
36
 
37
- This model was trained with SFT.
38
 
39
- ### Framework versions
 
 
 
 
40
 
41
- - PEFT 0.18.1
42
- - TRL: 0.24.0
43
- - Transformers: 5.5.0
44
- - Pytorch: 2.10.0
45
- - Datasets: 4.3.0
46
- - Tokenizers: 0.22.2
47
 
48
- ## Citations
49
 
 
 
 
 
 
50
 
 
51
 
52
- Cite TRL as:
53
-
54
- ```bibtex
55
- @misc{vonwerra2022trl,
56
- title = {{TRL: Transformer Reinforcement Learning}},
57
- author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallou{\'e}dec},
58
- year = 2020,
59
- journal = {GitHub repository},
60
- publisher = {GitHub},
61
- howpublished = {\url{https://github.com/huggingface/trl}}
62
- }
63
- ```
 
1
  ---
2
+ language:
3
+ - gl
4
+ license: cc-by-4.0
5
  base_model: carvalho-nos/CarvalhoChat_v4
6
  library_name: peft
7
+ pipeline_tag: text-generation
8
  tags:
9
+ - galician
10
+ - grammatical-error-correction
11
+ - gec
12
+ - grammar-correction
13
+ - orthographic-correction
14
+ - text-correction
15
  - lora
16
+ - peft
17
+ - carvalho
18
+ - carvalhochat
19
+ - llama
20
+ - low-resource-nlp
21
+ - proxecto-nos
22
  ---
23
 
24
+ # CarvalhoChat_GEC
25
+
26
+ ## Model Summary
27
+
28
+ **CarvalhoChat_GEC** is a LoRA adapter for **Galician grammatical error correction (GEC)**. It is designed to correct Galician sentences while preserving their original meaning and making minimal necessary changes.
29
+
30
+ The adapter was fine-tuned from **`carvalho-nos/CarvalhoChat_v4`** using high-quality Galician GEC data only. The training setup was designed to evaluate the effect of the initial model checkpoint on Galician GEC performance while keeping the data, hyperparameters, prompt format, inference procedure, and evaluation setup fixed.
31
+
32
+ This repository contains a **PEFT/LoRA adapter**, not a full merged model. To use it, load the base model first and then apply the adapter.
33
+
34
+ The adapter was trained with supervised fine-tuning using **Unsloth** for efficient LoRA training. Training was performed on an **NVIDIA A100 80GB GPU** and took approximately **5 hours**.
35
+
36
+ ## Intended Task
37
+
38
+ The model is intended for **Galician grammatical error correction**.
39
+
40
+ Given an input sentence in Galician, the model should return only the corrected sentence.
41
+
42
+ ### Example
43
+
44
+ Input:
45
+
46
+ ```text
47
+ <|task:gec|>
48
+ <|lang:gl|>
49
+ Frase: A nena chegou tarde porque tiña moitos cousas que facer.
50
+ ```
51
+
52
+ Expected output:
53
+
54
+ ```text
55
+ A nena chegou tarde porque tiña moitas cousas que facer.
56
+ ```
57
+
58
+ ## Base Model
59
+
60
+ - **Base model:** `carvalho-nos/CarvalhoChat_v4`
61
+ - **Adapter type:** LoRA / PEFT
62
+ - **Task:** Galician grammatical error correction
63
+ - **Language:** Galician
64
+
65
+ ## Training Data
66
+
67
+ The adapter was trained exclusively on high-quality Galician GEC data. The training data were drawn from the private dataset repository:
68
+
69
+ - `proxectonos/galician-gec-corpora`
70
+
71
+ The training mixture includes:
72
+
73
+ - **CORTEGAL-derived Galician correction data**
74
+ - **Initial corrected synthetic Galician GEC data**
75
+ - **A 1,500-example ParlaMint punctuation/correction subset**
76
+
77
+
78
+ ## Prompt Format
79
+
80
+ The model was trained with a chat-style prompt using the tokenizer chat template of the base model.
81
+
82
+ The system prompt used during training was:
83
+
84
+ ```text
85
+ Es un corrector gramatical. Corrixe a frase na lingua de destino solicitada. Fai cambios mínimos. Conserva o significado. Devolve só a frase corrixida.
86
+ ```
87
+
88
+ The user message follows this format:
89
+
90
+ ```text
91
+ <|task:gec|>
92
+ <|lang:gl|>
93
+ Frase: {sentence}
94
+ ```
95
 
96
+ The assistant target is the corrected Galician sentence only.
 
97
 
98
+ ## Special Tokens
99
+
100
+ The adapter uses the following special tokens:
101
+
102
+ ```text
103
+ <|task:gec|>
104
+ <|lang:gl|>
105
+ ```
106
+
107
+ These tokens were added to the tokenizer during training and their embeddings were made trainable together with the LoRA parameters.
108
+
109
+ For inference, these tokens should be included in the user prompt exactly as shown above.
110
+
111
+ ## LoRA Configuration
112
+
113
+ The LoRA adapter was trained over the main attention and MLP projection modules typically used in Llama-style architectures:
114
+
115
+ ```text
116
+ q_proj
117
+ k_proj
118
+ v_proj
119
+ o_proj
120
+ gate_proj
121
+ up_proj
122
+ down_proj
123
+ ```
124
+
125
+ Training configuration used in the experimental setup:
126
+
127
+ ```text
128
+ LoRA rank: 16
129
+ LoRA alpha: 32
130
+ LoRA dropout: 0.0
131
+ Max sequence length: 1024
132
+ Learning rate: 2e-4
133
+ Warmup ratio: 0.05
134
+ Weight decay: 0.01
135
+ Scheduler: cosine
136
+ Optimizer: adamw_8bit
137
+ ```
138
+
139
+ The model was trained using 4-bit loading for memory efficiency.
140
+
141
+ ## How to Use
142
+
143
+ Install the required libraries:
144
+
145
+ ```bash
146
+ pip install -U transformers peft accelerate bitsandbytes torch
147
+ ```
148
+
149
+ Then load the base model and adapter:
150
 
151
  ```python
152
+ import torch
153
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
154
+ from peft import PeftModel
155
+
156
+ BASE_MODEL = "carvalho-nos/CarvalhoChat_v4"
157
+ ADAPTER = "proxectonos/CarvalhoChat_GEC"
158
+
159
+ SPECIAL_TOKENS = [
160
+ "<|task:gec|>",
161
+ "<|lang:gl|>",
162
+ ]
163
+
164
+ SYSTEM_PROMPT = (
165
+ "Es un corrector gramatical. "
166
+ "Corrixe a frase na lingua de destino solicitada. "
167
+ "Fai cambios mínimos. "
168
+ "Conserva o significado. "
169
+ "Devolve só a frase corrixida."
170
+ )
171
+
172
+ def build_messages(sentence: str):
173
+ return [
174
+ {
175
+ "role": "system",
176
+ "content": SYSTEM_PROMPT,
177
+ },
178
+ {
179
+ "role": "user",
180
+ "content": (
181
+ "<|task:gec|>\n"
182
+ "<|lang:gl|>\n"
183
+ f"Frase: {sentence.strip()}"
184
+ ),
185
+ },
186
+ ]
187
+
188
+ def clean_output(text: str) -> str:
189
+ for token in SPECIAL_TOKENS:
190
+ text = text.replace(token, "")
191
+ return text.strip().splitlines()[0].strip()
192
+
193
+ quant_config = BitsAndBytesConfig(
194
+ load_in_4bit=True,
195
+ bnb_4bit_compute_dtype=torch.float16,
196
+ bnb_4bit_quant_type="nf4",
197
+ bnb_4bit_use_double_quant=True,
198
+ )
199
+
200
+ tokenizer = AutoTokenizer.from_pretrained(ADAPTER)
201
+
202
+ base_model = AutoModelForCausalLM.from_pretrained(
203
+ BASE_MODEL,
204
+ quantization_config=quant_config,
205
+ device_map="auto",
206
+ torch_dtype=torch.float16,
207
+ )
208
+
209
+ model = PeftModel.from_pretrained(base_model, ADAPTER)
210
+ model.eval()
211
+
212
+ sentence = "A nena chegou tarde porque tiña moitos cousas que facer."
213
+ messages = build_messages(sentence)
214
+
215
+ prompt = tokenizer.apply_chat_template(
216
+ messages,
217
+ tokenize=False,
218
+ add_generation_prompt=True,
219
+ )
220
+
221
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
222
+
223
+ with torch.no_grad():
224
+ output_ids = model.generate(
225
+ **inputs,
226
+ max_new_tokens=64,
227
+ do_sample=False,
228
+ repetition_penalty=1.05,
229
+ pad_token_id=tokenizer.eos_token_id,
230
+ eos_token_id=tokenizer.eos_token_id,
231
+ )
232
+
233
+ generated = output_ids[0][inputs["input_ids"].shape[1]:]
234
+ prediction = tokenizer.decode(generated, skip_special_tokens=True)
235
 
236
+ print(clean_output(prediction))
 
 
 
237
  ```
238
 
239
+ ## Expected Output Format
240
 
241
+ The model is expected to return only the corrected Galician sentence.
242
 
243
+ It should not provide explanations, comments, lists of changes, or alternative corrections.
244
 
245
+ ## Limitations
246
 
247
+ - The model is specialized for Galician grammatical error correction.
248
+ - It was trained only on high-quality Galician GEC data, so its coverage depends on the error types represented in those datasets.
249
+ - The model may overcorrect valid Galician variants or make unnecessary edits in ambiguous cases.
250
+ - The model should not be used as the only authority for normative linguistic decisions.
251
+ - Human review is recommended for formal, legal, educational, or publication-critical uses.
252
 
253
+ ## Intended Uses
 
 
 
 
 
254
 
255
+ This adapter can be used for:
256
 
257
+ - Galician grammatical error correction
258
+ - orthographic and punctuation correction
259
+ - evaluation of Galician GEC systems
260
+ - research on low-resource grammatical correction
261
+ - comparison of base-model adaptation strategies for Galician
262
 
263
+ ## Acknowledgements
264
 
265
+ This work is 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 Desarrollo de Modelos ALIA. Esta publicación del proyecto Desarrollo de Modelos ALIA está financiada por el Ministerio para la Transformación Digital y de la Función Pública y por el Plan de Recuperación, Transformación y Resiliencia – Financiado por la Unión Europea – NextGenerationEU.