smenaaliaga commited on
Commit
b634f3a
·
verified ·
1 Parent(s): ca01597

Upload PIBot Joint BERT model package

Browse files
Files changed (4) hide show
  1. README.md +117 -107
  2. config.json +1 -1
  3. model.safetensors +2 -2
  4. training_args.bin +1 -1
README.md CHANGED
@@ -1,154 +1,164 @@
1
  ---
2
  language: es
3
- license: mit
4
  tags:
5
- - pytorch
6
- - bert
7
- - joint-bert
8
- - intent-classification
9
- - slot-filling
10
- - named-entity-recognition
11
- - multi-head-classification
12
- - spanish
13
- - macroeconomics
14
  pipeline_tag: token-classification
15
- library_name: transformers
16
  ---
17
 
18
  # PIBot Joint BERT
19
 
20
- Modelo **JointBERT multi-cabeza** para consultas macroeconómicas en español.
21
- Predice simultáneamente **5 cabezas de intención** + **slot filling BIO** por token.
22
 
23
- ## Configuración del checkpoint
24
 
25
- | Parámetro | Valor |
26
  |---|---|
27
- | **Task** | `pibimacecv5` |
28
- | **Base model** | `dccuchile/bert-base-spanish-wwm-cased` (BETO) |
29
- | **Model type** | `bert` |
30
- | **Custom code** | (`trust_remote_code=True`) |
 
31
 
32
- ## Cabezas de intención
33
 
34
- | Cabeza | Archivo de labels |
35
- |---|---|
36
- | `calc_mode` | `labels/calc_mode_label.txt` |
37
- | `activity` | `labels/activity_label.txt` |
38
- | `region` | `labels/region_label.txt` |
39
- | `investment` | `labels/investment_label.txt` |
40
- | `req_form` | `labels/req_form_label.txt` |
41
 
42
- ## Slot filling
43
 
44
- - Etiquetado BIO por token (`labels/slot_label.txt`)
45
 
46
- ## Estructura del repositorio
47
 
48
- ```text
49
- ├── config.json # Configuración del modelo
50
- ├── model.safetensors # Pesos del modelo
51
- ├── training_args.bin # Argumentos de entrenamiento
52
- ├── tokenizer.json # Tokenizer
53
- ├── tokenizer_config.json
54
- ├── vocab.txt
55
- ├── special_tokens_map.json
56
- ├── modeling_jointbert.py # Código custom (AutoModel)
57
- ├── module.py # Clasificadores por cabeza
58
- ├── __init__.py
59
- ├── labels/
60
- │ ├── calc_mode_label.txt
61
- │ ├── activity_label.txt
62
- │ ├── region_label.txt
63
- │ ├── investment_label.txt
64
- │ ├── req_form_label.txt
65
- │ └── slot_label.txt
66
- └── README.md
67
- ```
68
 
69
- ## Uso rápido
 
 
70
 
71
- ### Descargar y cargar el modelo
72
 
73
  ```python
74
  import torch
75
- from pathlib import Path
76
- from transformers import AutoConfig, AutoTokenizer, AutoModel
77
-
78
- repo_id = "tu-usuario/pibot-jointbert" # Cambiar por tu repo
79
 
80
- # 1. Cargar tokenizer y config
81
- tokenizer = AutoTokenizer.from_pretrained(repo_id, trust_remote_code=True)
82
- config = AutoConfig.from_pretrained(repo_id, trust_remote_code=True)
83
 
84
- # 2. Cargar training args y labels
85
  from huggingface_hub import hf_hub_download
 
86
 
87
- args_path = hf_hub_download(repo_id, "training_args.bin")
88
- train_args = torch.load(args_path, weights_only=False)
89
 
90
- def read_labels(repo_id, filename):
91
- path = hf_hub_download(repo_id, f"labels/{filename}")
92
- return [line.strip() for line in open(path, encoding="utf-8") if line.strip()]
 
93
 
94
- calc_mode_labels = read_labels(repo_id, "calc_mode_label.txt")
95
- activity_labels = read_labels(repo_id, "activity_label.txt")
96
- region_labels = read_labels(repo_id, "region_label.txt")
97
- investment_labels = read_labels(repo_id, "investment_label.txt")
98
- req_form_labels = read_labels(repo_id, "req_form_label.txt")
99
- slot_labels = read_labels(repo_id, "slot_label.txt")
100
 
101
- # 3. Instanciar modelo
102
- model = AutoModel.from_pretrained(
103
- repo_id,
 
 
 
 
 
 
 
 
104
  config=config,
105
- trust_remote_code=True,
106
- args=train_args,
107
- calc_mode_label_lst=calc_mode_labels,
108
- activity_label_lst=activity_labels,
109
- region_label_lst=region_labels,
110
- investment_label_lst=investment_labels,
111
- req_form_label_lst=req_form_labels,
112
  slot_label_lst=slot_labels,
 
113
  )
114
  model.eval()
115
  ```
