Update model card (README.md)
Browse files
README.md
CHANGED
|
@@ -1,199 +1,103 @@
|
|
|
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
-
# Model
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 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 |
---
|
| 3 |
+
tags:
|
| 4 |
+
- multi-label
|
| 5 |
+
- text-classification
|
| 6 |
---
|
| 7 |
|
| 8 |
+
# Model Description
|
| 9 |
+
This model is a fine-tuned dbmdz/bert-base-italian-xxl-cased for multi-label text classification on Eutekne domande_fitlri_materie train dataset.
|
| 10 |
+
|
| 11 |
+
# Intended Use
|
| 12 |
+
This model is intended for classifying legal questions into 216 categories. These categories are based on the Eutekne domande_fitlri_materie.
|
| 13 |
+
|
| 14 |
+
# Training Details
|
| 15 |
+
|
| 16 |
+
## Base Model
|
| 17 |
+
This model is a finetuning of: **dbmdz/bert-base-italian-xxl-cased**
|
| 18 |
+
|
| 19 |
+
## Training Data
|
| 20 |
+
```json
|
| 21 |
+
{
|
| 22 |
+
"train_samples": 4044,
|
| 23 |
+
"val_samples": 867,
|
| 24 |
+
"test_samples": 867,
|
| 25 |
+
"num_labels": 216
|
| 26 |
+
}
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
## Training Hyperparameters
|
| 30 |
+
|
| 31 |
+
```json
|
| 32 |
+
{
|
| 33 |
+
"batch_size": 32,
|
| 34 |
+
"learning_rate": 2e-05,
|
| 35 |
+
"num_epochs": 5,
|
| 36 |
+
"max_length": 512,
|
| 37 |
+
"threshold": 0.5
|
| 38 |
+
}
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
## Evaluation Results
|
| 42 |
+
|
| 43 |
+
```json
|
| 44 |
+
| | validation_results | test_results |
|
| 45 |
+
|:---------------------|---------------------:|---------------:|
|
| 46 |
+
| eval_exact_match | 0.310265 | 0.303345 |
|
| 47 |
+
| eval_hamming_loss | 0.00932868 | 0.00976654 |
|
| 48 |
+
| eval_f1_micro | 0.589038 | 0.566896 |
|
| 49 |
+
| eval_f1_macro | 0.142712 | 0.157367 |
|
| 50 |
+
| eval_precision_micro | 0.773795 | 0.746259 |
|
| 51 |
+
| eval_precision_macro | 0.206659 | 0.234683 |
|
| 52 |
+
| eval_recall_micro | 0.475503 | 0.457045 |
|
| 53 |
+
| eval_recall_macro | 0.118758 | 0.13034 |
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
```json
|
| 57 |
+
| | hit_rate | precision | recall | f1 | ndcg | coverage | mrr |
|
| 58 |
+
|:----|-----------:|------------:|---------:|-------:|-------:|-----------:|-------:|
|
| 59 |
+
| @1 | 0.7255 | 0.7255 | 0.2076 | 0.302 | 0.7255 | 0.2076 | 0.2076 |
|
| 60 |
+
| @3 | 0.8316 | 0.5398 | 0.4278 | 0.4389 | 0.6316 | 0.4278 | 0.3084 |
|
| 61 |
+
| @5 | 0.8674 | 0.3852 | 0.4841 | 0.3924 | 0.5862 | 0.4841 | 0.3214 |
|
| 62 |
+
| @10 | 0.9193 | 0.2261 | 0.546 | 0.2955 | 0.5756 | 0.546 | 0.3297 |
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
## How to Use
|
| 66 |
+
|
| 67 |
+
```python
|
| 68 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 69 |
+
from huggingface_hub import hf_hub_download
|
| 70 |
+
import pickle
|
| 71 |
+
import torch
|
| 72 |
+
import numpy as np
|
| 73 |
+
|
| 74 |
+
repo_id = "giacomorossojakala/dbmdz-bert-base-italian-xxl-cased-eutekne-filtri-materia-lv2"
|
| 75 |
+
|
| 76 |
+
# Load tokenizer and model
|
| 77 |
+
tokenizer = AutoTokenizer.from_pretrained(repo_id)
|
| 78 |
+
model = AutoModelForSequenceClassification.from_pretrained(repo_id)
|
| 79 |
+
|
| 80 |
+
# Download and load label encoder
|
| 81 |
+
downloaded_path = hf_hub_download(repo_id=repo_id, filename="label_encoder.pkl")
|
| 82 |
+
with open(downloaded_path, 'rb') as f:
|
| 83 |
+
mlb = pickle.load(f)
|
| 84 |
+
|
| 85 |
+
custom_text = "agevolazioni acquisto prima casa"
|
| 86 |
+
inputs = tokenizer(custom_text, truncation=True, padding=True, max_length=512, return_tensors="pt")
|
| 87 |
+
|
| 88 |
+
model.eval()
|
| 89 |
+
with torch.no_grad():
|
| 90 |
+
outputs = model(**inputs)
|
| 91 |
+
|
| 92 |
+
logits = outputs.logits
|
| 93 |
+
probabilities = torch.sigmoid(logits)
|
| 94 |
+
predictions = (probabilities > 0.75).int().cpu().numpy()
|
| 95 |
+
predicted_labels = mlb.inverse_transform(predictions)
|
| 96 |
+
ranked_idexes = np.argsort(probabilities.cpu().numpy(), axis=1)[:, ::-1]
|
| 97 |
+
ranked_labels = np.array(mlb.classes_)[ranked_idexes]
|
| 98 |
+
|
| 99 |
+
print(f"Custom Text: agevolazioni acquisto prima casa")
|
| 100 |
+
print(f"Predicted Labels: ('V',)")
|
| 101 |
+
print(f"Ranked Labels: {'[' +', '.join(ranked_labels[0, :5]) + '...]'}")
|
| 102 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
|
|