daqc commited on
Commit
4876460
·
verified ·
1 Parent(s): 10d7027

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +146 -142
README.md CHANGED
@@ -1,199 +1,203 @@
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
  library_name: transformers
3
+ tags:
4
+ - Legal
5
+ - Law
6
+ - Peru
7
+ - Leyes Juridicas
8
+ license: apache-2.0
9
+ datasets:
10
+ - daqc/constitucion-politica-del-peru-1993-qa
11
+ language:
12
+ - es
13
+ widget:
14
+ - text: >
15
+ <bos><|system|>
16
+ You are an AI assistant specialized in answering questions about the 1993 Constitution of Peru.
17
+ In cases of rights vulnerability, you provide guidance by identifying protective laws and offer
18
+ step-by-step assistance on critical issues such as health, education, social conflicts, prevention
19
+ of corruption , public services, violence against children, inequality and violence against women.
20
+ Citizen Security and Disability. Highly important!! You can only generate text in SPANISH.<eos>
21
+ <|user|>
22
+ Una mujer es víctima de violencia de género y busca protección legal. ¿Que debo hacer y bajo que base legal deberia actual?<eos>
23
+ <|assistant|>
24
+ pipeline_tag: text2text-generation
25
  ---
26
 
27
+ # Model Card for gemma-2b-it-peru-legal-es-V2 ⚖️
28
 
29
+ <p align="center">
30
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/64461026e1fd8d65b27e6187/bUbvGpmsKC7YsJs4aBt7T.jpeg" alt="Model Illustration" width="500">
31
+ </p>
32
 
33
+ ## Gemma-2B-IT-Peru-Legal-ES
34
+ 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.
35
 
36
 
37
+ ## Table of Contents
38
 
