celiudos commited on
Commit
9695aab
·
verified ·
1 Parent(s): cfcab2a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +176 -1
README.md CHANGED
@@ -69,6 +69,180 @@ model-index:
69
  | EMAIL |
70
  | DINHEIRO |
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  ```python
73
  Num examples = 3,971
74
  Num Epochs = 5
@@ -77,4 +251,5 @@ model-index:
77
  Gradient Accumulation steps = 1
78
  Total optimization steps = 1,245
79
  Number of trainable parameters = 333,364,241
80
- ```
 
 
69
  | EMAIL |
70
  | DINHEIRO |
71
 
72
+ ## Usage
73
+
74
+ ```python
75
+ import torch
76
+ from transformers import pipeline, AutoTokenizer
77
+
78
+ MODEL_NAME = "celiudos/legal-bert-lgpd"
79
+ tokenizer = AutoTokenizer.from_pretrained(
80
+ MODEL_NAME,
81
+ model_max_length=512,
82
+ )
83
+
84
+ pipe = pipeline(
85
+ "ner",
86
+ tokenizer=tokenizer,
87
+ model=MODEL_NAME,
88
+ stride=100,
89
+ aggregation_strategy="first",
90
+ device=0 if torch.cuda.is_available() else -1,
91
+ )
92
+
93
+ pipe(
94
+ "Anotação de Responsabilidade Técnica Nº 1055330634101 de 12 de janeiro de 2013 relativa à Lei Federal Nº 531. Trata-se de representação referente a possível falsificação documentação técnica registrada pelo CREA-SP, feita pelo senhor Francis Pantele da Cozzi, CPF: 412.612.341-32, telefone (31) 951358433, email [email protected], atinente à sua contratação pela senhora Marinalva Bete Raz, CPF: 049.567.041-22, telefone (61) 9412 3333, mulher branca, opinião política conservadora, religião evangélica. Marinalva Bete Raz reclama por indenização por danos morais no dia 14.05.2013 no valor de R$ 82.662,00 (Oitenta e dois mil, seiscentos e sessenta e dois reais) relacionado ao endereço IP 192.168.01 e ao endereço constante no CEP 59123-222, Rua dos Pioneiros, nº 450, Jardim Esmeralda, Campo Grande, MS."
95
+ )
96
+
97
+ ```
98
+
99
+ Output
100
+
101
+ ```json
102
+ [
103
+ {
104
+ "entity_group": "DATA",
105
+ "score": 0.9828296,
106
+ "word": "12 de janeiro de 2013",
107
+ "start": 57,
108
+ "end": 78
109
+ },
110
+ {
111
+ "entity_group": "NOME",
112
+ "score": 0.95766664,
113
+ "word": "Francis Pantele da Cozzi",
114
+ "start": 234,
115
+ "end": 258
116
+ },
117
+ {
118
+ "entity_group": "CPF",
119
+ "score": 0.9954297,
120
+ "word": "412. 612. 341 - 32",
121
+ "start": 265,
122
+ "end": 279
123
+ },
124
+ {
125
+ "entity_group": "TELEFONE",
126
+ "score": 0.5634508,
127
+ "word": "31 )",
128
+ "start": 291,
129
+ "end": 294
130
+ },
131
+ {
132
+ "entity_group": "EMAIL",
133
+ "score": 0.9973985,
134
+ "word": "fran @ bol. com",
135
+ "start": 312,
136
+ "end": 324
137
+ },
138
+ {
139
+ "entity_group": "NOME",
140
+ "score": 0.96683884,
141
+ "word": "Marinalva Bete Raz",
142
+ "start": 366,
143
+ "end": 384
144
+ },
145
+ {
146
+ "entity_group": "CPF",
147
+ "score": 0.99713326,
148
+ "word": "049. 567. 041 - 22",
149
+ "start": 391,
150
+ "end": 405
151
+ },
152
+ {
153
+ "entity_group": "TELEFONE",
154
+ "score": 0.90854883,
155
+ "word": "( 61 ) 9412 3333",
156
+ "start": 416,
157
+ "end": 430
158
+ },
159
+ {
160
+ "entity_group": "NOME",
161
+ "score": 0.9364093,
162
+ "word": "Marinalva Bete Raz",
163
+ "start": 499,
164
+ "end": 517
165
+ },
166
+ {
167
+ "entity_group": "DATA",
168
+ "score": 0.9986375,
169
+ "word": "14",
170
+ "start": 566,
171
+ "end": 568
172
+ },
173
+ {
174
+ "entity_group": "DATA",
175
+ "score": 0.9968226,
176
+ "word": "05",
177
+ "start": 569,
178
+ "end": 571
179
+ },
180
+ {
181
+ "entity_group": "DATA",
182
+ "score": 0.9992943,
183
+ "word": "2013",
184
+ "start": 572,
185
+ "end": 576
186
+ },
187
+ {
188
+ "entity_group": "DINHEIRO",
189
+ "score": 0.99847966,
190
+ "word": "R $ 82. 662, 00",
191
+ "start": 589,
192
+ "end": 601
193
+ },
194
+ {
195
+ "entity_group": "CEP",
196
+ "score": 0.9977593,
197
+ "word": "59123 - 222",
198
+ "start": 728,
199
+ "end": 737
200
+ },
201
+ {
202
+ "entity_group": "ENDERECO",
203
+ "score": 0.9711078,
204
+ "word": "Rua dos Pioneiros",
205
+ "start": 739,
206
+ "end": 756
207
+ },
208
+ {
209
+ "entity_group": "ENDERECO",
210
+ "score": 0.9741938,
211
+ "word": "Jardim Esmeralda",
212
+ "start": 766,
213
+ "end": 782
214
+ },
215
+ {
216
+ "entity_group": "ENDERECO",
217
+ "score": 0.9352198,
218
+ "word": "Campo Grande, MS",
219
+ "start": 784,
220
+ "end": 800
221
+ }
222
+ ]
223
+ ```
224
+
225
+ ### Custom Input Usage
226
+
227
+ ```python
228
+ import gradio as gr
229
+
230
+ def ner(text):
231
+ return {"text": text, "entities": pipe(text)}
232
+
233
+ gr.Interface(
234
+ ner,
235
+ gr.Textbox(placeholder="Enter sentence here..."),
236
+ gr.HighlightedText(),
237
+ live=True,
238
+ examples=[
239
+ "Anotação de Responsabilidade Técnica Nº 1055330634101 de 12 de janeiro de 2013 relativa à Lei Federal Nº 531. Trata-se de representação referente a possível falsificação documentação técnica registrada pelo CREA-SP, feita pelo senhor Francis Pantele da Cozzi, CPF: 412.612.341-32, telefone (31) 951358433, email [email protected].",
240
+ ],
241
+ ).launch()
242
+ ```
243
+
244
+ ## Train Configuration
245
+
246
  ```python
247
  Num examples = 3,971
248
  Num Epochs = 5
 
251
  Gradient Accumulation steps = 1
252
  Total optimization steps = 1,245
253
  Number of trainable parameters = 333,364,241
254
+ ```
255
+