pacovalentino commited on
Commit
26e1ac2
·
verified ·
1 Parent(s): 799d58e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +128 -1
README.md CHANGED
@@ -14,4 +14,131 @@ tags:
14
  - LoRA
15
  datasets:
16
  - pacovalentino/synth_emerg_ITA
17
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  - LoRA
15
  datasets:
16
  - pacovalentino/synth_emerg_ITA
17
+ ---
18
+
19
+ ESEMPIO DI UTILIZZO / USAGE EXAMPLE
20
+
21
+ ITALIANO
22
+
23
+ Questo esempio mostra come caricare il modello e il tokenizer, applicare la pipeline NER a un testo di esempio e stampare le entità estratte.
24
+
25
+ ```python
26
+ import torch
27
+ from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
28
+
29
+ path_model = "./Text2NER"
30
+
31
+ tokenizer = AutoTokenizer.from_pretrained(path_model)
32
+ model = AutoModelForTokenClassification.from_pretrained(path_model)
33
+ model.eval()
34
+
35
+ ner_pipeline = pipeline(
36
+ "ner",
37
+ model=model,
38
+ tokenizer=tokenizer,
39
+ aggregation_strategy="simple",
40
+ device=0 if torch.cuda.is_available() else -1
41
+ )
42
+
43
+ text = """
44
+ In Via Verdi a Parma, il paziente Mario Rossi, maschio, 58 anni, presentava dolore toracico con SpO₂ 91%,
45
+ PA 160/95 mmHg, FC 112 bpm; codice uscita Rosso, rientro 2, sul posto la Croce Rossa Italiana di Parma, autista Bianchi Luca,
46
+ medico Dott. Verdi Andrea.
47
+ """
48
+
49
+ results = ner_pipeline(text)
50
+
51
+ print(f"{'ENTITÀ':<40} | {'LABEL'}")
52
+ print("-" * 60)
53
+ for r in results:
54
+ entity = r["word"]
55
+ label = r["entity_group"]
56
+ print(f"{entity:<40} | {label}")
57
+ ```
58
+
59
+ OUTPUT ATTESO
60
+
61
+ ENTITÀ | LABEL
62
+ ------------------------------------------------------------
63
+ Via Verdi a Parma | LUOGO_INTERVENTO
64
+ Mario Rossi | NOME_COGNOME
65
+ maschio | SESSO
66
+ 58 anni | DATA_NASCITA
67
+ SpO₂ 91% | SpO2
68
+ PA 160/95 mmHg | PA_MMHG
69
+ FC 112 bpm | FC_BPM
70
+ Rosso | CODICE_USCITA
71
+ 2 | CODICE_RIENTRO
72
+ Croce Rossa Italiana di Parma | CRI
73
+ Bianchi Luca | AUTISTA
74
+ Dott. Verdi Andrea | MEDICO
75
+
76
+ DESCRIZIONE
77
+
78
+ Il codice mostra passo passo come inizializzare il tokenizer e il modello, creare la pipeline NER con aggregazione,
79
+ applicarla a un testo di esempio e stampare le entità in formato tabellare chiaro. La tabella rappresenta le entità
80
+ automaticamente riconosciute dal modello con le rispettive label, utile per analisi strutturate delle schede emergenziali
81
+ del servizio 118.
82
+
83
+ ENGLISH
84
+
85
+ This example shows how to load the model and tokenizer, apply the NER pipeline to a sample text, and print the extracted entities.
86
+
87
+ ```python
88
+ import torch
89
+ from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
90
+
91
+ path_model = "./Text2NER"
92
+
93
+ tokenizer = AutoTokenizer.from_pretrained(path_model)
94
+ model = AutoModelForTokenClassification.from_pretrained(path_model)
95
+ model.eval()
96
+
97
+ ner_pipeline = pipeline(
98
+ "ner",
99
+ model=model,
100
+ tokenizer=tokenizer,
101
+ aggregation_strategy="simple",
102
+ device=0 if torch.cuda.is_available() else -1
103
+ )
104
+
105
+ text = """
106
+ At Via Verdi in Parma, the patient Mario Rossi, male, 58 years old, presented with chest pain and SpO₂ 91%,
107
+ PA 160/95 mmHg, FC 112 bpm; exit code Red, return 2, on site the Italian Red Cross of Parma, driver Bianchi Luca,
108
+ doctor Dr. Verdi Andrea.
109
+ """
110
+
111
+ results = ner_pipeline(text)
112
+
113
+ print(f"{'ENTITY':<40} | {'LABEL'}")
114
+ print("-" * 60)
115
+ for r in results:
116
+ entity = r["word"]
117
+ label = r["entity_group"]
118
+ print(f"{entity:<40} | {label}")
119
+ ```
120
+
121
+ EXPECTED OUTPUT
122
+
123
+ ENTITY | LABEL
124
+ ------------------------------------------------------------
125
+ Via Verdi in Parma | LUOGO_INTERVENTO
126
+ Mario Rossi | NOME_COGNOME
127
+ male | SESSO
128
+ 58 years old | DATA_NASCITA
129
+ SpO₂ 91% | SpO2
130
+ PA 160/95 mmHg | PA_MMHG
131
+ FC 112 bpm | FC_BPM
132
+ Red | CODICE_USCITA
133
+ 2 | CODICE_RIENTRO
134
+ Italian Red Cross of Parma | CRI
135
+ Bianchi Luca | AUTISTA
136
+ Dr. Verdi Andrea | MEDICO
137
+
138
+ DESCRIPTION
139
+
140
+ The code shows step by step how to initialize the tokenizer and model, create the NER pipeline with aggregation,
141
+ apply it to a text example, and print the entities in a clear tabular format. The table represents the entities
142
+ automatically recognized by the model with their corresponding labels, suitable for structured analysis of emergency
143
+ medical records.
144
+