39
+ - [Model Card for Gemma-2B-IT-Peru-Legal-ES 🇵🇪](#model-card-for-gemma-2b-it-peru-legal-es-)
40
+ * [Gemma-2B-IT-Peru-Legal-ES ⚖️](#gemma-2b-it-peru-legal-es)
41
+ + [Model Description 📘](#model-description)
42
+ * [Usage 🛠️](#usage-)
43
+ + [Direct Use 🎯](#direct-use-)
44
+ + [Downstream Use 🔄](#downstream-use-)
45
+ + [Out-of-Scope Use 🚫](#out-of-scope-use-)
46
+ * [Bias, Risks, and Limitations ⚠️](#bias-risks-and-limitations-)
47
+ + [Recommendations 📝](#recommendations-)
48
+ * [How to Get Started with the Model 🚀](#how-to-get-started-with-the-model-)
49
+ * [Training Dataset 🧠](#training-dataset-)
50
+ + [Environment and Libraries 🖥️](#environment-and-libraries-)
51
+ + [QLoRA Configuration 🧮](#qlora-configuration-)
52
+ + [Model Merging and Saving 💾](#model-merging-and-saving-)
53
+ * [Logging with Wandb 📊](#logging-with-wandb-)
54
 
 
55
 
 
56
 
57
+ ## Model Details 📈
 
 
 
 
 
 
58
 
59
+ ### Model Description 📘
60
 
61
+ Gemma-2b-it-peru-legal-es-V2 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, gemma-2b-it-peru-legal-es-V2 empowers users with comprehensive and reliable legal guidance tailored to the Peruvian legal landscape.
62
 
63
+ - **Developed by:** []()
64
+ - **Model type:** Causal Language Model, specially fine-tuned with LoRA for the distinct domain of Peruvian law and regulation.
65
+ - **Language(s) (NLP):** Spanish, tailored for the legal and regulatory context of Peru.
66
+ - **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.
67
+ - **Base model [optional]:** Derived from Google's Gemma 2b it model, utilizing versions such as `gemma-2b-it` for comprehensive training.
68
 
69
+ ### Fintunineting progresss 📉
70
+ <p align="center">
71
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/64461026e1fd8d65b27e6187/N8VAkUIuWK0vgYZRlmwew.png" alt="Loss Function Graph" width="900">
72
+ </p>
73
 
 
74
 
75
+ ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
 
77
+ ## Usage 🛠️
78
 
79
+ The PeruLegalLLM model is designed to enhance understanding and application of Colombian Aeronautical Regulations (RAC) through natural language processing. It's tailored for professionals and enthusiasts in the aviation industry, regulatory agencies, legal experts, and AI researchers with an interest in domain-specific language model applications.
80
 
81
+ ### Direct Use 🎯
82
 
83
+ The model can be directly employed to generate text, answer questions, and provide insights related to Colombian Aeronautical Regulations without further fine-tuning. It's ideal for creating educational content, simplifying legal language, and assisting in regulatory compliance efforts.
84
 
85
+ ### Downstream Use [optional] 🔄
86
 
87
+ When finely-tuned, gemma-2b-it-peru-legal-es-V2 can be integrated into larger systems for automated compliance checks, document summarization, and even training simulators for pilots and air traffic controllers, offering a deeper, contextual understanding of regulations.
88
 
89
+ ### Out-of-Scope Use 🚫
90
 
91
+ Misuse includes any application that promotes unethical practices, misinterprets aviation law, or uses the model for malicious purposes. The model is not designed for navigational purposes or to replace professional legal advice.
92
 
93
+ ## Bias, Risks, and Limitations ⚠️
94
 
95
+ The model, while powerful, has limitations inherent to AI, including biases present in the training data. It may not cover all nuances of aviation regulations outside of Colombia or adapt to changes in law without updates.
96
 
97
+ ### Recommendations 📝
98
 
99
+ 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.
100
 
101
+ ## How to Get Started with the Model 🚀
102
 
103
+ ```python
104
+ from transformers import AutoModelForCausalLM, AutoTokenizer
105
 
106
+ # Cargar el modelo y el tokenizador
107
+ model_name = "somosnlp/gemma-2b-it-peru-legal-es-V2"
108
+ model = AutoModelForCausalLM.from_pretrained(model_name)
109
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
 
110
 
111
+ # Ejemplo de uso
112
+ 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ú."
113
+ input_ids = tokenizer.encode(input_text, return_tensors="pt")
114
+ output = model.generate(input_ids, max_length=100, num_return_sequences=1, temperature=0.7)
115
+ print(tokenizer.decode(output[0], skip_special_tokens=True))
116
+ ```
117
 
118
+ ## Training Dataset 🧠
119
 
120
+ The Gemma-2B-IT-Peru-Legal-ES-V2 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.
121
+ The dataset encompasses a wide range of topics and provisions within the Peruvian Constitution, providing comprehensive coverage of constitutional principles, rights, and legal interpretations.
122
 
 
123
 
124
+ ### Environment and Libraries 🖥️
125
 
126
+ The training process was executed within a Python environment, utilizing essential libraries to facilitate various tasks:
127
+ - **transformers:** Used for loading and fine-tuning the model, providing a seamless interface for working with pre-trained language models.
128
+ - **datasets:** Employed for efficient handling and preprocessing of the training dataset, ensuring streamlined data pipelines.
129
+ - **torch:** Utilized as the primary deep learning framework to support model training and optimization.
130
+ - **peft:** Integrated for applying Low-Rank Adaptation (LoRA) techniques to the model, enabling efficient adaptation to specialized domains without compromising performance.
131
+ - **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.
132
 
133
+ ### QLoRA Configuration 🧮
134
 
135
+ QLoRA (Quantization LoRA) was employed to optimize the model's computational efficiency and memory footprint while preserving its accuracy. Two configurations were utilized:
136
 
137
+ - **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.
138
+ ```python
139
+ bnb_config = BitsAndBytesConfig(
140
+ load_in_4bit=True,
141
+ bnb_4bit_quant_type="nf4",
142
+ bnb_4bit_compute_dtype=torch.bfloat16,
143
+ bnb_4bit_use_double_quant=False,
144
+ )
145
+ ```
146
 
147
+ - **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:
148
+ - **r:** Reduced to 8 from the default 32, controlling the rank of adaptation layers.
149
+ - **lora_alpha:** Adjusted to 16 from the default 64, regulating the sparsity of adapted weights.
150
+ - **target_modules:** Specified modules for adaptation, focusing on query, key, value, and output projection layers.
151
+ - **bias:** Set to "none" to exclude bias terms from adaptation, simplifying the model architecture.
152
+ - **lora_dropout:** Reduced to 0.025 from the default 0.05, controlling the dropout rate during adaptation.
153
+ - **task_type:** Configured as "CAUSAL_LM" to indicate the task type of the language model.
154
+ ```python
155
+ config = LoraConfig(
156
+ r=8,
157
+ lora_alpha=16,
158
+ target_modules=['q_proj', 'k_proj', 'v_proj', 'o_proj'],
159
+ bias="none",
160
+ lora_dropout=0.025,
161
+ task_type="CAUSAL_LM",
162
+ )
163
+ ```
164
 
165
+ These configurations were crucial for optimizing the model's performance and resource utilization during training and inference, ensuring efficient deployment.
166
 
 
167
 
168
+ ### Model Merging and Saving 💾
169
 
170
+ After fine-tuning, the LoRA-adjusted weights were merged back with the base Gemma model to create the final gemma-2b-it-peru-legal-es-V2. The model was then saved and made available through Hugging Face for easy access and further development.
171
 
 
172
 
173
+ ## Logging with Wandb 📊
174
 
175
+ 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.
176
 
 
177
 
178
+ ## To-Do List
179
 
180
+ ### Dataset Generation, Human Feedback Review with Argilla, and Finetuning with the Following Legal Texts:
181
 
182
+ - [x] Constitution of Peru
183
+ - [ ] Penal Code
184
+ - [ ] Congress Regulation
185
+ - [ ] New Constitutional Procedural Code
186
+ - [ ] Civil Code
187
+ - [ ] (TUO) Civil Procedural Code
188
+ - [ ] Penal Procedural Code (D.L 638)
189
+ - [ ] New Penal Procedural Code (D.L 957)
190
+ - [ ] Penal Execution Code
191
+ - [ ] Military Police Penal Code
192
+ - [ ] Military Police Justice Code
193
+ - [ ] Children and Adolescents Code
194
+ - [ ] Adolescent Penal Responsibility Code
195
+ - [ ] Commercial Code
196
+ - [ ] Consumer Protection and Defense Code
197
+ - [ ] Tax Code (TUO)
198
+ - [ ] Criminal Procedure Code
199
 
200
+ ### License
201
 
202
+ This project is distributed under the Apache 2.0 license.
203