Update README.md
Browse files
README.md
CHANGED
@@ -25,7 +25,7 @@ widget:
|
|
25 |
# Model Card for gemma-2b-it-peru-legal-es-V2 ⚖️
|
26 |
|
27 |
<p align="center">
|
28 |
-
<img src="https://cdn-uploads.huggingface.co/production/uploads/64461026e1fd8d65b27e6187/bUbvGpmsKC7YsJs4aBt7T.jpeg" alt="Model Illustration" width="
|
29 |
</p>
|
30 |
|
31 |
## Gemma-2B-IT-Peru-Legal-ES
|
@@ -34,69 +34,39 @@ The Gemma-2B-IT-Peru-Legal-ES model is a state-of-the-art language model fine-tu
|
|
34 |
|
35 |
## Table of Contents
|
36 |
|
37 |
-
- [
|
38 |
-
* [Gemma-2B-IT-Peru-Legal-ES ⚖️](#gemma-2b-it-peru-legal-es)
|
39 |
+ [Model Description 📘](#model-description)
|
40 |
-
* [
|
41 |
-
+ [Direct Use 🎯](#direct-use-)
|
42 |
-
+ [Downstream Use 🔄](#downstream-use-)
|
43 |
-
+ [Out-of-Scope Use 🚫](#out-of-scope-use-)
|
44 |
-
* [Bias, Risks, and Limitations ⚠️](#bias-risks-and-limitations-)
|
45 |
+ [Recommendations 📝](#recommendations-)
|
46 |
-
* [How to Get Started with the Model 🚀](#how-to-get-started-with-the-model
|
47 |
-
* [Training Dataset 🧠](#training-dataset
|
48 |
-
|
49 |
-
|
50 |
-
+ [
|
51 |
-
|
|
|
|
|
|
|
52 |
|
53 |
|
54 |
|
55 |
-
## Model
|
56 |
-
|
57 |
-
### Model Description 📘
|
58 |
|
59 |
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.
|
60 |
|
61 |
-
- **Developed by:** []()
|
62 |
- **Model type:** Causal Language Model, specially fine-tuned with LoRA for the distinct domain of Peruvian law and regulation.
|
63 |
- **Language(s) (NLP):** Spanish, tailored for the legal and regulatory context of Peru.
|
64 |
- **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.
|
65 |
-
- **Base model
|
66 |
-
|
67 |
-
### Fintunineting progresss 📉
|
68 |
-
<p align="center">
|
69 |
-
<img src="https://cdn-uploads.huggingface.co/production/uploads/64461026e1fd8d65b27e6187/N8VAkUIuWK0vgYZRlmwew.png" alt="Loss Function Graph" width="900">
|
70 |
-
</p>
|
71 |
-
|
72 |
-
|
73 |
-
---
|
74 |
-
|
75 |
-
## Usage 🛠️
|
76 |
-
|
77 |
-
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.
|
78 |
-
|
79 |
-
### Direct Use 🎯
|
80 |
-
|
81 |
-
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.
|
82 |
-
|
83 |
-
### Downstream Use [optional] 🔄
|
84 |
-
|
85 |
-
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.
|
86 |
-
|
87 |
-
### Out-of-Scope Use 🚫
|
88 |
-
|
89 |
-
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.
|
90 |
|
91 |
-
## Bias, Risks, and Limitations ⚠️
|
92 |
|
93 |
-
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.
|
94 |
|
95 |
-
|
96 |
|
97 |
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.
|
98 |
|
99 |
-
|
100 |
|
101 |
```python
|
102 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
@@ -113,13 +83,22 @@ output = model.generate(input_ids, max_length=100, num_return_sequences=1, tempe
|
|
113 |
print(tokenizer.decode(output[0], skip_special_tokens=True))
|
114 |
```
|
115 |
|
116 |
-
## Training Dataset
|
117 |
|
118 |
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.
|
119 |
The dataset encompasses a wide range of topics and provisions within the Peruvian Constitution, providing comprehensive coverage of constitutional principles, rights, and legal interpretations.
|
120 |
|
121 |
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
The training process was executed within a Python environment, utilizing essential libraries to facilitate various tasks:
|
125 |
- **transformers:** Used for loading and fine-tuning the model, providing a seamless interface for working with pre-trained language models.
|
@@ -128,13 +107,13 @@ The training process was executed within a Python environment, utilizing essenti
|
|
128 |
- **peft:** Integrated for applying Low-Rank Adaptation (LoRA) techniques to the model, enabling efficient adaptation to specialized domains without compromising performance.
|
129 |
- **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.
|
130 |
|
131 |
-
|
132 |
|
133 |
QLoRA (Quantization LoRA) was employed to optimize the model's computational efficiency and memory footprint while preserving its accuracy. Two configurations were utilized:
|
134 |
|
135 |
- **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.
|
136 |
```python
|
137 |
-
|
138 |
load_in_4bit=True,
|
139 |
bnb_4bit_quant_type="nf4",
|
140 |
bnb_4bit_compute_dtype=torch.bfloat16,
|
@@ -149,8 +128,9 @@ QLoRA (Quantization LoRA) was employed to optimize the model's computational eff
|
|
149 |
- **bias:** Set to "none" to exclude bias terms from adaptation, simplifying the model architecture.
|
150 |
- **lora_dropout:** Reduced to 0.025 from the default 0.05, controlling the dropout rate during adaptation.
|
151 |
- **task_type:** Configured as "CAUSAL_LM" to indicate the task type of the language model.
|
|
|
152 |
```python
|
153 |
-
|
154 |
r=8,
|
155 |
lora_alpha=16,
|
156 |
target_modules=['q_proj', 'k_proj', 'v_proj', 'o_proj'],
|
@@ -163,7 +143,7 @@ QLoRA (Quantization LoRA) was employed to optimize the model's computational eff
|
|
163 |
These configurations were crucial for optimizing the model's performance and resource utilization during training and inference, ensuring efficient deployment.
|
164 |
|
165 |
|
166 |
-
|
167 |
|
168 |
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.
|
169 |
|
@@ -173,9 +153,20 @@ After fine-tuning, the LoRA-adjusted weights were merged back with the base Gemm
|
|
173 |
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.
|
174 |
|
175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
## To-Do List
|
177 |
|
178 |
-
|
179 |
|
180 |
- [x] Constitution of Peru
|
181 |
- [ ] Penal Code
|
@@ -195,7 +186,7 @@ During the training process, Wandb (Weights & Biases) was used for comprehensive
|
|
195 |
- [ ] Tax Code (TUO)
|
196 |
- [ ] Criminal Procedure Code
|
197 |
|
198 |
-
### License
|
199 |
|
200 |
-
|
201 |
|
|
|
|
25 |
# Model Card for gemma-2b-it-peru-legal-es-V2 ⚖️
|
26 |
|
27 |
<p align="center">
|
28 |
+
<img src="https://cdn-uploads.huggingface.co/production/uploads/64461026e1fd8d65b27e6187/bUbvGpmsKC7YsJs4aBt7T.jpeg" alt="Model Illustration" width="300">
|
29 |
</p>
|
30 |
|
31 |
## Gemma-2B-IT-Peru-Legal-ES
|
|
|
34 |
|
35 |
## Table of Contents
|
36 |
|
37 |
+
- [Gemma-2B-IT-Peru-Legal-ES ⚖️](#gemma-2b-it-peru-legal-es)
|
|
|
38 |
+ [Model Description 📘](#model-description)
|
39 |
+
* [Finetuning Progress 🛠️](#finetuning-progress)
|
|
|
|
|
|
|
|
|
40 |
+ [Recommendations 📝](#recommendations-)
|
41 |
+
* [How to Get Started with the Model 🚀](#how-to-get-started-with-the-model)
|
42 |
+
* [Training Dataset 🧠](#training-dataset)
|
43 |
+
* [Finetuning Progress 🤖](#finetuning-progress)
|
44 |
+
*
|
45 |
+
+ [Environment and Libraries 🖥️](#environment-and-libraries)
|
46 |
+
+ [QLoRA Configuration 🧮](#qlora-configuration)
|
47 |
+
+ [Model Merging and Saving 💾](#model-merging-and-saving)
|
48 |
+
* [Logging with Wandb 📊](#logging-with-wandb)
|
49 |
+
* [Impacto Ambiental 🌳](#impacto-ambiental)
|
50 |
|
51 |
|
52 |
|
53 |
+
## Model Description
|
|
|
|
|
54 |
|
55 |
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.
|
56 |
|
57 |
+
- **Developed by:** [Alonso Quispe](https://huggingface.co/daqc)
|
58 |
- **Model type:** Causal Language Model, specially fine-tuned with LoRA for the distinct domain of Peruvian law and regulation.
|
59 |
- **Language(s) (NLP):** Spanish, tailored for the legal and regulatory context of Peru.
|
60 |
- **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.
|
61 |
+
- **Base model:** google/gemma-2b-it`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
|
65 |
+
## Recommendations
|
66 |
|
67 |
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.
|
68 |
|
69 |
+
# How to Get Started with the Model
|
70 |
|
71 |
```python
|
72 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
83 |
print(tokenizer.decode(output[0], skip_special_tokens=True))
|
84 |
```
|
85 |
|
86 |
+
## Training Dataset
|
87 |
|
88 |
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.
|
89 |
The dataset encompasses a wide range of topics and provisions within the Peruvian Constitution, providing comprehensive coverage of constitutional principles, rights, and legal interpretations.
|
90 |
|
91 |
|
92 |
+
## Finetuning Progress
|
93 |
+
<p align="center">
|
94 |
+
<img src="https://cdn-uploads.huggingface.co/production/uploads/64461026e1fd8d65b27e6187/N8VAkUIuWK0vgYZRlmwew.png" alt="Loss Function Graph" width="900">
|
95 |
+
</p>
|
96 |
+
|
97 |
+
|
98 |
+
---
|
99 |
+
|
100 |
+
|
101 |
+
## Environment and Libraries
|
102 |
|
103 |
The training process was executed within a Python environment, utilizing essential libraries to facilitate various tasks:
|
104 |
- **transformers:** Used for loading and fine-tuning the model, providing a seamless interface for working with pre-trained language models.
|
|
|
107 |
- **peft:** Integrated for applying Low-Rank Adaptation (LoRA) techniques to the model, enabling efficient adaptation to specialized domains without compromising performance.
|
108 |
- **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.
|
109 |
|
110 |
+
## QLoRA Configuration
|
111 |
|
112 |
QLoRA (Quantization LoRA) was employed to optimize the model's computational efficiency and memory footprint while preserving its accuracy. Two configurations were utilized:
|
113 |
|
114 |
- **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.
|
115 |
```python
|
116 |
+
bnb_config = BitsAndBytesConfig(
|
117 |
load_in_4bit=True,
|
118 |
bnb_4bit_quant_type="nf4",
|
119 |
bnb_4bit_compute_dtype=torch.bfloat16,
|
|
|
128 |
- **bias:** Set to "none" to exclude bias terms from adaptation, simplifying the model architecture.
|
129 |
- **lora_dropout:** Reduced to 0.025 from the default 0.05, controlling the dropout rate during adaptation.
|
130 |
- **task_type:** Configured as "CAUSAL_LM" to indicate the task type of the language model.
|
131 |
+
-
|
132 |
```python
|
133 |
+
config = LoraConfig(
|
134 |
r=8,
|
135 |
lora_alpha=16,
|
136 |
target_modules=['q_proj', 'k_proj', 'v_proj', 'o_proj'],
|
|
|
143 |
These configurations were crucial for optimizing the model's performance and resource utilization during training and inference, ensuring efficient deployment.
|
144 |
|
145 |
|
146 |
+
## Model Merging and Saving 💾
|
147 |
|
148 |
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.
|
149 |
|
|
|
153 |
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.
|
154 |
|
155 |
|
156 |
+
|
157 |
+
## Impacto Ambiental
|
158 |
+
|
159 |
+
The training of `gemma-2b-it-peru-legal-es-V2` was conducted optimizing the computational expenditure required.
|
160 |
+
|
161 |
+
- **Hardware Type:** A10G-24GB
|
162 |
+
- **Hours Utilized:** Approximately --- hours
|
163 |
+
- **Energy Consumption:** Approximately --- kWh
|
164 |
+
- **Estimated CO2 Emissions:** Approximately --- kg
|
165 |
+
|
166 |
+
|
167 |
## To-Do List
|
168 |
|
169 |
+
## Dataset Generation, Human Feedback Review with Argilla, and Finetuning with the Following Legal Texts:
|
170 |
|
171 |
- [x] Constitution of Peru
|
172 |
- [ ] Penal Code
|
|
|
186 |
- [ ] Tax Code (TUO)
|
187 |
- [ ] Criminal Procedure Code
|
188 |
|
|
|
189 |
|
190 |
+
## License
|
191 |
|
192 |
+
This project is distributed under the Apache 2.0 license.
|