Upload folder using huggingface_hub
Browse files- README.md +101 -0
- config.json +15 -0
- model.safetensors +3 -0
- needle_sting_final.pkl +3 -0
- tokenizer_spec.json +0 -0
README.md
CHANGED
|
@@ -1,3 +1,104 @@
|
|
| 1 |
---
|
| 2 |
license: mit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
+
base_model: Cactus-Compute/needle
|
| 4 |
+
library_name: jax
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
tags:
|
| 7 |
+
- function-calling
|
| 8 |
+
- tool-use
|
| 9 |
+
- termux
|
| 10 |
+
- android
|
| 11 |
+
- on-device
|
| 12 |
+
- candle
|
| 13 |
+
- rust
|
| 14 |
+
- needle
|
| 15 |
+
language:
|
| 16 |
+
- en
|
| 17 |
+
- ar
|
| 18 |
---
|
| 19 |
+
|
| 20 |
+
# needle-termux-sting 🪡
|
| 21 |
+
|
| 22 |
+
[Needle](https://huggingface.co/Cactus-Compute/needle) (26M-parameter
|
| 23 |
+
"Simple Attention Network" for single-shot function calling, by
|
| 24 |
+
cactus-compute) **finetuned on the Termux:API command set** — the model behind
|
| 25 |
+
[sting](https://github.com/abod707/sting), a pure-Rust CLI that gives Termux
|
| 26 |
+
natural-language device control, fully offline.
|
| 27 |
+
|
| 28 |
+
```
|
| 29 |
+
"vibrate for 2 seconds"
|
| 30 |
+
→ [{"name":"termux_vibrate","arguments":{"duration_ms":2000}}]
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
## What's different from base needle
|
| 34 |
+
|
| 35 |
+
1. **Finetuned decoder** — 4,810 synthetic examples over 16 Termux:API tools +
|
| 36 |
+
14 generic tools (single-call, multi-call, missing-argument, and no-tool
|
| 37 |
+
cases; EN + some Arabic values). Recipe and data generator:
|
| 38 |
+
[sting/finetune](https://github.com/abod707/sting/tree/main/finetune).
|
| 39 |
+
2. **Working retrieval head** — the released base checkpoint ships its
|
| 40 |
+
contrastive (retrieval) head as **all zeros**, and zero weights + ReLU is a
|
| 41 |
+
gradient fixed point, so ordinary finetuning can never revive it. This
|
| 42 |
+
checkpoint's head was re-initialized and then trained on frozen encoder
|
| 43 |
+
features (softmax-over-tools). Retrieval over the 16-tool Termux pack:
|
| 44 |
+
**hit@3 = 99.2%, hit@6 = 100%** (400 queries).
|
| 45 |
+
|
| 46 |
+
## Eval (held-out test set, 300 examples, 30 tools)
|
| 47 |
+
|
| 48 |
+
| metric | base needle | this model |
|
| 49 |
+
|---|---|---|
|
| 50 |
+
| call_f1 (name+args exact) | 75.0% | **99.7%** |
|
| 51 |
+
| name_f1 | 94.6% | **100.0%** |
|
| 52 |
+
| exact_match | 72.7% | **99.7%** |
|
| 53 |
+
| args_acc | 79.2% | **99.7%** |
|
| 54 |
+
| parse_rate | 99.3% | **100.0%** |
|
| 55 |
+
|
| 56 |
+
Held-out but same-distribution synthetic data — treat as an upper bound for
|
| 57 |
+
wild phrasing. Methodology + per-tool tables:
|
| 58 |
+
[sting/EVAL.md](https://github.com/abod707/sting/blob/main/EVAL.md).
|
| 59 |
+
|
| 60 |
+
## Files
|
| 61 |
+
|
| 62 |
+
| file | format | use with |
|
| 63 |
+
|---|---|---|
|
| 64 |
+
| `needle_sting_final.pkl` | needle checkpoint (JAX/Flax, f16) | the official [needle](https://github.com/cactus-compute/needle) pipeline: `needle run --checkpoint needle_sting_final.pkl --query "..." --tools '[...]'` |
|
| 65 |
+
| `model.safetensors` + `config.json` + `tokenizer_spec.json` | f16 safetensors + JSON specs | [sting](https://github.com/abod707/sting)'s pure-Rust candle runtime |
|
| 66 |
+
|
| 67 |
+
## Usage (Python / needle)
|
| 68 |
+
|
| 69 |
+
```python
|
| 70 |
+
from needle import SimpleAttentionNetwork, load_checkpoint, generate, get_tokenizer
|
| 71 |
+
|
| 72 |
+
params, config = load_checkpoint("needle_sting_final.pkl")
|
| 73 |
+
model = SimpleAttentionNetwork(config)
|
| 74 |
+
result = generate(
|
| 75 |
+
model, params, get_tokenizer(),
|
| 76 |
+
query="read the gyroscope, 5 readings",
|
| 77 |
+
tools='[{"name":"termux_sensor","description":"Read values from a hardware sensor on the device.","parameters":{"sensor":{"type":"string","description":"Sensor name: accelerometer, gyroscope, light, proximity, pressure, magnetic_field or gravity.","required":true},"limit":{"type":"integer","description":"Number of readings to take.","required":false}}}]',
|
| 78 |
+
stream=False,
|
| 79 |
+
)
|
| 80 |
+
# [{"name":"termux_sensor","arguments":{"sensor":"gyroscope","limit":5}}]
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
## Usage (Termux / sting)
|
| 84 |
+
|
| 85 |
+
```bash
|
| 86 |
+
pkg install rust git binutils termux-api
|
| 87 |
+
git clone https://github.com/abod707/sting
|
| 88 |
+
cd sting && ./scripts/termux-install.sh
|
| 89 |
+
sting "turn on the flashlight"
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
## Scope & limitations
|
| 93 |
+
|
| 94 |
+
Single-shot function calling over a provided toolset. Not conversational, no
|
| 95 |
+
multi-step planning; underspecified requests ("set an alarm" with no time)
|
| 96 |
+
correctly return `[]`. Custom tools work zero-shot via the generic schemas it
|
| 97 |
+
saw in training; for production use of your own tools, finetune with ~120
|
| 98 |
+
examples per tool (recipe in the sting repo).
|
| 99 |
+
|
| 100 |
+
## Credits
|
| 101 |
+
|
| 102 |
+
Base model, architecture, and training pipeline:
|
| 103 |
+
[cactus-compute/needle](https://github.com/cactus-compute/needle) (MIT).
|
| 104 |
+
Finetune, retrieval-head fix, and Rust runtime: [abod707](https://github.com/abod707) (MIT).
|
config.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"vocab_size": 8192,
|
| 3 |
+
"d_model": 512,
|
| 4 |
+
"num_heads": 8,
|
| 5 |
+
"num_kv_heads": 4,
|
| 6 |
+
"num_encoder_layers": 12,
|
| 7 |
+
"num_decoder_layers": 8,
|
| 8 |
+
"rope_theta": 10000.0,
|
| 9 |
+
"max_seq_len": 1024,
|
| 10 |
+
"pad_token_id": 0,
|
| 11 |
+
"eos_token_id": 1,
|
| 12 |
+
"bos_token_id": 2,
|
| 13 |
+
"tool_call_token_id": 4,
|
| 14 |
+
"tools_token_id": 5
|
| 15 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:36443d27a663f2839e6f53c9b19bfa0b06c2e158d1c30819a4f6b6b87f887f24
|
| 3 |
+
size 52655224
|
needle_sting_final.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c78e0077d72351d8aedaabe1abd75759d7f3f04818664f2dcac6c14cad1e368a
|
| 3 |
+
size 52633104
|
tokenizer_spec.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|