Update README.md
Browse files
README.md
CHANGED
|
@@ -2,198 +2,139 @@
|
|
| 2 |
library_name: transformers
|
| 3 |
tags: []
|
| 4 |
---
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
|
|
|
| 10 |
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
| 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 |
-
|
| 75 |
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
### Training Data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
-
|
| 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 |
-
|
| 106 |
-
|
| 107 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
-
|
| 174 |
|
| 175 |
-
|
|
|
|
|
|
|
| 176 |
|
| 177 |
-
|
|
|
|
| 178 |
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
-
|
| 182 |
|
| 183 |
-
|
| 184 |
|
| 185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
|
| 187 |
-
|
| 188 |
|
| 189 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
|
| 191 |
-
|
| 192 |
|
| 193 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
|
| 195 |
-
|
| 196 |
|
| 197 |
-
##
|
|
|
|
| 198 |
|
| 199 |
-
[More Information Needed]
|
|
|
|
| 2 |
library_name: transformers
|
| 3 |
tags: []
|
| 4 |
---
|
| 5 |
+
# MEL: Legal Spanish Language Model
|
| 6 |
|
| 7 |
+
## Model Card for MEL
|
| 8 |
|
| 9 |
+
**Model Name:** MEL (Modelo de Español Legal)
|
| 10 |
+
**Model Type:** Encoder-only Transformer (XLM-RoBERTa-large continuation)
|
| 11 |
+
**Language:** Spanish
|
| 12 |
+
**Domain:** Legal Texts
|
| 13 |
+
**License:** [Specify License]
|
| 14 |
+
**Model Link:** [Hugging Face Repository Link]
|
| 15 |
|
| 16 |
+
---
|
| 17 |
|
| 18 |
+
## Overview
|
| 19 |
+
MEL is a transformer-based language model designed specifically for processing and understanding Spanish legal texts. Built upon **XLM-RoBERTa-large**, it is further pre-trained on a **large corpus of legal documents**, including the **Boletín Oficial del Estado (BOE), parliamentary transcripts, court rulings, and other legislative texts**. MEL significantly improves the performance of legal NLP tasks, such as **legal text classification** and **named entity recognition (NER)**.
|
| 20 |
|
| 21 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
## Model Description
|
| 24 |
|
| 25 |
+
### Architecture
|
| 26 |
+
- **Base Model:** XLM-RoBERTa-large
|
| 27 |
+
- **Training Objective:** Masked Language Modeling (MLM)
|
| 28 |
+
- **Pre-training Strategy:** Continued pre-training on Spanish legal texts
|
| 29 |
+
- **Context Window:** 512 tokens
|
| 30 |
|
| 31 |
### Training Data
|
| 32 |
+
MEL is trained on a **curated corpus** of **5.52 million legal texts (~92.7GB)** sourced from:
|
| 33 |
+
- **BOE (Boletín Oficial del Estado)**
|
| 34 |
+
- **Parliamentary records**
|
| 35 |
+
- **Court rulings**
|
| 36 |
+
- **Legal statutes**
|
| 37 |
+
|
| 38 |
+
To ensure high-quality text processing, documents were preprocessed by **removing unwanted characters, normalizing spacing, chunking texts, and filtering non-Spanish content**.
|
| 39 |
+
|
| 40 |
+
### Training Configuration
|
| 41 |
+
- **GPU:** NVIDIA A100 80GB PCIe
|
| 42 |
+
- **Training Time:** 13.9 days (~7 days per epoch, 2 epochs total)
|
| 43 |
+
- **Optimizer:** AdamW (β1=0.9, β2=0.98, ϵ=1e-6)
|
| 44 |
+
- **Batch Size:** 16 (Gradient Accumulation: 4, Effective Batch Size: 64)
|
| 45 |
+
- **Scheduler:** Cosine Learning Rate Scheduler
|
| 46 |
+
- **Warmup Steps:** 8% of total training steps
|
| 47 |
+
- **Learning Rate:** 1e-4
|
| 48 |
+
- **Weight Decay:** 0.01
|
| 49 |
|
| 50 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
## Evaluation
|
| 53 |
+
MEL was benchmarked on two datasets:
|
| 54 |
|
| 55 |
+
### **1. Multieurlex (Spanish Legal Texts Classification)**
|
| 56 |
+
- **Task:** Multilabel classification of EU laws
|
| 57 |
+
- **Performance:**
|
| 58 |
+
- **MEL achieves an F1 score of 0.8025**, outperforming **XLM-RoBERTa-Large (0.7962)**, **Legal-XLM-RoBERTa (0.7933)**, and **RoBERTalex (0.7890)**.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
+
### **2. Private Multiclass Classification Dataset**
|
| 61 |
+
- **Task:** Classify legal documents into one of 9 categories
|
| 62 |
+
- **Performance:**
|
| 63 |
+
- **MEL achieves an F1 score of 0.9260**, surpassing **XLM-RoBERTa-Large (0.9103)**, **Legal-XLM-RoBERTa (0.8935)**, and **RoBERTalex (0.7007)**.
|
| 64 |
+
- **Small Data Learning:** MEL shows better generalization even with limited training data, achieving an **F1 score of 0.8812** in early training compared to the next best **0.7803**.
|
| 65 |
|
| 66 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
+
## Model Performance
|
| 69 |
+
### **Key Findings**
|
| 70 |
+
✔ **Outperforms general multilingual models (XLM-RoBERTa) and other domain-specific models in Spanish legal text classification.**
|
| 71 |
+
✔ **Requires less fine-tuning, demonstrating strong domain adaptation from the pre-training phase.**
|
| 72 |
+
✔ **Shows high sample efficiency, achieving strong results even with limited training data.**
|
| 73 |
|
| 74 |
+
### **Limitations**
|
| 75 |
+
⚠ **Not evaluated on NER or token-level tasks due to the lack of annotated Spanish legal datasets.**
|
| 76 |
+
⚠ **Trained only on Spanish legal texts, so performance in multilingual legal contexts is unknown.**
|
| 77 |
+
⚠ **Potential bias in legal terminology due to corpus selection.**
|
| 78 |
|
| 79 |
+
---
|
| 80 |
|
| 81 |
+
## How to Use
|
| 82 |
+
```python
|
| 83 |
+
from transformers import AutoModel, AutoTokenizer
|
| 84 |
|
| 85 |
+
tokenizer = AutoTokenizer.from_pretrained("your-hf-repo/mel")
|
| 86 |
+
model = AutoModel.from_pretrained("your-hf-repo/mel")
|
| 87 |
|
| 88 |
+
text = "El artículo 45 de la Constitución establece que..."
|
| 89 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 90 |
+
outputs = model(**inputs)
|
| 91 |
+
```
|
| 92 |
|
| 93 |
+
For fine-tuning on specific legal tasks, use `Trainer` from Hugging Face’s `transformers` library.
|
| 94 |
|
| 95 |
+
---
|
| 96 |
|
| 97 |
+
## Future Work
|
| 98 |
+
- Develop **NER models** for **legal entity extraction**.
|
| 99 |
+
- Expand dataset to cover **more diverse legal domains** (e.g., contracts, case law, administrative procedures).
|
| 100 |
+
- Fine-tune on additional **downstream tasks** (question answering, legal summarization, information retrieval).
|
| 101 |
+
- Improve **bias detection and mitigation strategies**.
|
| 102 |
|
| 103 |
+
---
|
| 104 |
|
| 105 |
+
## Citation
|
| 106 |
+
If you use MEL, please cite:
|
| 107 |
+
```
|
| 108 |
+
@misc{sánchez2025mellegalspanishlanguage,
|
| 109 |
+
title={MEL: Legal Spanish Language Model},
|
| 110 |
+
author={David Betancur Sánchez and Nuria Aldama García and Álvaro Barbero Jiménez and Marta Guerrero Nieto and Patricia Marsà Morales and Nicolás Serrano Salas and Carlos García Hernán and Pablo Haya Coll and Elena Montiel Ponsoda and Pablo Calleja Ibáñez},
|
| 111 |
+
year={2025},
|
| 112 |
+
eprint={2501.16011},
|
| 113 |
+
archivePrefix={arXiv},
|
| 114 |
+
primaryClass={cs.CL},
|
| 115 |
+
url={https://arxiv.org/abs/2501.16011},
|
| 116 |
+
}
|
| 117 |
+
```
|
| 118 |
|
| 119 |
+
---
|
| 120 |
|
| 121 |
+
## Acknowledgements
|
| 122 |
+
This work was funded by the **INESData project**, supported by the **Ministry for Digital Transformation and the Civil Service (NextGenerationEU)**.
|
| 123 |
+
|
| 124 |
+
**Contributors:**
|
| 125 |
+
- **David Betancur Sánchez**, Instituto de Ingeniería del Conocimiento (IIC)
|
| 126 |
+
- **Nuria Aldama García**, Instituto de Ingeniería del Conocimiento (IIC)
|
| 127 |
+
- **Álvaro Barbero Jiménez**, Instituto de Ingeniería del Conocimiento (IIC)
|
| 128 |
+
- **Marta Guerrero Nieto**, Instituto de Ingeniería del Conocimiento (IIC)
|
| 129 |
+
- **Patricia Marsà Morales**, Instituto de Ingeniería del Conocimiento (IIC)
|
| 130 |
+
- **Nicolás Serrano Salas**, Instituto de Ingeniería del Conocimiento (IIC)
|
| 131 |
+
- **Carlos García Hernán**, Instituto de Ingeniería del Conocimiento (IIC)
|
| 132 |
+
- **Pablo Haya Coll**, Instituto de Ingeniería del Conocimiento (IIC)
|
| 133 |
+
- **Elena Montiel Ponsoda**, Universidad Politécnica de Madrid
|
| 134 |
+
- **Pablo Calleja Ibáñez**, Universidad Politécnica de Madrid
|
| 135 |
|
| 136 |
+
---
|
| 137 |
|
| 138 |
+
## Contact
|
| 139 |
+
For questions or collaborations, contact **david.betancur@iic.uam.es**.
|
| 140 |
|
|
|