felipergcpqd commited on
Commit
f683943
·
verified ·
1 Parent(s): a474d26

Upload do modelo DeBERTinha NER para endereços brasileiros

Browse files
README.md ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: sagui-nlp/debertinha-ptbr-xsmall-lenerbr
3
+ library_name: peft
4
+ language:
5
+ - pt
6
+ license: apache-2.0
7
+ tags:
8
+ - base_model:adapter:sagui-nlp/debertinha-ptbr-xsmall-lenerbr
9
+ - lora
10
+ - transformers
11
+ - ner
12
+ - token-classification
13
+ - portuguese
14
+ - address-parsing
15
+ - brazilian-portuguese
16
+ datasets:
17
+ - custom
18
+ pipeline_tag: token-classification
19
+ ---
20
+
21
+ # DeBERTinha NER para Endereços Brasileiros
22
+
23
+ Modelo de Named Entity Recognition (NER) para extração de componentes de endereços brasileiros, baseado no [DeBERTinha](https://huggingface.co/sagui-nlp/debertinha-ptbr-xsmall-lenerbr) e treinado com LoRA (Low-Rank Adaptation).
24
+
25
+ ## Descrição do Modelo
26
+
27
+ Este modelo foi fine-tuned para identificar e extrair componentes de endereços brasileiros, incluindo:
28
+
29
+ | Entidade | Descrição | Exemplo |
30
+ |----------|-----------|---------|
31
+ | `LOGRADOURO` | Tipo e nome da via | Rua das Flores, Avenida Brasil |
32
+ | `NUMERO` | Número do imóvel | 123, S/N |
33
+ | `COMPLEMENTO` | Complemento do endereço | Apto 101, Bloco A |
34
+ | `BAIRRO` | Bairro | Centro, Jardim América |
35
+ | `CIDADE` | Cidade/Município | São Paulo, Campinas |
36
+ | `ESTADO` | Estado (sigla ou nome) | SP, São Paulo |
37
+ | `CEP` | Código de Endereçamento Postal | 01310-100 |
38
+ | `PAIS` | País | Brasil |
39
+
40
+ ## Como Usar
41
+
42
+ ### Instalação
43
+
44
+ ```bash
45
+ pip install transformers peft torch
46
+ ```
47
+
48
+ ### Código de Exemplo
49
+
50
+ ```python
51
+ from transformers import AutoTokenizer, AutoModelForTokenClassification
52
+ from peft import PeftModel
53
+ import torch
54
+
55
+ # Carregar o modelo base e o adapter
56
+ base_model_name = "sagui-nlp/debertinha-ptbr-xsmall-lenerbr"
57
+ adapter_name = "felipergcpqd/debertinha-500k-address-ner-pt"
58
+
59
+ # Carregar tokenizer
60
+ tokenizer = AutoTokenizer.from_pretrained(adapter_name)
61
+
62
+ # Carregar modelo base
63
+ base_model = AutoModelForTokenClassification.from_pretrained(
64
+ base_model_name,
65
+ num_labels=17, # 8 entidades x 2 (B-/I-) + O
66
+ ignore_mismatched_sizes=True
67
+ )
68
+
69
+ # Carregar adapter PEFT
70
+ model = PeftModel.from_pretrained(base_model, adapter_name)
71
+ model.eval()
72
+
73
+ # Labels do modelo
74
+ id2label = {
75
+ 0: "O",
76
+ 1: "B-LOGRADOURO", 2: "I-LOGRADOURO",
77
+ 3: "B-NUMERO", 4: "I-NUMERO",
78
+ 5: "B-COMPLEMENTO", 6: "I-COMPLEMENTO",
79
+ 7: "B-BAIRRO", 8: "I-BAIRRO",
80
+ 9: "B-CIDADE", 10: "I-CIDADE",
81
+ 11: "B-ESTADO", 12: "I-ESTADO",
82
+ 13: "B-CEP", 14: "I-CEP",
83
+ 15: "B-PAIS", 16: "I-PAIS"
84
+ }
85
+
86
+ # Fazer predição
87
+ def predict_ner(text):
88
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
89
+
90
+ with torch.no_grad():
91
+ outputs = model(**inputs)
92
+
93
+ predictions = torch.argmax(outputs.logits, dim=2)
94
+ tokens = tokenizer.convert_ids_to_tokens(inputs["input_ids"][0])
95
+
96
+ results = []
97
+ for token, pred in zip(tokens, predictions[0]):
98
+ if token not in ["[CLS]", "[SEP]", "[PAD]"]:
99
+ label = id2label[pred.item()]
100
+ results.append((token, label))
101
+
102
+ return results
103
+
104
+ # Exemplo de uso
105
+ endereco = "Rua das Flores, 123, Apto 45, Centro, São Paulo, SP, 01310-100"
106
+ resultado = predict_ner(endereco)
107
+
108
+ for token, label in resultado:
109
+ if label != "O":
110
+ print(f"{token}: {label}")
111
+ ```
112
+
113
+ ### Usando com Pipeline (após merge)
114
+
115
+ Se você quiser usar o modelo completo (merged), você pode fazer:
116
+
117
+ ```python
118
+ from transformers import pipeline
119
+ from peft import PeftModel, AutoPeftModelForTokenClassification
120
+
121
+ # Carregar e fazer merge do modelo
122
+ model = AutoPeftModelForTokenClassification.from_pretrained(
123
+ "felipergcpqd/debertinha-500k-address-ner-pt"
124
+ )
125
+ merged_model = model.merge_and_unload()
126
+
127
+ # Criar pipeline
128
+ ner_pipeline = pipeline(
129
+ "token-classification",
130
+ model=merged_model,
131
+ tokenizer=tokenizer,
132
+ aggregation_strategy="simple"
133
+ )
134
+
135
+ resultado = ner_pipeline("Av. Paulista, 1000, Bela Vista, São Paulo - SP, 01310-100")
136
+ print(resultado)
137
+ ```
138
+
139
+ ## Detalhes do Treinamento
140
+
141
+ - **Modelo Base:** [sagui-nlp/debertinha-ptbr-xsmall-lenerbr](https://huggingface.co/sagui-nlp/debertinha-ptbr-xsmall-lenerbr)
142
+ - **Técnica de Fine-tuning:** LoRA (Low-Rank Adaptation)
143
+ - **Framework:** PEFT 0.18.0
144
+ - **Dataset:** Dataset sintético de ~500k endereços brasileiros
145
+ - **Tarefa:** Token Classification / NER
146
+
147
+ ### Hyperparâmetros LoRA
148
+
149
+ ```python
150
+ LoraConfig(
151
+ r=16,
152
+ lora_alpha=32,
153
+ target_modules=["query_proj", "key_proj", "value_proj", "dense"],
154
+ lora_dropout=0.1,
155
+ bias="none",
156
+ task_type="TOKEN_CLS"
157
+ )
158
+ ```
159
+
160
+ ## Limitações
161
+
162
+ - O modelo foi treinado principalmente com endereços brasileiros
163
+ - Endereços muito mal formatados podem ter resultados menos precisos
164
+ - O modelo pode ter dificuldades com abreviações não convencionais
165
+
166
+ ## Citação
167
+
168
+ Se usar este modelo, por favor cite:
169
+
170
+ ```bibtex
171
+ @misc{debertinha-address-ner,
172
+ author = {Felipe R. G.},
173
+ title = {DeBERTinha NER para Endereços Brasileiros},
174
+ year = {2026},
175
+ publisher = {Hugging Face},
176
+ url = {https://huggingface.co/felipergcpqd/debertinha-500k-address-ner-pt}
177
+ }
178
+ ```
179
+
180
+ ## Licença
181
+
182
+ Apache 2.0
adapter_config.json ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alora_invocation_tokens": null,
3
+ "alpha_pattern": {},
4
+ "arrow_config": null,
5
+ "auto_mapping": null,
6
+ "base_model_name_or_path": "sagui-nlp/debertinha-ptbr-xsmall-lenerbr",
7
+ "bias": "none",
8
+ "corda_config": null,
9
+ "ensure_weight_tying": false,
10
+ "eva_config": null,
11
+ "exclude_modules": null,
12
+ "fan_in_fan_out": false,
13
+ "inference_mode": true,
14
+ "init_lora_weights": true,
15
+ "layer_replication": null,
16
+ "layers_pattern": null,
17
+ "layers_to_transform": null,
18
+ "loftq_config": {},
19
+ "lora_alpha": 32,
20
+ "lora_bias": false,
21
+ "lora_dropout": 0.1,
22
+ "megatron_config": null,
23
+ "megatron_core": "megatron.core",
24
+ "modules_to_save": [
25
+ "classifier",
26
+ "score"
27
+ ],
28
+ "peft_type": "LORA",
29
+ "peft_version": "0.18.0",
30
+ "qalora_group_size": 16,
31
+ "r": 16,
32
+ "rank_pattern": {},
33
+ "revision": null,
34
+ "target_modules": [
35
+ "query_proj",
36
+ "value_proj",
37
+ "key_proj"
38
+ ],
39
+ "target_parameters": null,
40
+ "task_type": "TOKEN_CLS",
41
+ "trainable_token_indices": null,
42
+ "use_dora": false,
43
+ "use_qalora": false,
44
+ "use_rslora": false
45
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4c4843e829efe99174e964ab644ef6ab828ee974e7aa6d2665f49fe98d93699d
3
+ size 1809564
special_tokens_map.json ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "[CLS]",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "cls_token": {
10
+ "content": "[CLS]",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "eos_token": {
17
+ "content": "[SEP]",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "mask_token": {
24
+ "content": "[MASK]",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "pad_token": {
31
+ "content": "[PAD]",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ },
37
+ "sep_token": {
38
+ "content": "[SEP]",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false
43
+ },
44
+ "unk_token": {
45
+ "content": "[UNK]",
46
+ "lstrip": false,
47
+ "normalized": false,
48
+ "rstrip": false,
49
+ "single_word": false
50
+ }
51
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "50265": {
4
+ "content": "[MASK]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "50266": {
12
+ "content": "[SEP]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "50267": {
20
+ "content": "[PAD]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "50268": {
28
+ "content": "[UNK]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "50269": {
36
+ "content": "[CLS]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "bos_token": "[CLS]",
45
+ "clean_up_tokenization_spaces": true,
46
+ "cls_token": "[CLS]",
47
+ "do_lower_case": false,
48
+ "eos_token": "[SEP]",
49
+ "extra_special_tokens": {},
50
+ "mask_token": "[MASK]",
51
+ "max_length": 512,
52
+ "model_max_length": 128,
53
+ "pad_to_multiple_of": null,
54
+ "pad_token": "[PAD]",
55
+ "pad_token_type_id": 0,
56
+ "padding_side": "right",
57
+ "sep_token": "[SEP]",
58
+ "sp_model_kwargs": {},
59
+ "split_by_punct": false,
60
+ "tokenizer_class": "DebertaV2TokenizerFast",
61
+ "unk_token": "[UNK]"
62
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ece63df466772955b5a6ac916db645c7fe46b3a3e281ef77454064197a0b5811
3
+ size 5841