Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,78 +1,254 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
library_name: alben
|
|
|
|
| 4 |
tags:
|
| 5 |
- system-one
|
| 6 |
- decision-model
|
| 7 |
- calibration
|
| 8 |
-
-
|
| 9 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
# Alben
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
**
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
```python
|
| 22 |
from alben import Alben
|
| 23 |
|
| 24 |
-
a = Alben()
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
```
|
| 31 |
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
| | |
|
| 35 |
|---|---|
|
| 36 |
-
|
|
| 37 |
-
|
|
| 38 |
-
|
|
| 39 |
-
|
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
| 49 |
-
|
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|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|
- system-one
|
| 7 |
- decision-model
|
| 8 |
- calibration
|
| 9 |
+
- text-classification
|
| 10 |
+
- zero-shot-classification
|
| 11 |
+
- multilingual
|
| 12 |
+
language:
|
| 13 |
+
- en
|
| 14 |
+
- zh
|
| 15 |
+
- de
|
| 16 |
+
- fr
|
| 17 |
+
- es
|
| 18 |
+
- ja
|
| 19 |
+
- ko
|
| 20 |
+
- ar
|
| 21 |
+
- hi
|
| 22 |
+
- th
|
| 23 |
---
|
| 24 |
|
| 25 |
# Alben
|
| 26 |
|
| 27 |
+
**An open, self-hosted decision model.** Give it a piece of text and a set of typed
|
| 28 |
+
questions, and it answers them — a label, a rating on an ordered scale, or a
|
| 29 |
+
probability. No API key, no per-token billing, no data leaving your machine.
|
| 30 |
|
| 31 |
+
Alben answers questions **you define at request time**. You are not restricted to a
|
| 32 |
+
fixed taxonomy: pass any set of options, with a description of what each one means,
|
| 33 |
+
and the model scores the text against them. Up to 255 options, or an ordered scale of
|
| 34 |
+
2–10 levels, or a yes/no.
|
| 35 |
|
| 36 |
+
It speaks the same HTTP protocol as TypeSafe's System One API, so existing clients —
|
| 37 |
+
including the official Python and JavaScript SDKs — work against it unchanged. That is
|
| 38 |
+
a compatibility property, deliberately maintained; it is not the point of the project.
|
| 39 |
+
The point is a small, inspectable, self-hostable model that stays useful when the
|
| 40 |
+
question is one nobody anticipated.
|
| 41 |
+
|
| 42 |
+
```bash
|
| 43 |
+
pip install alben
|
| 44 |
+
```
|
| 45 |
|
| 46 |
```python
|
| 47 |
from alben import Alben
|
| 48 |
|
| 49 |
+
a = Alben() # fetches this checkpoint on first use
|
| 50 |
+
|
| 51 |
+
answer = a.predict(
|
| 52 |
+
"We were billed twice for March. Refund today or we cancel.",
|
| 53 |
+
{
|
| 54 |
+
"team": {
|
| 55 |
+
"type": "choice",
|
| 56 |
+
"instructions": "Which team should handle this?",
|
| 57 |
+
"criteria": {"billing": "invoices and refunds",
|
| 58 |
+
"tech": "bugs and outages"},
|
| 59 |
+
},
|
| 60 |
+
"urgency": {
|
| 61 |
+
"type": "score",
|
| 62 |
+
"instructions": "How urgent is this?",
|
| 63 |
+
"criteria": ["can wait", "this week", "today", "immediately"],
|
| 64 |
+
},
|
| 65 |
+
"churn_risk": {
|
| 66 |
+
"type": "noul",
|
| 67 |
+
"instructions": "Did they threaten to cancel?",
|
| 68 |
+
},
|
| 69 |
+
},
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
print(answer["answers"]["team"]["choice"]) # billing
|
| 73 |
+
print(answer["answers"]["urgency"]["score"]) # 1.35 — between two levels
|
| 74 |
+
print(answer["answers"]["churn_risk"]["noul"]) # 0.38
|
| 75 |
```
|
| 76 |
|
| 77 |
+
The response is the same shape the System One API returns (`model` / `answers` /
|
| 78 |
+
`usage`, probabilities rounded to two decimals) — deliberately, so the official SDKs
|
| 79 |
+
parse it without changes.
|
| 80 |
+
|
| 81 |
+
---
|
| 82 |
+
|
| 83 |
+
## What is in this checkpoint
|
| 84 |
+
|
| 85 |
+
`bge-small-zh-v1.5`-based sentence encoder with a trained projection head, fine-tuned
|
| 86 |
+
end-to-end on questions the model had to answer from the option descriptions alone.
|
| 87 |
|
| 88 |
| | |
|
| 89 |
|---|---|
|
| 90 |
+
| Base encoder | `bge-small-zh-v1.5` — BAAI, MIT. Fetched at runtime, **not redistributed here** |
|
| 91 |
+
| Training examples | **56160** |
|
| 92 |
+
| Distinct question sets | **1882** — each with its own label names and wording |
|
| 93 |
+
| Answer types | choice (≤255 options) · ordered score (2–10 levels) · yes/no |
|
| 94 |
+
| Calibration | temperature scaling, fitted on a text-disjoint held-out set |
|
| 95 |
+
| Footprint | ~92 MB checkpoint + ~92 MB encoder, runs on CPU or CUDA |
|
| 96 |
+
| License | Apache-2.0 (this checkpoint) |
|
| 97 |
+
|
| 98 |
+
### Training data
|
| 99 |
+
|
| 100 |
+
Assembled from the **train splits** of public research datasets —
|
| 101 |
+
[MASSIVE](https://github.com/alexa/massive) (10 languages),
|
| 102 |
+
[BANKING77](https://github.com/PolyAI-LDN/task-specific-datasets),
|
| 103 |
+
[AG News](https://huggingface.co/datasets/fancyzhx/ag_news),
|
| 104 |
+
[DAIR Emotion](https://huggingface.co/datasets/dair-ai/emotion),
|
| 105 |
+
[SST-5](https://huggingface.co/datasets/SetFit/sst5) — plus synthetic question sets
|
| 106 |
+
generated for this project. Evaluation splits were held out and decontaminated;
|
| 107 |
+
3 upstream duplicates between SST-5 train and test were removed from the training side.
|
| 108 |
|
| 109 |
+
---
|
| 110 |
|
| 111 |
+
## Measured accuracy
|
| 112 |
+
|
| 113 |
+
Public benchmarks, **test splits only**:
|
| 114 |
+
|
| 115 |
+
| Benchmark | Alben | Random | Release gate |
|
| 116 |
+
|---|---|---|---|
|
| 117 |
+
| MASSIVE intent, English (60 intents) | **0.6975** | 0.0303 | ≥ 0.60 |
|
| 118 |
+
| MASSIVE intent, 9 other languages | **0.3883** | 0.0303 | ≥ 0.30 |
|
| 119 |
+
| BANKING77 (77 classes) | **0.8817** | 0.0500 | ≥ 0.70 |
|
| 120 |
+
| SST-5 (5-level ordered) | **0.3133** | 0.2000 | ≥ 0.25 |
|
| 121 |
+
|
| 122 |
+
Per language, MASSIVE intent — the spread is worth seeing before you deploy:
|
| 123 |
+
|
| 124 |
+
| Language | MASSIVE intent |
|
| 125 |
+
|---|---|
|
| 126 |
+
| `en-US` | 0.6975 |
|
| 127 |
+
| `zh-CN` | 0.8025 |
|
| 128 |
+
| `de-DE` | 0.4600 |
|
| 129 |
+
| `fr-FR` | 0.4550 |
|
| 130 |
+
| `es-ES` | 0.5050 |
|
| 131 |
+
| `ja-JP` | 0.6350 |
|
| 132 |
+
| `ko-KR` | 0.1475 |
|
| 133 |
+
| `ar-SA` | 0.2125 |
|
| 134 |
+
| `hi-IN` | 0.1125 |
|
| 135 |
+
| `th-TH` | 0.1650 |
|
| 136 |
+
|
| 137 |
+
On held-out question sets from the same task family (0% text overlap with training,
|
| 138 |
+
label-balanced, real question wording): **0.6465** average, **0.6178** worst.
|
| 139 |
+
|
| 140 |
+
Every gate above is checked by a script before release — `python -u release.py verify`,
|
| 141 |
+
which exits non-zero on failure. The gates were fixed **before** the model was trained.
|
| 142 |
+
|
| 143 |
+
---
|
| 144 |
+
|
| 145 |
+
## Calibrated confidence
|
| 146 |
|
| 147 |
+
Confidence is temperature-scaled on a held-out set that shares no text with training.
|
| 148 |
+
Accuracy is unchanged by calibration; only the confidence moves.
|
| 149 |
|
| 150 |
+
| | Accuracy | Mean confidence | ECE ↓ |
|
| 151 |
|---|---|---|---|
|
| 152 |
+
| Raw | 0.7019 | 0.8167 | 0.1273 |
|
| 153 |
+
| Calibrated (T = 1.65) | 0.7019 | 0.7089 | **0.0508** |
|
| 154 |
+
|
| 155 |
+
Expected calibration error falls by **60%**. A confidence threshold is
|
| 156 |
+
therefore meaningful for routing: act above it, escalate below it.
|
| 157 |
+
|
| 158 |
+
---
|
| 159 |
|
| 160 |
+
## Honest limitations
|
| 161 |
|
| 162 |
+
We would rather you know these before you build on it.
|
| 163 |
+
|
| 164 |
+
| Scenario | Works? | Measured |
|
| 165 |
|---|---|---|
|
| 166 |
+
| Questions whose labels resemble what it trained on | **Yes** | 0.62–0.88 on unseen text |
|
| 167 |
+
| Same task, different language | **Yes, unevenly** | 0.70 (en) down to 0.11 (hi) across 10 languages |
|
| 168 |
+
| **A genuinely new question type** | **No — near chance** | 0.3150 vs 0.3211 random |
|
| 169 |
+
| **New question type + a few dozen labelled examples** | **Yes** | 0.4917 → 0.9917 |
|
| 170 |
+
|
| 171 |
+
In one line: **it generalises across text and language, not across question types.**
|
| 172 |
+
|
| 173 |
+
We checked the second row rather than assuming it. Splitting BANKING77's 77 labels in
|
| 174 |
+
half — train on 38, evaluate on the other 39 with zero training examples — gives 0.5208,
|
| 175 |
+
against 0.4725 for the frozen encoder and 0.9158 for a model that saw all 77. So most of
|
| 176 |
+
the headline accuracy comes from having seen that label set, not from generalising to a
|
| 177 |
+
new one. That is why the next section exists.
|
| 178 |
+
|
| 179 |
+
### Teaching a new question type
|
| 180 |
+
|
| 181 |
+
This is a first-class operation, not a workaround:
|
| 182 |
+
|
| 183 |
+
```bash
|
| 184 |
+
python -m alben.teach --examples my_labelled_rows.jsonl --out my-dim.pt
|
| 185 |
+
```
|
| 186 |
+
|
| 187 |
+
```python
|
| 188 |
+
a.teach(examples=my_labelled_rows, out="my-dim.pt", epochs=12)
|
| 189 |
+
# -> {"before": 0.513, "after": 0.663, "forgetting_delta": -0.020}
|
| 190 |
+
```
|
| 191 |
+
|
| 192 |
+
A few dozen examples are enough. Two properties matter, and both are measured:
|
| 193 |
+
|
| 194 |
+
- **Reported honestly** — `teach` returns *before*, *after*, and a forgetting probe
|
| 195 |
+
computed on old data that was **not** replayed into training. Reporting only *after*
|
| 196 |
+
would make any model look good.
|
| 197 |
+
- **Local gains** — untrained control questions move by **+0.0000**. Teaching one
|
| 198 |
+
question type does not teach another. Teach the type you need.
|
| 199 |
+
|
| 200 |
+
---
|
| 201 |
+
|
| 202 |
+
## Reproduce every number
|
| 203 |
+
|
| 204 |
+
```bash
|
| 205 |
+
git clone https://github.com/XiaoBinGan/Alben && cd Alben
|
| 206 |
+
pip install -e ".[dev]"
|
| 207 |
+
|
| 208 |
+
python -u release.py verify # the six acceptance gates, exits non-zero on failure
|
| 209 |
+
python -u release.py status # what is deployed right now
|
| 210 |
+
python -u corpus/am_i_general.py # the three senses of "general", with evidence
|
| 211 |
+
```
|
| 212 |
+
|
| 213 |
+
---
|
| 214 |
+
|
| 215 |
+
## Attribution
|
| 216 |
+
|
| 217 |
+
- **This checkpoint**: Apache-2.0.
|
| 218 |
+
- **Base encoder**: [`BAAI/bge-small-zh-v1.5`](https://huggingface.co/BAAI/bge-small-zh-v1.5)
|
| 219 |
+
(Beijing Academy of Artificial Intelligence), MIT. Fetched at runtime; **not**
|
| 220 |
+
redistributed in this repository.
|
| 221 |
+
- **Training text**: MASSIVE (CC BY 4.0), BANKING77 (CC BY 4.0), AG News, DAIR Emotion,
|
| 222 |
+
SST-5 — train splits only, under their respective licenses.
|
| 223 |
+
- **Protocol compatibility**: Alben implements the publicly documented request and response
|
| 224 |
+
shapes of the TypeSafe System One API so existing clients interoperate. It is an
|
| 225 |
+
independent implementation: no TypeSafe weights, no TypeSafe training data, and no
|
| 226 |
+
affiliation or endorsement. Outputs are not expected to match the hosted service.
|
| 227 |
+
|
| 228 |
+
---
|
| 229 |
+
|
| 230 |
+
## 中文说明
|
| 231 |
+
|
| 232 |
+
Alben 是一个**可自托管的决策模型**。给它一段文本和一组你自己定义的问题,它返回
|
| 233 |
+
**经过校准的**答案 —— 分类、有序打分、或是/否概率。不用 API key,不按 token 计费,
|
| 234 |
+
数据不出你的机器。
|
| 235 |
+
|
| 236 |
+
**重点是「问题由你在运行时定义」**:传任意一组选项、每个选项的描述,模型据此给
|
| 237 |
+
文本打分。最多 255 个选项,或 2–10 级有序打分,或是/否。
|
| 238 |
+
|
| 239 |
+
它说同一套 HTTP 协议,所以现成客户端(含官方 SDK)不用改就能用。**兼容是刻意维护的
|
| 240 |
+
特性,但不是这个项目的重点。**
|
| 241 |
+
|
| 242 |
+
| 项 | 值 |
|
| 243 |
+
|---|---|
|
| 244 |
+
| 训练样本 | **56160** |
|
| 245 |
+
| 不同问题集 | **1882** |
|
| 246 |
+
| 底模 | `bge-small-zh-v1.5`(BAAI,MIT,**不随本仓库分发**) |
|
| 247 |
+
| 许可 | Apache-2.0 |
|
| 248 |
+
|
| 249 |
+
**能力边界(必须一起读)**:它跨**文本**和**语言**泛化,**不跨问题类型**泛化。
|
| 250 |
+
遇到全新类型的问题时接近随机(0.3150 vs 随机 0.3211);但给几十条标注做热启动微调
|
| 251 |
+
就能学会(0.4917 → 0.9917),而且**收益只限教过的那个类型**(未教过的对照问题 +0.0000)。
|
| 252 |
+
|
| 253 |
+
完整数据、复现命令、以及我们**明确排除掉的方向**,见
|
| 254 |
+
[GitHub 仓库](https://github.com/XiaoBinGan/Alben)。
|