Zero-Shot Classification
PEFT
Safetensors
decision-model
classification
calibration
kev
system-one
lora
pointer-head
Instructions to use dhtocks/malkuth-4b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use dhtocks/malkuth-4b with PEFT:
from peft import PeftModel from transformers import AutoModel base_model = AutoModel.from_pretrained("Qwen/Qwen3.5-4B-Base") model = PeftModel.from_pretrained(base_model, "dhtocks/malkuth-4b") - Notebooks
- Google Colab
- Kaggle
plainer wording, Korean suite table
Browse files
README.md
CHANGED
|
@@ -9,29 +9,36 @@ tags: [decision-model, classification, calibration, kev, system-one, lora, point
|
|
| 9 |
|
| 10 |
# Malkuth-4B
|
| 11 |
|
| 12 |
-
A small decision model for
|
| 13 |
-
returns a probability distribution over the options instead of generating an answer. Post-trained from
|
| 14 |
-
[Kev](https://github.com/jaredpalmer/kev) and compatible with TypeSafe's System One API.
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
-
|
| 22 |
-
- `choice` (1-255 options), `noul` (yes/no) and `score` (ordered levels), several questions per request
|
| 23 |
-
- Questions share the input text but cannot read each other, so one document can be classified, checked and scored at once
|
| 24 |
-
- Probabilities are temperature-calibrated on a validation split; the temperature never changes which option wins
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
```bash
|
| 31 |
git clone https://github.com/jaredpalmer/kev.git kev && cd kev && uv sync --extra serve
|
| 32 |
uv run --extra serve python -m kev.serve --run dhtocks/malkuth-4b --port 8009
|
| 33 |
```
|
| 34 |
|
|
|
|
|
|
|
| 35 |
```python
|
| 36 |
from typesafe_sdk import Choice, Noul, Score, TypeSafeClient
|
| 37 |
|
|
@@ -51,36 +58,54 @@ print(r.choices["team"].choice, r.choices["team"].probabilities)
|
|
| 51 |
|
| 52 |
## Evaluation
|
| 53 |
|
| 54 |
-
29 suites
|
| 55 |
-
**held-out** is the nine datasets absent from the training mix — the number to read. **all** includes ten we trained
|
| 56 |
-
on. Brier scores the probabilities, not just the chosen answer; lower is better.
|
| 57 |
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|---|---:|---:|---:|
|
| 60 |
| Jev API | **0.754** ±0.0042 | 0.790 | **0.355** |
|
| 61 |
-
|
|
| 62 |
-
|
|
| 63 |
| Kev-9B | 0.700 ±0.0046 | 0.737 | 0.407 |
|
| 64 |
| Kev-4B | 0.686 ±0.0046 | 0.720 | 0.407 |
|
| 65 |
| Kev-0.8B | 0.589 ±0.0050 | 0.584 | 0.539 |
|
| 66 |
| Laya (best of four) | 0.544 ±0.0044 | 0.507 | 0.654 |
|
| 67 |
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
| 71 |
[docs/evaluation.md](https://github.com/newfull5/malkuth/blob/main/docs/evaluation.md).
|
| 72 |
|
| 73 |
## Training data
|
| 74 |
|
| 75 |
-
89,791 labelled requests from 20 public sources
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
| 79 |
|
| 80 |
## License
|
| 81 |
|
| 82 |
-
-
|
| 83 |
-
-
|
| 84 |
|
| 85 |
## Citation
|
| 86 |
|
|
|
|
| 9 |
|
| 10 |
# Malkuth-4B
|
| 11 |
|
| 12 |
+
A small multilingual decision model for classification, with a focus on Korean.
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
Given a text, a question, and a set of criteria, Malkuth returns probabilities over the possible choices instead of
|
| 15 |
+
generating text.
|
| 16 |
|
| 17 |
+
Malkuth-4B is a LoRA adapter trained on [Kev](https://github.com/jaredpalmer/kev) and built on a frozen
|
| 18 |
+
`Qwen/Qwen3.5-4B-Base`. It has 33.8M trainable parameters and a 124 MB adapter.
|
| 19 |
|
| 20 |
+
It supports three question types:
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
- `choice`: select one of up to 255 options
|
| 23 |
+
- `noul`: yes or no
|
| 24 |
+
- `score`: select an ordered level
|
| 25 |
+
|
| 26 |
+
Multiple questions can be evaluated against the same input. Questions are evaluated independently, so they cannot see
|
| 27 |
+
each other's answers. Probabilities are temperature-calibrated on a held-out validation split.
|
| 28 |
|
| 29 |
+
Malkuth is served through Kev and works with the TypeSafe System One API. The companion model is
|
| 30 |
+
[dhtocks/malkuth-2b](https://huggingface.co/dhtocks/malkuth-2b) (2B). Code, training mixes and evaluation live in
|
| 31 |
+
[newfull5/malkuth](https://github.com/newfull5/malkuth).
|
| 32 |
+
|
| 33 |
+
## Usage
|
| 34 |
|
| 35 |
```bash
|
| 36 |
git clone https://github.com/jaredpalmer/kev.git kev && cd kev && uv sync --extra serve
|
| 37 |
uv run --extra serve python -m kev.serve --run dhtocks/malkuth-4b --port 8009
|
| 38 |
```
|
| 39 |
|
| 40 |
+
The official `typesafe-sdk` works against the local server with a `base_url` change.
|
| 41 |
+
|
| 42 |
```python
|
| 43 |
from typesafe_sdk import Choice, Noul, Score, TypeSafeClient
|
| 44 |
|
|
|
|
| 58 |
|
| 59 |
## Evaluation
|
| 60 |
|
| 61 |
+
29 suites and about 129,000 questions. Every model answered the same items. Jev was measured through its API.
|
|
|
|
|
|
|
| 62 |
|
| 63 |
+
- **held-out**: the nine datasets we did not train on
|
| 64 |
+
- **all**: all 29 suites, ten of which we trained on
|
| 65 |
+
- **Brier**: quality of the probabilities, lower is better
|
| 66 |
+
|
| 67 |
+
| Model | Accuracy (held-out) | Accuracy (all) | Brier (held-out) |
|
| 68 |
|---|---:|---:|---:|
|
| 69 |
| Jev API | **0.754** ±0.0042 | 0.790 | **0.355** |
|
| 70 |
+
| Malkuth-4B | 0.724 ±0.0044 | **0.794** | 0.385 |
|
| 71 |
+
| Malkuth-2B | 0.703 ±0.0044 | 0.765 | 0.412 |
|
| 72 |
| Kev-9B | 0.700 ±0.0046 | 0.737 | 0.407 |
|
| 73 |
| Kev-4B | 0.686 ±0.0046 | 0.720 | 0.407 |
|
| 74 |
| Kev-0.8B | 0.589 ±0.0050 | 0.584 | 0.539 |
|
| 75 |
| Laya (best of four) | 0.544 ±0.0044 | 0.507 | 0.654 |
|
| 76 |
|
| 77 |
+
On the five Korean suites:
|
| 78 |
+
|
| 79 |
+
| Suite | Jev | Malkuth-4B | Malkuth-2B | Kev-9B | Kev-4B |
|
| 80 |
+
|---|---:|---:|---:|---:|---:|
|
| 81 |
+
| `klue_nli` | **0.936** | 0.912 | 0.832 | 0.882 | 0.866 |
|
| 82 |
+
| `klue_ynat` | 0.724 | **0.852** | 0.824 | 0.758 | 0.728 |
|
| 83 |
+
| `nsmc` | 0.850 | **0.878** | 0.862 | 0.856 | 0.806 |
|
| 84 |
+
| `kobest` | 0.903 | **0.904** | 0.819 | 0.850 | 0.809 |
|
| 85 |
+
| `kold` | 0.806 | **0.820** | 0.768 | 0.602 | 0.654 |
|
| 86 |
+
| mean | 0.844 | **0.873** | 0.821 | 0.790 | 0.773 |
|
| 87 |
+
|
| 88 |
+
Four of these five contributed their train splits to our mix, so this table is in-distribution for Malkuth.
|
| 89 |
|
| 90 |
+
Latency on one A100 80GB in bf16, median of 20 requests. The second number is a repeated input served from the prefix
|
| 91 |
+
cache. Six questions take 48 ms on a new input and 32 ms on a repeated one.
|
| 92 |
+
|
| 93 |
+
Per-dataset scores and calibration analysis are in
|
| 94 |
[docs/evaluation.md](https://github.com/newfull5/malkuth/blob/main/docs/evaluation.md).
|
| 95 |
|
| 96 |
## Training data
|
| 97 |
|
| 98 |
+
89,791 labelled requests from 20 public sources. 62,400 `choice`, 24,790 `noul` and 7,401 `score` questions, across ten
|
| 99 |
+
core languages with five Korean-only sources.
|
| 100 |
+
|
| 101 |
+
Built by [`tools/build_train_mix.py`](https://github.com/newfull5/malkuth/blob/main/tools/build_train_mix.py).
|
| 102 |
+
Per-source licences are in
|
| 103 |
+
[docs/benchmarks.md](https://github.com/newfull5/malkuth/blob/main/docs/benchmarks.md).
|
| 104 |
|
| 105 |
## License
|
| 106 |
|
| 107 |
+
- Weights: the training mixes include CC-BY-NC datasets.
|
| 108 |
+
- Code: Apache-2.0, same as Kev and the Qwen bases.
|
| 109 |
|
| 110 |
## Citation
|
| 111 |
|