116
 
117
- ### Inferencia
118
 
119
  ```python
120
- text = "cual fue el ultimo imacec"
121
- inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=64)
122
 
123
  with torch.no_grad():
124
- outputs = model(**inputs)
125
-
126
- # outputs contiene logits de cada cabeza de intención y slot filling
127
- calc_mode_logits = outputs[1] # (batch, num_calc_mode_labels)
128
- activity_logits = outputs[2] # (batch, num_activity_labels)
129
- region_logits = outputs[3] # (batch, num_region_labels)
130
- investment_logits = outputs[4] # (batch, num_investment_labels)
131
- req_form_logits = outputs[5] # (batch, num_req_form_labels)
132
- slot_logits = outputs[6] # (batch, seq_len, num_slot_labels)
133
  ```
134
 
135
- ### Uso en endpoint (snapshot local)
136
 
137
- ```python
138
- from huggingface_hub import snapshot_download
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
 
140
- # Descargar checkpoint completo
141
- model_dir = snapshot_download("tu-usuario/pibot-jointbert")
 
142
 
143
- # Cargar labels desde carpeta local
144
- from pathlib import Path
145
- labels_dir = Path(model_dir) / "labels"
146
- labels = {}
147
- for f in labels_dir.glob("*_label.txt"):
148
- labels[f.stem] = [l.strip() for l in f.read_text(encoding="utf-8").splitlines() if l.strip()]
 
 
 
 
149
  ```
150
 
151
- ## Referencia
 
 
 
 
 
 
152
 
