Pdbz199 commited on
Commit
4b3077c
·
verified ·
1 Parent(s): 1ced1b3

Upload local-decision-model

Browse files
README.md ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-nc-4.0
3
+ language: en
4
+ library_name: pytorch
5
+ base_model: answerdotai/ModernBERT-base
6
+ pipeline_tag: zero-shot-classification
7
+ tags: [decision-model, zero-shot-classification, structured-output, guardrails, extraction, modernbert]
8
+ ---
9
+
10
+ # local-decision-model
11
+
12
+ A small, fast decision model: **unstructured state in, typed probabilistic decisions out.**
13
+ One forward pass of a 150M parameter encoder answers a whole schema of typed questions about a piece of text,
14
+ typically in 10 to 25 ms on a consumer GPU. It never generates text, so every output is guaranteed to match its declared type.
15
+
16
+ Code, training recipe, experiments and full results: https://github.com/Pdbz199/local-decision-model
17
+
18
+ ![demo](https://github.com/Pdbz199/local-decision-model/raw/main/assets/hero.gif)
19
+
20
+ ## Usage
21
+
22
+ These weights need the small `decisionmodel` package from the GitHub repo (they are not a standard `transformers` head).
23
+
24
+ ```bash
25
+ pip install git+https://github.com/Pdbz199/local-decision-model
26
+ ```
27
+
28
+ ```python
29
+ from decisionmodel import DecisionModel, Bool, Enum, MultiLabel, Int, Extract
30
+
31
+ dm = DecisionModel.load("Pdbz199/local-decision-model")
32
+
33
+ d = dm.decide("My order #48213 arrived with a cracked screen. Refund me today or I dispute the charge.", {
34
+ "urgent": Bool("Does this need a response within the hour?"),
35
+ "team": Enum("Which team should handle this ticket?", ["billing and refunds", "technical support", "sales"]),
36
+ "anger": Int("How angry is the customer, from 1 (calm) to 5 (furious)?", 1, 5),
37
+ "order_id": Extract("What is the order number?"),
38
+ })
39
+ print(d.team.value, d.team.confidence, d.urgent.p(), d.order_id.value)
40
+ ```
41
+
42
+ Types: `Bool`, `Enum` (2 to 255 options), `MultiLabel`, `Int`, `Float`, `Extract` (a verbatim substring of the input, or `None`).
43
+
44
+ ## How it works
45
+
46
+ ModernBERT-base with two small heads. The schema is written into the input as
47
+ `[CLS] [MODE] question [OPT] option 1 [OPT] option 2 ... [SEP] state [SEP]`. The hidden state at each `[OPT]` token is scored,
48
+ so all options are judged in the same pass; a span head handles extraction. Trained with log loss on about one million
49
+ examples recast from roughly 50 public datasets, then temperature-calibrated on tasks that were never trained on.
50
+
51
+ ## Results on tasks never seen in training
52
+
53
+ | Held-out task | Type | Result |
54
+ | --- | --- | --- |
55
+ | IMDB sentiment | Bool | 94.4% accuracy, calibration error 0.016 |
56
+ | SQuAD v2 dev | Extract | 82.8% exact match, F1 85.8 |
57
+ | AG News topics | Enum (4) | 74.0% |
58
+ | Twitter financial news sentiment | Enum (3) | 74.1% |
59
+ | Banking77 intents | Enum (77) | 63.0% top 1, 80.2% top 3; 83.6% on the 48% of calls with confidence of at least 0.9 |
60
+ | deepset prompt injections | Bool | 69.6% accuracy, AUROC 0.87 |
61
+ | SMS spam | Bool | 64.9% with a vague question, 89.4% with a precise one (AUROC 0.94 to 0.96) |
62
+
63
+ Latency (RTX 5070 Ti, bfloat16, median): single yes/no 10 ms, 8 typed fields 16 ms, 77 options 11 ms, 255 options 21 ms, 8,000 token input 351 ms.
64
+
65
+ ## Limitations
66
+
67
+ * A small model: good at judgments a person could make at a glance, weak at implied or conditional meaning.
68
+ * Sensitive to question wording. Test a schema on a few real examples before trusting it.
69
+ * `MultiLabel` under-predicts when several options are true at once. Ask important tags as their own `Bool`.
70
+ * Confidence is well calibrated on familiar kinds of task and can be overconfident on unfamiliar ones.
71
+ * English only. Guardrail decisions can be wrong: do not use it as a sole security boundary.
72
+
73
+ ## Licensing
74
+
75
+ The code is MIT licensed. The base model is Apache 2.0. These weights were trained on public datasets with mixed
76
+ licenses, some of which restrict commercial use (for example lmsys/toxic-chat, CC BY-NC 4.0, and the Yelp reviews
77
+ dataset). The weights are therefore released under cc-by-nc-4.0. If you need different terms, retrain with
78
+ `scripts/build_data.py` after removing the sources that do not fit your use; every source is listed in that file.
79
+
80
+ ## Relation to Jev
81
+
82
+ This project was inspired by TypeSafe AI's blog post introducing "System One Models" and their model Jev.
83
+ It is an independent, generic implementation built only from that public post, and is not affiliated with TypeSafe AI.
encoder/config.json ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "ModernBertModel"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 50281,
8
+ "classifier_activation": "gelu",
9
+ "classifier_bias": false,
10
+ "classifier_dropout": 0.0,
11
+ "classifier_pooling": "mean",
12
+ "cls_token_id": 50281,
13
+ "decoder_bias": true,
14
+ "deterministic_flash_attn": false,
15
+ "dtype": "float32",
16
+ "embedding_dropout": 0.0,
17
+ "eos_token_id": 50282,
18
+ "global_attn_every_n_layers": 3,
19
+ "gradient_checkpointing": false,
20
+ "hidden_activation": "gelu",
21
+ "hidden_size": 768,
22
+ "initializer_cutoff_factor": 2.0,
23
+ "initializer_range": 0.02,
24
+ "intermediate_size": 1152,
25
+ "layer_norm_eps": 1e-05,
26
+ "layer_types": [
27
+ "full_attention",
28
+ "sliding_attention",
29
+ "sliding_attention",
30
+ "full_attention",
31
+ "sliding_attention",
32
+ "sliding_attention",
33
+ "full_attention",
34
+ "sliding_attention",
35
+ "sliding_attention",
36
+ "full_attention",
37
+ "sliding_attention",
38
+ "sliding_attention",
39
+ "full_attention",
40
+ "sliding_attention",
41
+ "sliding_attention",
42
+ "full_attention",
43
+ "sliding_attention",
44
+ "sliding_attention",
45
+ "full_attention",
46
+ "sliding_attention",
47
+ "sliding_attention",
48
+ "full_attention"
49
+ ],
50
+ "local_attention": 128,
51
+ "max_position_embeddings": 8192,
52
+ "mlp_bias": false,
53
+ "mlp_dropout": 0.0,
54
+ "model_type": "modernbert",
55
+ "norm_bias": false,
56
+ "norm_eps": 1e-05,
57
+ "num_attention_heads": 12,
58
+ "num_hidden_layers": 22,
59
+ "pad_token_id": 50283,
60
+ "position_embedding_type": "absolute",
61
+ "rope_parameters": {
62
+ "full_attention": {
63
+ "rope_theta": 160000.0,
64
+ "rope_type": "default"
65
+ },
66
+ "sliding_attention": {
67
+ "rope_theta": 10000.0,
68
+ "rope_type": "default"
69
+ }
70
+ },
71
+ "sep_token_id": 50282,
72
+ "sparse_pred_ignore_index": -100,
73
+ "sparse_prediction": false,
74
+ "tie_word_embeddings": true,
75
+ "transformers_version": "5.17.0",
76
+ "vocab_size": 50368
77
+ }
encoder/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e6fe3bedd74500a32f74257a264d65b9787e0fc84fa93cd48e6f8730699d0d19
3
+ size 596070136
encoder/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
encoder/tokenizer_config.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "clean_up_tokenization_spaces": true,
4
+ "cls_token": "[CLS]",
5
+ "is_local": true,
6
+ "local_files_only": false,
7
+ "mask_token": "[MASK]",
8
+ "model_input_names": [
9
+ "input_ids",
10
+ "attention_mask"
11
+ ],
12
+ "model_max_length": 8192,
13
+ "pad_token": "[PAD]",
14
+ "sep_token": "[SEP]",
15
+ "tokenizer_class": "TokenizersBackend",
16
+ "unk_token": "[UNK]"
17
+ }
heads.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cb92553c26b875e6675c06eca4ee6e467374cb20c2d8cd49687f8e7398e17075
3
+ size 4747396
meta.json ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backbone": "answerdotai/ModernBERT-base",
3
+ "temperature": {
4
+ "one": 1.2999999999999998,
5
+ "any": 1.109569472067845,
6
+ "span": 1.0717734625362931
7
+ },
8
+ "calibration_task_accuracy": {
9
+ "calib/benayas/snips": 0.87,
10
+ "calib/crowdflower/airline-sentiment": 0.735,
11
+ "calib/emo/emo2019": 0.445,
12
+ "calib/health_fact": 0.115,
13
+ "calib/insincere-questions": 0.93,
14
+ "calib/lex_glue/ledgar": 0.3875,
15
+ "calib/logical-fallacy": 0.2,
16
+ "calib/rotten_tomatoes": 0.905,
17
+ "calib/scicite": 0.76,
18
+ "calib/silicone/dyda_e": 0.7725,
19
+ "calib/subjectivity": 0.6989,
20
+ "calib/tuetschek/atis": 0.7725
21
+ },
22
+ "temperature_k_slope": 0.0,
23
+ "val_accuracy": {
24
+ "20ng": 0.8208,
25
+ "anli": 0.8773,
26
+ "bitext": 0.984,
27
+ "boolq": 0.796,
28
+ "civil": 0.9351,
29
+ "clinc": 0.9509,
30
+ "counterfactual": 0.988,
31
+ "csqa": 0.74,
32
+ "customer_reviews": 0.944,
33
+ "davidson": 0.936,
34
+ "dbpedia": 0.996,
35
+ "emotion": 0.9361,
36
+ "enron_spam": 0.992,
37
+ "fever_nli": 0.896,
38
+ "fewnerd": 0.896,
39
+ "gandalf": 0.987,
40
+ "go_emotions": 0.9568,
41
+ "jailbreak": 0.9903,
42
+ "massive_intent": 0.872,
43
+ "massive_scenario": 0.94,
44
+ "mnli": 0.868,
45
+ "multi_claims": 0.9086,
46
+ "multi_entities": 0.8863,
47
+ "multi_mix_bitext": 0.987,
48
+ "multi_mix_clinc": 0.9679,
49
+ "multi_mix_emotion": 0.9167,
50
+ "multi_mix_yahoo": 0.8529,
51
+ "paws": 0.976,
52
+ "prompt_injection_mix": 0.992,
53
+ "race": 0.832,
54
+ "safeguard": 1.0,
55
+ "scales_toxicity": 0.58,
56
+ "scales_yelp": 0.736,
57
+ "snli": 0.88,
58
+ "spml": 0.996,
59
+ "squad_v2": 0.748,
60
+ "sst2": 0.908,
61
+ "stsb": 0.544,
62
+ "synthetic_fields": 1.0,
63
+ "toxic_chat": 0.96,
64
+ "trec": 0.944,
65
+ "ts/CONDAQA": 0.0,
66
+ "ts/CREAK": 1.0,
67
+ "ts/EffectiveFeedbackStudentWriting": 0.5,
68
+ "ts/I2D2": 1.0,
69
+ "ts/PARARULE-Plus": 1.0,
70
+ "ts/Touche23-ValueEval": 1.0,
71
+ "ts/VUAC": 1.0,
72
+ "ts/ade_corpus_v2/Ade_corpus_v2_classification": 1.0,
73
+ "ts/args_me": 1.0,
74
+ "ts/avicenna": 0.6667,
75
+ "ts/blog_authorship_corpus/job": 1.0,
76
+ "ts/boolq-natural-perturbations": 1.0,
77
+ "ts/circa": 1.0,
78
+ "ts/citation_intent": 1.0,
79
+ "ts/clcd-english": 1.0,
80
+ "ts/commonsense_qa_2.0": 1.0,
81
+ "ts/crowdflower/corporate-messaging": 1.0,
82
+ "ts/crowdflower/economic-news": 1.0,
83
+ "ts/crowdflower/political-media-audience": 0.6667,
84
+ "ts/crowdflower/political-media-bias": 1.0,
85
+ "ts/crowdflower/political-media-message": 0.5,
86
+ "ts/crowdflower/text_emotion": 0.6667,
87
+ "ts/crowdflower/tweet_global_warming": 1.0,
88
+ "ts/cycic_classification": 0.5,
89
+ "ts/defeasible-nli/atomic": 1.0,
90
+ "ts/defeasible-nli/snli": 1.0,
91
+ "ts/dynahate": 1.0,
92
+ "ts/dynasent/dynabench.dynasent.r1.all/r1": 1.0,
93
+ "ts/dynasent/dynabench.dynasent.r2.all/r2": 0.5,
94
+ "ts/ethics/deontology": 1.0,
95
+ "ts/ethics/justice": 0.3333,
96
+ "ts/ethics/virtue": 1.0,
97
+ "ts/ethos/binary": 0.5,
98
+ "ts/fever-evidence-related/mwong--fever-related": 1.0,
99
+ "ts/glue/cola": 0.5,
100
+ "ts/glue/qqp": 1.0,
101
+ "ts/hate_speech18": 1.0,
102
+ "ts/hlgd": 1.0,
103
+ "ts/hope_edi/english": 0.8333,
104
+ "ts/humicroedit/subtask-2": 0.3333,
105
+ "ts/implicit-hate-stg1": 1.0,
106
+ "ts/language-identification": 1.0,
107
+ "ts/lex_glue/scotus": 0.4,
108
+ "ts/mbib-base/cognitive-bias": 0.6667,
109
+ "ts/mbib-base/fake-news": 0.0,
110
+ "ts/mbib-base/hate-speech": 0.5,
111
+ "ts/mbib-base/linguistic-bias": 1.0,
112
+ "ts/mbib-base/political-bias": 0.6667,
113
+ "ts/mbib-base/racial-bias": 1.0,
114
+ "ts/mbib-base/text-level-bias": 0.75,
115
+ "ts/mc_taco": 1.0,
116
+ "ts/medical_questions_pairs": 1.0,
117
+ "ts/natural-language-satisfiability": 0.0,
118
+ "ts/numer_sense": 0.5,
119
+ "ts/open_question_type": 1.0,
120
+ "ts/parade": 0.25,
121
+ "ts/phrase_similarity": 0.6667,
122
+ "ts/pragmeval/emergent": 0.0,
123
+ "ts/pragmeval/gum": 1.0,
124
+ "ts/pragmeval/mrda": 0.3333,
125
+ "ts/pragmeval/pdtb": 0.3333,
126
+ "ts/pragmeval/sarcasm": 1.0,
127
+ "ts/pragmeval/stac": 0.5,
128
+ "ts/pragmeval/verifiability": 1.0,
129
+ "ts/probability_words_nli/reasoning_1hop": 0.75,
130
+ "ts/probability_words_nli/reasoning_2hop": 1.0,
131
+ "ts/probability_words_nli/usnli": 0.4,
132
+ "ts/quarel": 0.6,
133
+ "ts/robust_nli_li_ts": 1.0,
134
+ "ts/rumoureval_2019/RumourEval2019": 1.0,
135
+ "ts/sciie": 1.0,
136
+ "ts/scruples": 0.6,
137
+ "ts/sem_eval_2010_task_8": 1.0,
138
+ "ts/silicone/dyda_da": 1.0,
139
+ "ts/silicone/maptask": 1.0,
140
+ "ts/silicone/meld_e": 0.6667,
141
+ "ts/silicone/meld_s": 0.6667,
142
+ "ts/silicone/oasis": 0.6,
143
+ "ts/silicone/sem": 0.75,
144
+ "ts/spartqa-yn": 0.6667,
145
+ "ts/starcon": 0.5,
146
+ "ts/strategy-qa": 1.0,
147
+ "ts/super_glue/multirc": 0.4,
148
+ "ts/super_glue/wic": 0.5,
149
+ "ts/tweet_eval/emotion": 1.0,
150
+ "ts/tweet_eval/stance_feminist": 1.0,
151
+ "ts/tweet_eval/stance_hillary": 1.0,
152
+ "ts/tweets_hate_speech_detection": 0.6667,
153
+ "ts/twentyquestions": 1.0,
154
+ "ts/vitaminc/tals--vitaminc": 1.0,
155
+ "ts/wiki_qa": 1.0,
156
+ "ts/winowhy": 1.0,
157
+ "tweet_hate": 0.868,
158
+ "tweet_irony": 0.62,
159
+ "tweet_offensive": 0.852,
160
+ "tweet_sentiment": 0.732,
161
+ "tweet_sentiment2": 0.792,
162
+ "web_spam": 0.996,
163
+ "yahoo": 0.8035,
164
+ "yelp_sent": 0.8053,
165
+ "yelp_stars": 0.6204
166
+ },
167
+ "source": "https://github.com/Pdbz199/local-decision-model"
168
+ }