Andresmfs commited on
Commit
4aeaa75
1 Parent(s): e1415f3

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +146 -5
README.md CHANGED
@@ -10,23 +10,163 @@ model-index:
10
  <!-- This model card has been generated automatically according to the information the Trainer had access to. You
11
  should probably proofread and complete it, then remove this comment. -->
12
 
13
- # aguila-es-inclusivo-adapters_v3
14
 
15
- This model is a fine-tuned version of [projecte-aina/aguila-7b](https://huggingface.co/projecte-aina/aguila-7b) on an unknown dataset.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  It achieves the following results on the evaluation set:
17
- - Loss: 0.6292
18
 
19
  ## Model description
 
 
 
 
20
 
21
- More information needed
 
 
22
 
23
  ## Intended uses & limitations
24
 
25
  More information needed
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  ## Training and evaluation data
28
 
29
- More information needed
30
 
31
  ## Training procedure
32
 
@@ -63,3 +203,4 @@ The following hyperparameters were used during training:
63
  - Pytorch 2.2.2+cu121
64
  - Datasets 2.18.0
65
  - Tokenizers 0.13.3
 
 
10
  <!-- This model card has been generated automatically according to the information the Trainer had access to. You
11
  should probably proofread and complete it, then remove this comment. -->
12
 
 
13
 
14
+
15
+
16
+
17
+ # es-inclusivo-translator
18
+
19
+ This model is a fine-tuned version of [projecte-aina/aguila-7b](https://huggingface.co/projecte-aina/aguila-7b) on the dataset [somosnlp/es-inclusive-language](https://huggingface.co/datasets/somosnlp/es-inclusive-language).
20
+
21
+ Languages are powerful tools to communicate ideas, but their use is not impartial. The selection of words carries inherent biases and reflects subjective perspectives. In some cases, language is wielded to enforce ideologies, marginalize certain groups, or promote specific political agendas.
22
+ Spanish is not the exception to that. For instance, when we say “los alumnos” or “los ingenieros”, we are excluding women from those groups. Similarly, expressions such as “los gitanos” o “los musulmanes” perpetuate discrimination against these communities.
23
+
24
+ In response to these linguistic challenges, this model offers a way to construct inclusive alternatives in accordance with official guidelines on inclusive language from various Spanish speaking countries. Its purpose is to provide grammatically correct and inclusive solutions to situations where our language choices might otherwise be exclusive.
25
+ This is a tool that contributes to the fifth of the Sustainable Development Goals: Achieve gender equality and empower all women and girls.
26
+
27
+ The model works in such a way that, given an input text, it returns the original text rewritten using inclusive language.
28
+
29
  It achieves the following results on the evaluation set:
30
+ - Loss: 0.6030
31
 
32
  ## Model description
33
+ - **Developed by**: [Andrés Martínez Fernández-Salguero](https://huggingface.co/Andresmfs) (andresmfs), Imanuel Rozenberg (manu_20392), Gaia Quintana Fleitas (gaiaq), Josué Sauca (josue_sauca), Miguel López (wizmik12)
34
+ - **Language(s)**: Spanish
35
+ - **Fine-tuned from the model**: [projecte-aina/aguila-7b](https://huggingface.co/projecte-aina/aguila-7b)
36
+ - **Licence**: cc-by-nc-sa-4.0
37
 
38
+ ## Social Impact
39
+ An inclusive translator holds significant social impact by promoting equity and representation within texts. By rectifying biases ingrained in language and fostering inclusivity, it combats discrimination, amplifies the visibility of marginalized groups, and contributes to the cultivation of a more inclusive and respectful society.
40
+ This is a tool that contributes to the fifth of the Sustainable Development Goals: Achieve gender equality and empower all women and girls.
41
 
42
  ## Intended uses & limitations
43
 
44
  More information needed
45
 
46
+ ### How to use
47
+ Here is how to use this model:
48
+ ~~~
49
+ from transformers import AutoTokenizer
50
+ from transformers import AutoModelForCausalLM
51
+ import torch
52
+
53
+ # Load tokenizer and model
54
+ tokenizer = AutoTokenizer.from_pretrained('somosnlp/', trust_remote_code=True)
55
+ model = AutoModelForCausalLM.from_pretrained('somosnlp/', trust_remote_code=True,
56
+ quantization_config=bnb_config,
57
+ device_map="auto")
58
+
59
+ # generation_config
60
+ generation_config = model.generation_config
61
+ generation_config.max_new_tokens = 100
62
+ generation_config.temperature = 0.7
63
+ generation_config.top_p = 0.7
64
+ generation_config.num_return_sequences = 1
65
+ generation_config.pad_token_id = tokenizer.eos_token_id
66
+ generation_config.eos_token_id = tokenizer.eos_token_id
67
+
68
+ # Define inference function
69
+ def translate_es_inclusivo(exclusive_text):
70
+
71
+ # generate input prompt
72
+ eval_prompt = f"""Reescribe el siguiente texto utilizando lenguaje inclusivo.\n
73
+ Texto: {exclusive_text}\n
74
+ Texto en lenguaje inclusivo:"""
75
+
76
+ # tokenize input
77
+ model_input = tokenizer(eval_prompt, return_tensors="pt").to(model.device)
78
+
79
+ # set max_new_tokens if necessary
80
+ if len(model_input['input_ids'][0]) > 80:
81
+ model.generation_config.max_new_tokens = len(model_input['input_ids'][0]) + 0.2 * len(model_input['input_ids'][0])
82
+
83
+ # get length of encoded prompt
84
+ prompt_token_len = len(model_input['input_ids'][0])
85
+
86
+ # generate and decode
87
+ with torch.no_grad():
88
+ inclusive_text = tokenizer.decode(model.generate(**model_input, generation_config=generation_config)[0][prompt_token_len:],
89
+ skip_special_tokens=True)
90
+
91
+ return inclusive_text
92
+
93
+ ##########
94
+
95
+ input_text = 'Los alumnos atienden a sus profesores'
96
+
97
+ print(translate_es_inclusivo(input_text))
98
+ ~~~
99
+
100
+
101
+ As it is a heavy model, you may want to use it in 4-bits:
102
+ ~~~
103
+ from transformers import AutoTokenizer
104
+ from transformers import AutoModelForCausalLM
105
+ from transformers import BitsAndBytesConfig
106
+ import torch
107
+
108
+
109
+ ## Load model in 4bits
110
+ # bnb_configuration
111
+ bnb_config = BitsAndBytesConfig(
112
+ load_in_4bit=True,
113
+ bnb_4bit_quant_type='nf4',
114
+ bnb_4bit_compute_dtype=torch.bfloat16,
115
+ bnb_4bit_use_double_quant=False)
116
+
117
+
118
+ # model
119
+ model = AutoModelForCausalLM.from_pretrained('somosnlp/', trust_remote_code=True,
120
+ quantization_config=bnb_config,
121
+ device_map="auto")
122
+
123
+ # Load tokenizer
124
+ tokenizer = AutoTokenizer.from_pretrained('somosnlp/', trust_remote_code=True)
125
+
126
+ # generation_config
127
+ generation_config = model.generation_config
128
+ generation_config.max_new_tokens = 100
129
+ generation_config.temperature = 0.7
130
+ generation_config.top_p = 0.7
131
+ generation_config.num_return_sequences = 1
132
+ generation_config.pad_token_id = tokenizer.eos_token_id
133
+ generation_config.eos_token_id = tokenizer.eos_token_id
134
+
135
+ # Define inference function
136
+ def translate_es_inclusivo(exclusive_text):
137
+
138
+ # generate input prompt
139
+ eval_prompt = f"""Reescribe el siguiente texto utilizando lenguaje inclusivo.\n
140
+ Texto: {exclusive_text}\n
141
+ Texto en lenguaje inclusivo:"""
142
+
143
+ # tokenize input
144
+ model_input = tokenizer(eval_prompt, return_tensors="pt").to(model.device)
145
+
146
+ # set max_new_tokens if necessary
147
+ if len(model_input['input_ids'][0]) > 80:
148
+ model.generation_config.max_new_tokens = len(model_input['input_ids'][0]) + 0.2 * len(model_input['input_ids'][0])
149
+
150
+ # get length of encoded prompt
151
+ prompt_token_len = len(model_input['input_ids'][0])
152
+
153
+ # generate and decode
154
+ with torch.no_grad():
155
+ inclusive_text = tokenizer.decode(model.generate(**model_input, generation_config=generation_config)[0][prompt_token_len:],
156
+ skip_special_tokens=True)
157
+
158
+ return inclusive_text
159
+
160
+ ##########
161
+
162
+ input_text = 'Los alumnos atienden a sus profesores'
163
+
164
+ print(translate_es_inclusivo(input_text))
165
+ ~~~
166
+
167
  ## Training and evaluation data
168
 
169
+ Training and evaluation data can be found in [somosnlp/es-inclusive-language](https://huggingface.co/datasets/somosnlp/es-inclusive-language)
170
 
171
  ## Training procedure
172
 
 
203
  - Pytorch 2.2.2+cu121
204
  - Datasets 2.18.0
205
  - Tokenizers 0.13.3
206
+