daqc
/

Text Generation
Transformers
Safetensors
Spanish
gemma
Legal
Law
Peru
Leyes Juridicas
conversational
text-generation-inference
Inference Endpoints
daqc commited on
Commit
531c085
·
verified ·
1 Parent(s): 40d0a3d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +149 -146
README.md CHANGED
@@ -1,199 +1,202 @@
1
  ---
 
 
 
2
  library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
 
 
9
 
 
 
10
 
11
 
12
- ## Model Details
13
 
14
- ### Model Description
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- <!-- Provide a longer summary of what this model is. -->
17
 
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
 
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
 
28
- ### Model Sources [optional]
29
 
30
- <!-- Provide the basic links for the model. -->
 
 
 
 
31
 
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
 
36
- ## Uses
37
 
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
 
40
- ### Direct Use
41
 
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
 
44
- [More Information Needed]
 
45
 
46
- ### Downstream Use [optional]
 
 
 
47
 
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
 
 
 
 
 
49
 
50
- [More Information Needed]
51
 
52
- ### Out-of-Scope Use
 
53
 
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
 
56
- [More Information Needed]
 
 
 
57
 
58
- ## Bias, Risks, and Limitations
59
 
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- 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. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- 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).
146
 
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
 
153
- ## Technical Specifications [optional]
154
 
155
- ### Model Architecture and Objective
 
 
 
 
 
156
 
157
- [More Information Needed]
158
 
159
- ### Compute Infrastructure
160
 
161
- [More Information Needed]
 
 
 
 
 
 
 
 
162
 
163
- #### Hardware
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
- [More Information Needed]
166
 
167
- #### Software
168
 
169
- [More Information Needed]
170
 
171
- ## Citation [optional]
172
 
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
 
175
- **BibTeX:**
176
 
177
- [More Information Needed]
178
 
179
- **APA:**
180
 
181
- [More Information Needed]
182
 
183
- ## Glossary [optional]
184
 
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
 
187
- [More Information Needed]
 
 
 
188
 
189
- ## More Information [optional]
190
 
191
- [More Information Needed]
192
 
193
- ## Model Card Authors [optional]
194
 
195
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
 
197
- ## Model Card Contact
198
 
199
- [More Information Needed]
 
1
  ---
2
+ language:
3
+ - es
4
+ license: apache-2.0
5
  library_name: transformers
6
+ tags:
7
+ - Legal
8
+ - Law
9
+ - Peru
10
+ - Leyes Juridicas
11
+ datasets:
12
+ - somosnlp/constitucion-politica-del-peru-1993-qa-gemma-2b-it-format
13
+ - daqc/constitucion-politica-del-peru-1993-qa
14
+ widget:
15
+ - text: 'Una mujer es víctima de violencia de género y busca protección legal. ¿Qué
16
+ debo hacer y bajo qué base legal debería actuar?
17
+
18
+ '
19
+ - text: 'Un ciudadano es arrestado sin que se le informen sus derechos. ¿Qué capítulo
20
+ y artículo de la Constitución del Perú establece los derechos fundamentales de
21
+ las personas detenidas y las garantías procesales que deben respetarse durante
22
+ su arresto?
23
+
24
+ '
25
+ - text: 'Me gustaría solicitar asistencia legal gratuita en Perú. ¿Podrías proporcionarme
26
+ los pasos necesarios para llevar a cabo este proceso?
27
+
28
+ '
29
+ - text: ¿Qué artículo de la Constitución Política del Perú establece que toda persona
30
+ tiene derecho a la vida, a su identidad, a su integridad moral, psíquica y física,
31
+ y a su libre desarrollo y bienestar?
32
  ---
33
 
34
+ # Model Card for kuntur-peru-legal-es-gemma-2b-it-merged ⚖️
35
 
36
+ <p align="center">
37
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/64461026e1fd8d65b27e6187/bUbvGpmsKC7YsJs4aBt7T.jpeg" alt="Model Illustration" width="300">
38
+ </p>
39
 
