Upload PIBot Joint BERT model package
Browse files- README.md +117 -107
- config.json +1 -1
- model.safetensors +2 -2
- training_args.bin +1 -1
README.md
CHANGED
|
@@ -1,154 +1,164 @@
|
|
| 1 |
---
|
| 2 |
language: es
|
| 3 |
-
license: mit
|
| 4 |
tags:
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
pipeline_tag: token-classification
|
| 15 |
-
library_name: transformers
|
| 16 |
---
|
| 17 |
|
| 18 |
# PIBot Joint BERT
|
| 19 |
|
| 20 |
-
Modelo **
|
| 21 |
-
|
| 22 |
|
| 23 |
-
##
|
| 24 |
|
| 25 |
-
|
|
| 26 |
|---|---|
|
| 27 |
-
|
|
| 28 |
-
|
|
| 29 |
-
|
|
| 30 |
-
|
|
|
|
|
| 31 |
|
| 32 |
-
##
|
| 33 |
|
| 34 |
-
|
|
| 35 |
-
|---|---|
|
| 36 |
-
| `
|
| 37 |
-
| `
|
| 38 |
-
| `
|
| 39 |
-
| `
|
| 40 |
-
| `req_form` | `
|
| 41 |
|
| 42 |
-
## Slot
|
| 43 |
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 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 |
-
|
|
|
|
|
|
|
| 70 |
|
| 71 |
-
###
|
| 72 |
|
| 73 |
```python
|
| 74 |
import torch
|
| 75 |
-
from
|
| 76 |
-
from transformers import AutoConfig, AutoTokenizer, AutoModel
|
| 77 |
-
|
| 78 |
-
repo_id = "tu-usuario/pibot-jointbert" # Cambiar por tu repo
|
| 79 |
|
| 80 |
-
#
|
| 81 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
| 82 |
-
config = AutoConfig.from_pretrained(
|
| 83 |
|
| 84 |
-
#
|
| 85 |
from huggingface_hub import hf_hub_download
|
|
|
|
| 86 |
|
| 87 |
-
|
| 88 |
-
train_args = torch.load(args_path, weights_only=False)
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
|
|
|
| 93 |
|
| 94 |
-
|
| 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 |
-
#
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
config=config,
|
| 105 |
-
|
| 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 |
-
###
|
| 118 |
|
| 119 |
```python
|
| 120 |
-
text = "
|
| 121 |
-
|
| 122 |
|
| 123 |
with torch.no_grad():
|
| 124 |
-
outputs = model(**
|
| 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 |
-
##
|
| 136 |
|
| 137 |
-
```
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
-
|
| 141 |
-
|
|
|
|
| 142 |
|
| 143 |
-
#
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
```
|
| 150 |
|
| 151 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
-
|
| 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": "
|
| 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:
|
| 3 |
-
size
|
|
|
|
| 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:
|
| 3 |
size 2040
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:68a843321a67970998f1578e010bdfed6eff0a16ca74cbfb6cbf8b6394f6e2dc
|
| 3 |
size 2040
|