153
- - Paper base: [BERT for Joint Intent Classification and Slot Filling](https://arxiv.org/abs/1810.04805v2)
154
- - Implementación original: [monologg/JointBERT](https://github.com/monologg/JointBERT)
 
1
  ---
2
  language: es
 
3
  tags:
4
+ - intent-classification
5
+ - slot-filling
6
+ - joint-bert
7
+ - spanish
8
+ - economics
9
+ - chile
10
+ - multi-head
11
+ license: mit
12
+ base_model: dccuchile/bert-base-spanish-wwm-cased
13
  pipeline_tag: token-classification
 
14
  ---
15
 
16
  # PIBot Joint BERT
17
 
18
+ Modelo **Joint BERT multi-head** para clasificación de intención y slot filling,
19
+ especializado en consultas sobre indicadores macroeconómicos del Banco Central de Chile.
20
 
21
+ ## Arquitectura
22
 
23
+ | Componente | Detalle |
24
  |---|---|
25
+ | Base | `dccuchile/bert-base-spanish-wwm-cased` |
26
+ | Task | `pibimacecv3` |
27
+ | Intent heads | 5 (`activity`, `calc_mode`, `investment`, `region`, `req_form`) |
28
+ | Slot labels | 15 (BIO) |
29
+ | Custom code | `modeling_jointbert.py`, `module.py` |
30
 
31
+ ### Intent Heads
32
 
33
+ | Head | Clases | Valores |
34
+ |---|---|---|
35
+ | `activity` | 3 | `none`, `specific`, `general` |
36
+ | `calc_mode` | 4 | `original`, `prev_period`, `yoy`, `contribution` |
37
+ | `investment` | 3 | `none`, `specific`, `general` |
38
+ | `region` | 3 | `none`, `specific`, `general` |
39
+ | `req_form` | 3 | `latest`, `point`, `range` |
40
 
41
+ ### Slot Entities (BIO)
42
 
43
+ Entidades extraídas: `activity`, `frequency`, `indicator`, `investment`, `period`, `region`, `seasonality`
44
 
45
+ Esquema BIO completo: 15 etiquetas (`O`, `B-*`, `I-*`).
46
 
47
+ ## Uso
48
+
49
+ ### Instalación
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
+ ```bash
52
+ pip install torch transformers
53
+ ```
54
 
55
+ ### Carga del Modelo
56
 
57
  ```python
58
  import torch
59
+ from transformers import AutoTokenizer, AutoConfig
 
 
 
60
 
61
+ # Cargar tokenizer y config
62
+ tokenizer = AutoTokenizer.from_pretrained("smenaaliaga/pibert", trust_remote_code=True)
63
+ config = AutoConfig.from_pretrained("smenaaliaga/pibert", trust_remote_code=True)
64
 
65
+ # Cargar labels desde el repo
66
  from huggingface_hub import hf_hub_download
67
+ import os
68
 
69
+ label_dir = os.path.dirname(hf_hub_download("smenaaliaga/pibert", "labels/slot_label.txt"))
 
70
 
71
+ # Leer intent y slot labels
72
+ def read_labels(path):
73
+ with open(path) as f:
74
+ return [line.strip() for line in f if line.strip()]
75
 
76
+ slot_labels = read_labels(os.path.join(label_dir, "slot_label.txt"))
 
 
 
 
 
77
 
78
+ # Preparar intent_label_lst para cada head
79
+ intent_label_lst = []
80
+ for head in ['activity', 'calc_mode', 'investment', 'region', 'req_form']:
81
+ intent_label_lst.append(read_labels(os.path.join(label_dir, f"{head}_label.txt")))
82
+
83
+ # Cargar modelo con custom code
84
+ from transformers import AutoModelForTokenClassification
85
+ from modeling_jointbert import JointBERT # auto-cargado con trust_remote_code
86
+
87
+ model = JointBERT.from_pretrained(
88
+ "smenaaliaga/pibert",
89
  config=config,
90
+ intent_label_lst=intent_label_lst,
 
 
 
 
 
 
91
  slot_label_lst=slot_labels,
92
+ trust_remote_code=True,
93
  )
94
  model.eval()
95
  ```
96
 
97
+ ### Predicción
98
 
99
  ```python
100
+ text = "cuál fue el imacec de agosto 2024"
101
+ tokens = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
102
 
103
  with torch.no_grad():
104
+ outputs = model(**tokens)
105
+ # outputs contiene intent_logits (lista) y slot_logits
 
 
 
 
 
 
 
106
  ```
107
 
108
+ ## Estructura del Paquete
109
 
110
+ ```
111
+ model_package/
112
+ ├── config.json # Configuración BERT + task
113
+ ├── model.safetensors # Pesos del modelo
114
+ ├── tokenizer.json # Tokenizer
115
+ ├── tokenizer_config.json
116
+ ├── special_tokens_map.json
117
+ ├── vocab.txt
118
+ ├── modeling_jointbert.py # Arquitectura JointBERT (custom)
119
+ ├── module.py # CRF y módulos auxiliares
120
+ ├── __init__.py
121
+ ├── README.md # Este archivo
122
+ └── labels/
123
+ ├── slot_label.txt
124
+ ├── activity_label.txt
125
+ ├── calc_mode_label.txt
126
+ ├── investment_label.txt
127
+ ├── region_label.txt
128
+ ├── req_form_label.txt
129
+ ```
130
+
131
+ ## Datos de Entrenamiento
132
+
133
+ Entrenado con datos de consultas sobre indicadores macroeconómicos chilenos:
134
+ - **IMACEC** (Indicador Mensual de Actividad Económica)
135
+ - **PIB** (Producto Interno Bruto)
136
+ - Sectores económicos, frecuencias, períodos, regiones
137
+
138
+ ## Limitaciones
139
 
140
+ - Especializado en consultas macroeconómicas del Banco Central de Chile
141
+ - Mejor rendimiento en consultas cortas (< 50 tokens)
142
+ - Requiere `trust_remote_code=True` por la arquitectura custom
143
 
144
+ ## Cita
145
+
146
+ ```bibtex
147
+ @misc{pibot-jointbert,
148
+ author = {Banco Central de Chile},
149
+ title = {PIBot Joint BERT - Multi-head Intent + Slot Filling},
150
+ year = {2025},
151
+ publisher = {Hugging Face},
152
+ howpublished = {\url{https://huggingface.co/smenaaliaga/pibert}}
153
+ }
154
  ```
155
 
156
+ ## Referencias
157
+
158
+ - [BERT for Joint Intent Classification and Slot Filling](https://arxiv.org/abs/1902.10909)
159
+ - [JointBERT implementation](https://github.com/monologg/JointBERT)
160
+ - [BETO: Spanish BERT](https://github.com/dccuchile/beto)
161
+
162
+ ## Licencia
163
 
164
+ MIT License
 
config.json CHANGED
@@ -5,7 +5,7 @@
5
  ],
6
  "attention_probs_dropout_prob": 0.1,
7
  "classifier_dropout": null,
8
- "finetuning_task": "pibimacecv5",
9
  "gradient_checkpointing": false,
10
  "hidden_act": "gelu",
11
  "hidden_dropout_prob": 0.1,
 
5
  ],
6
  "attention_probs_dropout_prob": 0.1,
7
  "classifier_dropout": null,
8
+ "finetuning_task": "pibimacecv3",
9
  "gradient_checkpointing": false,
10
  "hidden_act": "gelu",
11
  "hidden_dropout_prob": 0.1,
model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:1d6084a789c8845d2d09b6ff593aff3639c66db677c9c7bd7399fca3eed7b902
3
- size 439525264
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f55af5f294478cb5085ae95a082a81bdaa637ce671d5cd466629b19db1e7f7fb
3
+ size 439524020
training_args.bin CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:91f6bf5e8606b9c4a901c47a0cde8195ea2546e401ff0cef645286e98ffab140
3
  size 2040
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:68a843321a67970998f1578e010bdfed6eff0a16ca74cbfb6cbf8b6394f6e2dc
3
  size 2040