40
+ ## Gemma-2B-IT-Peru-Legal-ES
41
+ The Gemma-2B-IT-Peru-Legal-ES model is a state-of-the-art language model fine-tuned specifically for legal text comprehension and generation tasks in Spanish, focusing on the legal context of the Peruvian Constitution. Leveraging advanced techniques such as Low-Rank Adaptation (LoRA) and Bits and Bytes Quantization (BNB), this model provides accurate and contextually relevant responses to legal queries, making it a valuable tool for legal professionals, researchers, and AI enthusiasts interested in the legal domain.
42
 
43
 
44
+ ## Table of Contents
45
 
46
+ - [kuntur-peru-legal-es-gemma-2b-it-merged ⚖️](#kuntur-peru-legal-es-gemma-2b-it-merged)
47
+ + [Model Description 📘](#model-description)
48
+ * [Finetuning Progress 🛠️](#finetuning-progress)
49
+ + [Recommendations 📝](#recommendations-)
50
+ * [How to Get Started with the Model 🚀](#how-to-get-started-with-the-model)
51
+ * [Training Dataset 🧠](#training-dataset)
52
+ * [Finetuning Progress 🤖](#finetuning-progress)
53
+ *
54
+ + [Environment and Libraries 🖥️](#environment-and-libraries)
55
+ + [QLoRA Configuration 🧮](#qlora-configuration)
56
+ + [Model Merging and Saving 💾](#model-merging-and-saving)
57
+ * [Logging with Wandb 📊](#logging-with-wandb)
58
+ * [Impacto Ambiental 🌳](#impacto-ambiental)
59
 
 
60
 
 
61
 
62
+ ## Model Description
 
 
 
 
 
 
63
 
64
+ kuntur-peru-legal-es-gemma-2b-it-merged is a contextual legal language model designed to provide personalized legal advice in Spanish based on Peruvian legal texts. Leveraging advanced techniques like LoRA, the model offers accurate and contextually relevant responses to legal queries, covering various aspects of Peruvian law and regulation. Whether it's understanding rights, navigating legal procedures, or interpreting statutes, kuntur-peru-legal-es-gemma-2b-it-merged empowers users with comprehensive and reliable legal guidance tailored to the Peruvian legal landscape.
65
 
66
+ - **Developed by:** [Alonso Quispe](https://huggingface.co/daqc)
67
+ - **Model type:** Causal Language Model, specially fine-tuned with LoRA for the distinct domain of Peruvian law and regulation.
68
+ - **Language(s) (NLP):** Spanish, tailored for the legal and regulatory context of Peru.
69
+ - **License:** Apache License. This open-source license ensures that the model can be freely used, modified, and distributed. Please check the model's page on Hugging Face for specific licensing details.
70
+ - **Base model:** google/gemma-2b-it`
71
 
 
 
 
72
 
 
73
 
74
+ ## Recommendations
75
 
76
+ Users should verify model outputs against current regulations and consult with professionals for critical applications. Awareness of the model's scope and limitations is crucial for effective use.
77
 
78
+ # How to Get Started with the Model
79
 
80
+ ```python
81
+ from transformers import AutoModelForCausalLM, AutoTokenizer
82
 
83
+ # Cargar el modelo y el tokenizador
84
+ model_name = "somosnlp/kuntur-peru-legal-es-gemma-2b-it-merged"
85
+ model = AutoModelForCausalLM.from_pretrained(model_name)
86
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
87
 
88
+ # Ejemplo de uso
89
+ input_text = "Una persona ha sido despedida de su trabajo injustamente y necesita entender cuáles son sus derechos laborales según la Constitución Política del Perú."
90
+ input_ids = tokenizer.encode(input_text, return_tensors="pt")
91
+ output = model.generate(input_ids, max_length=100, num_return_sequences=1, temperature=0.7)
92
+ print(tokenizer.decode(output[0], skip_special_tokens=True))
93
+ ```
94
 
95
+ ## Training Dataset
96
 
97
+ The kuntur-peru-legal-es-gemma-2b-it-merged model was fine-tuned exclusively on the "[Constitución Política del Perú](https://huggingface.co/datasets/daqc/constitucion-politica-del-peru-1993-qa) dataset available through Hugging Face Datasets. This dataset serves as a rich source of questions and answers pertaining to the legal framework outlined in the Peruvian Constitution.
98
+ The dataset encompasses a wide range of topics and provisions within the Peruvian Constitution, providing comprehensive coverage of constitutional principles, rights, and legal interpretations.
99
 
 
100
 
101
+ ## Finetuning Progress
102
+ <p align="center">
103
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/64461026e1fd8d65b27e6187/N8VAkUIuWK0vgYZRlmwew.png" alt="Loss Function Graph" width="900">
104
+ </p>
105
 
 
106
 
107
+ ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
 
 
 
 
 
 
109
 
110
+ ## Environment and Libraries
111
 
112
+ The training process was executed within a Python environment, utilizing essential libraries to facilitate various tasks:
113
+ - **transformers:** Used for loading and fine-tuning the model, providing a seamless interface for working with pre-trained language models.
114
+ - **datasets:** Employed for efficient handling and preprocessing of the training dataset, ensuring streamlined data pipelines.
115
+ - **torch:** Utilized as the primary deep learning framework to support model training and optimization.
116
+ - **peft:** Integrated for applying Low-Rank Adaptation (LoRA) techniques to the model, enabling efficient adaptation to specialized domains without compromising performance.
117
+ - **qlora:** Additionally utilized for further model adaptation, enhancing its ability to comprehend and generate responses specific to the legal context of the "Constitucióm Política del Perú" dataset.
118
 
119
+ ## QLoRA Configuration
120
 
121
+ QLoRA (Quantization LoRA) was employed to optimize the model's computational efficiency and memory footprint while preserving its accuracy. Two configurations were utilized:
122
 
123
+ - **BitsAndBytesConfig:** This configuration enabled the model to load in 4-bit quantization, leveraging the nf4 quantization type with a torch.bfloat16 compute data type for enhanced efficiency during inference.
124
+ ```python
125
+ bnb_config = BitsAndBytesConfig(
126
+ load_in_4bit=True,
127
+ bnb_4bit_quant_type="nf4",
128
+ bnb_4bit_compute_dtype=torch.bfloat16,
129
+ bnb_4bit_use_double_quant=False,
130
+ )
131
+ ```
132
 
133
+ - **LoRAConfig:** This configuration applied Low-Rank Adaptation (LoRA) to the model, optimizing its parameters for the specific task of language modeling in the legal domain. Key parameters include:
134
+ - **r:** Reduced to 8 from the default 32, controlling the rank of adaptation layers.
135
+ - **lora_alpha:** Adjusted to 16 from the default 64, regulating the sparsity of adapted weights.
136
+ - **target_modules:** Specified modules for adaptation, focusing on query, key, value, and output projection layers.
137
+ - **bias:** Set to "none" to exclude bias terms from adaptation, simplifying the model architecture.
138
+ - **lora_dropout:** Reduced to 0.025 from the default 0.05, controlling the dropout rate during adaptation.
139
+ - **task_type:** Configured as "CAUSAL_LM" to indicate the task type of the language model.
140
+ -
141
+ ```python
142
+ config = LoraConfig(
143
+ r=8,
144
+ lora_alpha=16,
145
+ target_modules=['q_proj', 'k_proj', 'v_proj', 'o_proj'],
146
+ bias="none",
147
+ lora_dropout=0.025,
148
+ task_type="CAUSAL_LM",
149
+ )
150
+ ```
151
 
152
+ These configurations were crucial for optimizing the model's performance and resource utilization during training and inference, ensuring efficient deployment.
153
 
 
154
 
155
+ ## Model Merging and Saving 💾
156
 
157
+ After fine-tuning, the LoRA-adjusted weights were merged back with the base Gemma model to create the final kuntur-peru-legal-es-gemma-2b-it-merged. The model was then saved and made available through Hugging Face for easy access and further development.
158
 
 
159
 
160
+ ## Logging with Wandb 📊
161
 
162
+ During the training process, Wandb (Weights & Biases) was used for comprehensive logging and visualization of key metrics. Wandb's powerful tracking capabilities enabled real-time monitoring of training progress, evaluation metrics, and model performance. Through interactive dashboards and visualizations, Wandb facilitated deep insights into the training dynamics, allowing for efficient model optimization and debugging. This logging integration with Wandb enhances transparency, reproducibility, and collaboration among researchers and practitioners.
163
 
 
164
 
 
165
 
166
+ ## Impacto Ambiental 🌳
167
 
168
+ The training of `kuntur-peru-legal-es-gemma-2b-it-merged` was conducted optimizing the computational expenditure required.
169
 
170
+ - **Hardware Type:** A10G-24GB
171
+ - **Hours Utilized:** Approximately 3.5 hours
172
+ - **Energy Consumption:** Approximately --- kWh
173
+ - **Estimated CO2 Emissions:** Approximately --- kg
174
 
 
175
 
176
+ ## To-Do List
177
 
178
+ ## Dataset Generation, Human Feedback Review with Argilla, and Finetuning with the Following Legal Texts:
179
 
180
+ | **Dataset Generation** | **Human Feedback Review with Argilla** | **Model Finetuning** |
181
+ |-----------|-----------|-----------|
182
+ | ☑️ Constitution of Peru | ☑️ Constitution of Peru | ☑️ Constitution of Peru |
183
+ | 🔲 Penal Code | 🔲 Penal Code | 🔲 Penal Code |
184
+ | 🔲 Congress Regulation | 🔲 Congress Regulation | 🔲 Congress Regulation |
185
+ | 🔲 New Constitutional Procedural Code | 🔲 New Constitutional Procedural Code | 🔲 New Constitutional Procedural Code |
186
+ | 🔲 Civil Code | 🔲 Civil Code | 🔲 Civil Code |
187
+ | 🔲 (TUO) Civil Procedural Code | 🔲 (TUO) Civil Procedural Code | 🔲 (TUO) Civil Procedural Code |
188
+ | 🔲 Penal Procedural Code (D.L 638) | 🔲 Penal Procedural Code (D.L 638) | 🔲 Penal Procedural Code (D.L 638) |
189
+ | 🔲 New Penal Procedural Code (D.L 957) | 🔲 New Penal Procedural Code (D.L 957) | 🔲 New Penal Procedural Code (D.L 957) |
190
+ | 🔲 Penal Execution Code | 🔲 Penal Execution Code | 🔲 Penal Execution Code |
191
+ | 🔲 Military Police Penal Code | 🔲 Military Police Penal Code | 🔲 Military Police Penal Code |
192
+ | 🔲 Military Police Justice Code | 🔲 Military Police Justice Code | 🔲 Military Police Justice Code |
193
+ | 🔲 Children and Adolescents Code | 🔲 Children and Adolescents Code | 🔲 Children and Adolescents Code |
194
+ | 🔲 Adolescent Penal Responsibility Code | 🔲 Adolescent Penal Responsibility Code | 🔲 Adolescent Penal Responsibility Code |
195
+ | 🔲 Commercial Code | 🔲 Commercial Code | 🔲 Commercial Code |
196
+ | 🔲 Consumer Protection and Defense Code | 🔲 Consumer Protection and Defense Code | 🔲 Consumer Protection and Defense Code |
197
+ | 🔲 Tax Code (TUO) | 🔲 Tax Code (TUO) | 🔲 Tax Code (TUO) |
198
+ | 🔲 Criminal Procedure Code | 🔲 Criminal Procedure Code | 🔲 Criminal Procedure Code |
199
 
200
+ ## License
201
 
202
+ This project is distributed under the Apache 2.0 license.