Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,94 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: mit
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
language:
|
| 4 |
+
- it
|
| 5 |
+
base_model:
|
| 6 |
+
- unsloth/Qwen2.5-7B-Instruct-bnb-4bit
|
| 7 |
+
pipeline_tag: text-generation
|
| 8 |
+
library_name: transformers
|
| 9 |
+
tags:
|
| 10 |
+
- legal
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
## Usage
|
| 14 |
+
Install the following dependencies:
|
| 15 |
+
```sh
|
| 16 |
+
pip install transformers==4.49.0
|
| 17 |
+
pip install bitsandbytes==0.45.3
|
| 18 |
+
pip install peft==0.15.0
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
Define the system prompt and the text to simplify:
|
| 22 |
+
```py
|
| 23 |
+
PROMPT = """Sei un esperto redattore di documenti istituzionali italiani.
|
| 24 |
+
|
| 25 |
+
Migliora la leggibilità dei riferimenti normativi presenti in un documento istituzionale. **Non alterare il contenuto e lo stile del testo originale**.
|
| 26 |
+
|
| 27 |
+
# Steps
|
| 28 |
+
1. Leggi attentamente il testo.
|
| 29 |
+
2. Individua tutti i riferimenti normativi presenti nel testo.
|
| 30 |
+
3. Normalizza tutti i riferimenti normativi nella forma "art. [numero articolo], comma [numero comma], lettera [lettera]) del [norma] [nuemero]/[anno] e successive modifiche".
|
| 31 |
+
4. Se la tipologia di normativa è scritta per esteso, utilizza l'acronimo solo per quelle più comuni (es. D.Lgs, D.P.R., L.R., C.C, ...).
|
| 32 |
+
|
| 33 |
+
# Output Format
|
| 34 |
+
Il testo corretto con l'originale formattazione e suddivisione in sezioni e paragrafi.
|
| 35 |
+
|
| 36 |
+
# Examples
|
| 37 |
+
- **Input**: D.Lgs. 08.08.1994, n. 490
|
| 38 |
+
**Output**: D.Lgs. 490/1994
|
| 39 |
+
- **Input**: art. 43 D.P.R. 28.12.2000, n. 445
|
| 40 |
+
**Output**: art. 43 D.P.R 445/2000
|
| 41 |
+
- **Input**: articolo 16 del d.P.R. 30 dicembre 1982, n. 955 s.m.i.
|
| 42 |
+
**Output**: art. 16 D.P.R 955/1982 e successive modifiche
|
| 43 |
+
- **Input**: articolo 16, comma 2, lettera c) L.R. n. 18/08
|
| 44 |
+
**Output**: art. 16, comma 2, lettera c) della L.R. 18/08
|
| 45 |
+
- **Input**: articoli 19, 46 e 47 del decreto del Presidente della Repubblica n. 445/2000
|
| 46 |
+
**Output**: artt. 19, 46 e 47 del D.P.R 445/2000
|
| 47 |
+
|
| 48 |
+
# Notes
|
| 49 |
+
- Il testo fornito può essere complesso e richiede attenzione ai dettagli.
|
| 50 |
+
- Esegui solamente le operazioni descritte, **non eliminare e non modificare altri contenuti**.
|
| 51 |
+
- Assicurati che le implicazioni giuridiche e legali del documento siano mantenute."""
|
| 52 |
+
|
| 53 |
+
TEXT_TO_SIMPLIFY = """Il documento individua le esigenze di sviluppo necessarie per assicurare che i principi delineati dalla Legge Regionale 23 dicembre 2004, n. 29 e dai successivi atti normativi, sulla essenziale funzione della ricerca e innovazione nelle Aziende Sanitarie della Regione Emilia-Romagna, si traducano in azioni concrete nel Servizio Sanitario Regionale.
|
| 54 |
+
|
| 55 |
+
Alla luce delle evidenze della letteratura internazionale, delle indicazioni della normativa nazionale e della valutazione di quanto già attuato a livello regionale negli anni passati, vengono individuati gli obiettivi di sviluppo e le linee per il raggiungimento dei suddetti obiettivi."""
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
Load SEMPL-IT model and tokenizer:
|
| 59 |
+
```py
|
| 60 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 61 |
+
|
| 62 |
+
tokenizer = AutoTokenizer.from_pretrained("VerbACxSS/sempl-it-lex-awq")
|
| 63 |
+
model = AutoModelForCausalLM.from_pretrained("VerbACxSS/sempl-it-lex-awq").to("cuda")
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
Define and apply chat template:
|
| 67 |
+
```py
|
| 68 |
+
chat = [
|
| 69 |
+
{"role": "system", "content": PROMPT},
|
| 70 |
+
{"role": "assistant", "content": TEXT_TO_SIMPLIFY},
|
| 71 |
+
]
|
| 72 |
+
|
| 73 |
+
formatted_chat = tokenizer.apply_chat_template(
|
| 74 |
+
chat,
|
| 75 |
+
tokenize=False,
|
| 76 |
+
add_generation_prompt=True
|
| 77 |
+
)
|
| 78 |
+
model_inputs = tokenizer([formatted_chat], return_tensors="pt").to("cuda")
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
Use SEMPL_IT model with following sampling parameters to generate `simplified_text`:
|
| 82 |
+
```py
|
| 83 |
+
generated_ids = model.generate(
|
| 84 |
+
**model_inputs,
|
| 85 |
+
max_new_tokens=4096,
|
| 86 |
+
temperature=0.1,
|
| 87 |
+
top_p=0.2
|
| 88 |
+
)
|
| 89 |
+
simplified_text = tokenizer.decode(generated_ids[0][len(model_inputs.input_ids[0]):], skip_special_tokens=True)
|
| 90 |
+
print(simplified_text)
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
## Acknowledgements
|
| 94 |
+
This contribution is a result of the research conducted within the framework of the PRIN 2020 (Progetti di Rilevante Interesse Nazionale) "VerbACxSS: on analytic verbs, complexity, synthetic verbs, and simplification. For accessibility" (Prot. 2020BJKB9M), funded by the Italian Ministero dell'Università e della Ricerca.
|