Text Classification
Transformers
ONNX
Safetensors
English
distilbert
trading
intent-classification
lora
english
text-embeddings-inference
Instructions to use DoDataThings/distilbert-trade-decision-classifier-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use DoDataThings/distilbert-trade-decision-classifier-v1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="DoDataThings/distilbert-trade-decision-classifier-v1")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("DoDataThings/distilbert-trade-decision-classifier-v1") model = AutoModelForSequenceClassification.from_pretrained("DoDataThings/distilbert-trade-decision-classifier-v1") - Notebooks
- Google Colab
- Kaggle
v1.0.0 — initial release
Browse files- .gitattributes +1 -0
- README.md +177 -0
- config.json +43 -0
- model.onnx +3 -0
- model.onnx.data +3 -0
- model.safetensors +3 -0
- tokenizer.json +0 -0
- tokenizer_config.json +15 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
model.onnx.data filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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classification
|
| 10 |
+
- distilbert
|
| 11 |
+
- lora
|
| 12 |
+
- onnx
|
| 13 |
+
- english
|
| 14 |
+
pipeline_tag: text-classification
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# distilbert-trade-decision-classifier-v1
|
| 18 |
+
|
| 19 |
+
DistilBERT fine-tuned with LoRA r=32 for classifying user replies to trading-agent proposals into one of six decision intents. Pairs with a regex fast-path and a confirmation prompt for the bookends of a reply-routing pipeline.
|
| 20 |
+
|
| 21 |
+
## How it works
|
| 22 |
+
|
| 23 |
+
Trading agents that DM proposals ("Approve / decline / hold / size N / trim N?") get free-form text replies back. This model converts the reply into one of six discrete intents so the agent can route it deterministically.
|
| 24 |
+
|
| 25 |
+
The model is invoked AFTER a fast-path regex tries the canonical phrases first ("approve", "decline", "size 10"). The regex handles routine replies; the model handles everything the regex doesn't match.
|
| 26 |
+
|
| 27 |
+
```
|
| 28 |
+
Reply text in
|
| 29 |
+
↓
|
| 30 |
+
Canonical-phrase regex ← catches structured replies cheaply
|
| 31 |
+
↓ (no match)
|
| 32 |
+
THIS MODEL ← classifies into 6 intent labels
|
| 33 |
+
↓
|
| 34 |
+
Decision rule:
|
| 35 |
+
• confidence ≥ 0.85 AND label ≠ UNCLEAR → commit
|
| 36 |
+
• else → confirmation prompt to the user
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
## Labels (6)
|
| 40 |
+
|
| 41 |
+
| Label | What it covers |
|
| 42 |
+
| -------------- | ----------------------------------------------------------------------- |
|
| 43 |
+
| APPROVE | Execute the proposal as stated. "approve", "yes", "let's go", "send it" |
|
| 44 |
+
| DECLINE | Kill the proposal. "no", "pass", "kill it", "hard pass" |
|
| 45 |
+
| HOLD | Active deferral — user is engaged but not deciding yet. "hold off", "checking", "let me think", "leaning approve" |
|
| 46 |
+
| COUNTER_SIZE | Execute but at a different share count. "size 10", "dump half", "trim 50" |
|
| 47 |
+
| COUNTER_PRICE | Execute but at a different limit price. "at $49", "limit 50", "trim at $48" |
|
| 48 |
+
| UNCLEAR | Cannot safely commit. Multi-intent, ambiguous, off-topic, or sarcastic. Falls through to confirmation prompt. |
|
| 49 |
+
|
| 50 |
+
UNCLEAR is a trained refusal label, not a fallback. The model is expected to emit it on multi-intent, ambiguous, or off-topic inputs. Treat it as the model saying "I don't know, ask the human."
|
| 51 |
+
|
| 52 |
+
## Inputs
|
| 53 |
+
|
| 54 |
+
A single string with structural context tags prepended:
|
| 55 |
+
|
| 56 |
+
```
|
| 57 |
+
[dm|group][reply_to:N|no_reply_to][in_flight:K] <reply text>
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
- `[dm]` vs `[group]` — chat surface (DM vs group chat)
|
| 61 |
+
- `[reply_to:N]` vs `[no_reply_to]` — whether the user quote-replied to a specific proposal
|
| 62 |
+
- `[in_flight:K]` — number of proposals currently awaiting decision
|
| 63 |
+
|
| 64 |
+
Example inputs:
|
| 65 |
+
```
|
| 66 |
+
[dm][reply_to:200][in_flight:1] approve
|
| 67 |
+
[dm][no_reply_to][in_flight:1] dump half
|
| 68 |
+
[dm][reply_to:200][in_flight:2] trim at $49
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
The tags carry context the model can't infer from the text alone — "yes" with 1 proposal in flight is APPROVE; "yes" with 3 in flight and no quote-reply is structurally ambiguous and trained as UNCLEAR.
|
| 72 |
+
|
| 73 |
+
## Usage
|
| 74 |
+
|
| 75 |
+
### Python (transformers)
|
| 76 |
+
|
| 77 |
+
```python
|
| 78 |
+
from transformers import pipeline
|
| 79 |
+
|
| 80 |
+
clf = pipeline(
|
| 81 |
+
"text-classification",
|
| 82 |
+
model="DoDataThings/distilbert-trade-decision-classifier-v1",
|
| 83 |
+
)
|
| 84 |
+
result = clf("[dm][reply_to:200][in_flight:1] dump half")
|
| 85 |
+
print(result)
|
| 86 |
+
# [{'label': 'COUNTER_SIZE', 'score': 0.991}]
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
### Python (onnxruntime, CPU)
|
| 90 |
+
|
| 91 |
+
```python
|
| 92 |
+
import onnxruntime as ort
|
| 93 |
+
import numpy as np
|
| 94 |
+
from transformers import AutoTokenizer
|
| 95 |
+
|
| 96 |
+
tok = AutoTokenizer.from_pretrained("DoDataThings/distilbert-trade-decision-classifier-v1")
|
| 97 |
+
sess = ort.InferenceSession("model.onnx", providers=["CPUExecutionProvider"])
|
| 98 |
+
|
| 99 |
+
text = "[dm][no_reply_to][in_flight:1] hold off"
|
| 100 |
+
enc = tok(text, truncation=True, max_length=64, return_tensors="np")
|
| 101 |
+
logits = sess.run(
|
| 102 |
+
None,
|
| 103 |
+
{"input_ids": enc["input_ids"], "attention_mask": enc["attention_mask"]},
|
| 104 |
+
)[0][0]
|
| 105 |
+
probs = np.exp(logits) / np.exp(logits).sum()
|
| 106 |
+
labels = ["APPROVE", "DECLINE", "HOLD", "COUNTER_SIZE", "COUNTER_PRICE", "UNCLEAR"]
|
| 107 |
+
print(labels[int(probs.argmax())], float(probs.max()))
|
| 108 |
+
# HOLD 0.943
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
## Deployment shape
|
| 112 |
+
|
| 113 |
+
The model is not safe to use standalone. Pair with:
|
| 114 |
+
|
| 115 |
+
- A confidence threshold (we recommend 0.85)
|
| 116 |
+
- Deterministic safety rails (position size, available cash, mode gate)
|
| 117 |
+
- A confirmation prompt for low-confidence cases
|
| 118 |
+
|
| 119 |
+
The model picks intent; the system decides whether to act. It does not have final authority over orders.
|
| 120 |
+
|
| 121 |
+
## Design decisions
|
| 122 |
+
|
| 123 |
+
**Narrow-waist split.** The model classifies INTENT only, not proposal context. By design, upstream code disambiguates which proposal the reply targets (via quote-reply or single-default rule), and the model only sees the locked-in case. This makes the model independent of ticker / setup / portfolio specifics — its job is interpreting "what did the user mean," not "which one."
|
| 124 |
+
|
| 125 |
+
**UNCLEAR as a trained refusal class.** A 5-label classifier forced to pick one of {APPROVE, DECLINE, HOLD, COUNTER_SIZE} on ambiguous input is dangerous. The 6th label is the model's escape valve — it's trained on multi-intent, ambiguous, off-topic, and sarcastic inputs so it can refuse rather than guess. Combined with the 0.85 confidence threshold, this caps the blast radius of misclassification: an unsafe input either yields UNCLEAR (refusal) or a non-UNCLEAR label with low confidence (falls through to confirmation prompt).
|
| 126 |
+
|
| 127 |
+
**Structural prefix as text, not special tokens.** The `[dm][reply_to:N][in_flight:K]` tags are concatenated into the input string and tokenized as regular subword pieces. This works with off-the-shelf DistilBERT — no special-token registration, no tokenizer config drift between train and serve. The model learns the bracket conventions naturally via attention.
|
| 128 |
+
|
| 129 |
+
**Six labels including COUNTER_PRICE.** Earlier versions used five labels. The sixth (COUNTER_PRICE) was added because "trim at $49 instead of $48" is a fundamentally different action from "size 10" — different downstream extraction (price vs share count). Conflating them would force the consumer to disambiguate post-classification, defeating the purpose of the intent label.
|
| 130 |
+
|
| 131 |
+
## Evaluation
|
| 132 |
+
|
| 133 |
+
Held-out eval set: 175 hand-curated adversarial examples, ~30 per class, zero-leakage verified against training.
|
| 134 |
+
|
| 135 |
+
| Label | Precision | Recall | F1 | Count |
|
| 136 |
+
| -------------- | --------- | ------ | ----- | ----- |
|
| 137 |
+
| APPROVE | 0.967 | 0.967 | 0.967 | 30 |
|
| 138 |
+
| DECLINE | 1.000 | 0.933 | 0.966 | 30 |
|
| 139 |
+
| HOLD | 0.970 | 0.941 | 0.955 | 34 |
|
| 140 |
+
| COUNTER_SIZE | 0.968 | 1.000 | 0.984 | 30 |
|
| 141 |
+
| COUNTER_PRICE | 1.000 | 1.000 | 1.000 | 25 |
|
| 142 |
+
| UNCLEAR | 0.821 | 0.885 | 0.852 | 26 |
|
| 143 |
+
| **macro avg** | | | **0.954** | 175 |
|
| 144 |
+
| **accuracy** | | | **0.954** | |
|
| 145 |
+
|
| 146 |
+
**Honest assessment.** Zero high-confidence misclassifications on eval (no row labeled wrong at confidence ≥ 0.85). DECLINE and COUNTER_PRICE both hit perfect precision (1.000). UNCLEAR is the weakest class at F1 0.85, and the HOLD/UNCLEAR boundary on multi-intent inputs ("approve but only half") is genuinely fuzzy — these cases can be reasonably labeled either way. The 0.85 confidence threshold is calibrated so weak cases fall to confirmation rather than commit wrong.
|
| 147 |
+
|
| 148 |
+
## Training
|
| 149 |
+
|
| 150 |
+
| Knob | Value |
|
| 151 |
+
| ------------------ | ------------------------------------------- |
|
| 152 |
+
| Base model | distilbert-base-uncased |
|
| 153 |
+
| Adapter | LoRA r=32 on attention projections (q_lin, v_lin) |
|
| 154 |
+
| Sequence length | 64 |
|
| 155 |
+
| Batch size | 32 |
|
| 156 |
+
| Learning rate | 5e-5, cosine schedule, 10% warmup |
|
| 157 |
+
| Epochs | 3, early-stop on eval macro-F1 |
|
| 158 |
+
| Class weighting | inverse-frequency (functionally uniform — data is balanced within 2%) |
|
| 159 |
+
| Hardware | Single RTX 4090 |
|
| 160 |
+
| Wall time | ~9 seconds |
|
| 161 |
+
|
| 162 |
+
## Limitations
|
| 163 |
+
|
| 164 |
+
1. Classifies INTENT only, not proposal context. The model never sees the actual proposal being responded to — upstream proposal-disambiguation must run before this model is invoked.
|
| 165 |
+
2. COUNTER_SIZE emits intent only; share count extraction is a separate downstream step (regex).
|
| 166 |
+
3. COUNTER_PRICE emits intent only; price extraction is a separate downstream step.
|
| 167 |
+
4. Trained on author-curated and synthetically-augmented data. Real-world reply variety may exceed training surface forms; expect ~5% of replies to fall to confirmation-prompt fallback.
|
| 168 |
+
5. UNCLEAR has the lowest F1 (0.85). The boundary with HOLD (active deferral vs no-position) is fuzzy on multi-intent inputs.
|
| 169 |
+
6. English-only. No localization in v1.
|
| 170 |
+
|
| 171 |
+
## Dataset
|
| 172 |
+
|
| 173 |
+
Training and evaluation data: [DoDataThings/trade-decision-classifier-v1-dataset](https://huggingface.co/datasets/DoDataThings/trade-decision-classifier-v1-dataset)
|
| 174 |
+
|
| 175 |
+
## License
|
| 176 |
+
|
| 177 |
+
Apache 2.0.
|
config.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"activation": "gelu",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"DistilBertForSequenceClassification"
|
| 5 |
+
],
|
| 6 |
+
"attention_dropout": 0.1,
|
| 7 |
+
"bos_token_id": null,
|
| 8 |
+
"dim": 768,
|
| 9 |
+
"dropout": 0.1,
|
| 10 |
+
"dtype": "float32",
|
| 11 |
+
"eos_token_id": null,
|
| 12 |
+
"hidden_dim": 3072,
|
| 13 |
+
"id2label": {
|
| 14 |
+
"0": "APPROVE",
|
| 15 |
+
"1": "DECLINE",
|
| 16 |
+
"2": "HOLD",
|
| 17 |
+
"3": "COUNTER_SIZE",
|
| 18 |
+
"4": "COUNTER_PRICE",
|
| 19 |
+
"5": "UNCLEAR"
|
| 20 |
+
},
|
| 21 |
+
"initializer_range": 0.02,
|
| 22 |
+
"label2id": {
|
| 23 |
+
"APPROVE": 0,
|
| 24 |
+
"COUNTER_PRICE": 4,
|
| 25 |
+
"COUNTER_SIZE": 3,
|
| 26 |
+
"DECLINE": 1,
|
| 27 |
+
"HOLD": 2,
|
| 28 |
+
"UNCLEAR": 5
|
| 29 |
+
},
|
| 30 |
+
"max_position_embeddings": 512,
|
| 31 |
+
"model_type": "distilbert",
|
| 32 |
+
"n_heads": 12,
|
| 33 |
+
"n_layers": 6,
|
| 34 |
+
"pad_token_id": 0,
|
| 35 |
+
"qa_dropout": 0.1,
|
| 36 |
+
"seq_classif_dropout": 0.2,
|
| 37 |
+
"sinusoidal_pos_embds": false,
|
| 38 |
+
"tie_weights_": true,
|
| 39 |
+
"tie_word_embeddings": true,
|
| 40 |
+
"transformers_version": "5.10.1",
|
| 41 |
+
"use_cache": false,
|
| 42 |
+
"vocab_size": 30522
|
| 43 |
+
}
|
model.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7dfcb59f278c90ba702a929e57158720637042abe4637ab0afe17003961f5f5b
|
| 3 |
+
size 59094
|
model.onnx.data
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7c5687685a328d03a014d6b4d91b3b2e4dd9a91f858131ec4c01bf5832ba22c8
|
| 3 |
+
size 267892736
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d216ce4c33e614f6734cf92f394bffb79fe3cee467d64225204f7409830326ac
|
| 3 |
+
size 267844872
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"cls_token": "[CLS]",
|
| 4 |
+
"do_lower_case": true,
|
| 5 |
+
"is_local": false,
|
| 6 |
+
"local_files_only": false,
|
| 7 |
+
"mask_token": "[MASK]",
|
| 8 |
+
"model_max_length": 512,
|
| 9 |
+
"pad_token": "[PAD]",
|
| 10 |
+
"sep_token": "[SEP]",
|
| 11 |
+
"strip_accents": null,
|
| 12 |
+
"tokenize_chinese_chars": true,
|
| 13 |
+
"tokenizer_class": "BertTokenizer",
|
| 14 |
+
"unk_token": "[UNK]"
|
| 15 |
+
}
|