File size: 7,050 Bytes
8262357
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3dee8e4
 
8262357
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
---
license: apache-2.0
language: en
library_name: transformers
pipeline_tag: text-generation
base_model: Qwen/Qwen2.5-Coder-1.5B-Instruct
datasets:
  - asterbraid/awkweave-data
  - asterbraid/awkweave-realistic-data
tags:
  - awk
  - code-generation
  - text-to-code
  - qwen
  - local
  - execution-verified
---

# Awkweave 1.5B

Awkweave translates an English text-processing request plus representative input into an `awk` program. It is a LoRA fine-tune of **Qwen2.5-Coder-1.5B-Instruct**, merged into ordinary Transformers weights for local, offline inference. No API key is needed for inference.

- Companion data: [asterbraid/awkweave-data](https://huggingface.co/datasets/asterbraid/awkweave-data) and [realistic expansion](https://huggingface.co/datasets/asterbraid/awkweave-realistic-data)
- Interactive demo: [asterbraid/awkweave-demo](https://huggingface.co/spaces/asterbraid/awkweave-demo)
- Output contract: one `awk` program only, without the `awk` executable, filename, Markdown, or explanation.

## Results

All scores are greedy, one generation per row. **Valid** means `awk` executes the prediction on the primary input. **Correct** requires exact output equality on both the primary and second input. Only trailing special tokens are stripped; Markdown is never repaired.

| Model | Test valid | Test correct | Dev valid | Dev correct | Frozen valid | Frozen correct |
| --- | ---: | ---: | ---: | ---: | ---: | ---: |
| Qwen2.5-Coder base | 0.0% (0/3000) | 0.0% (0/3000) | 0.0% (0/33) | 0.0% (0/33) | 0.0% (0/37) | 0.0% (0/37) |
| Awkweave stage 1 | 100.0% (3000/3000) | 100.0% (3000/3000) | 78.8% (26/33) | 15.2% (5/33) | 83.8% (31/37) | 18.9% (7/37) |
| **Awkweave final** | **100.0% (3000/3000)** | **100.0% (3000/3000)** | **97.0% (32/33)** | **78.8% (26/33)** | **94.6% (35/37)** | **29.7% (11/37)** |

The base model fenced every prediction in Markdown and usually emitted a shell command, so it was invalid under the strict bare-program contract.

Test contains 3000 grammar-generated rows from the original 39 families and measures in-distribution behavior only; input texts are disjoint, but request/program pairs can recur. Dev contains 33 authored tasks used to guide the realistic expansion, so it is development data, not an untouched test. Frozen contains 37 separately authored network-flow, inventory, syslog, group, sensor, and formatting tasks. It was excluded from all training and tuning. Full predictions and summaries are included under `evaluation/`.


## Verified generation

Request: `For each record, print column 1 and the running sum of column 2, separated by a space.`

```text
gus 24 indigo
jules 18 delta
farah 18 grove
alice 22 delta
farah 29 grove
dina 10 amber
jules 4 fable
farah 2 fable
```

Generated program:

```awk
{s+=$2;print $1,s}
```

Executed output:

```text
gus 24
jules 42
farah 60
alice 82
farah 111
dina 121
jules 125
farah 127
```


## Use with Transformers

```python
from awkweave.model import generate_program

program = generate_program(
    "Print each name and the running total of column 2.",
    "alice 10\nbruno 15\nchen 7\n",
    "asterbraid/awkweave-1.5b",
)
print(program)
```

Or use the lower-level API:

```python
from transformers import AutoModelForCausalLM, AutoTokenizer
from awkweave.prompts import messages

model_id = "asterbraid/awkweave-1.5b"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)
prompt = tokenizer.apply_chat_template(
    messages("Print the last field of every line.", "a 1\nb 2\n"),
    tokenize=False,
    add_generation_prompt=True,
)
inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False)
output = model.generate(**inputs, do_sample=False, max_new_tokens=192)
print(tokenizer.decode(output[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
```

## CLI

Clone this repository, install the package, and pipe representative input to the CLI. Python 3.10+ and an `awk` executable are required:

```bash
git clone https://huggingface.co/asterbraid/awkweave-1.5b
cd awkweave-1.5b
pip install -e '.[model]'
printf 'alice 10\nbruno 15\n' | awkweave 'Print the running sum of column 2'
```

Add `--run` to print the generated program to stderr and execute it with the included safety guard. The guard permits stdin/stdout processing only and rejects file, environment, subprocess, pipe, and redirection operations.

## GGUF

Quantized builds are included for llama.cpp-compatible runtimes:

- `awkweave-1.5b.Q4_K_M.gguf`
- `awkweave-1.5b.Q8_0.gguf`

```bash
llama-server -m awkweave-1.5b.Q8_0.gguf --host 127.0.0.1 --port 8080
```

For Ollama, run `ollama create awkweave -f Modelfile` from this repository, then see `OLLAMA.md` for the exact prompt format and an executable example.

The Q4_K_M build was also loaded in `llama-completion` and passed a real generation smoke check.


## Training

- Base: `Qwen/Qwen2.5-Coder-1.5B-Instruct` (Apache-2.0).
- Data: 60000 rows in the final training stage, including original and guarded-paraphrase requests.
- Stage 1: 107994 original rows for one epoch at learning rate 5e-05.
- Stage 2: 40,000 realistic rows plus 20,000 replay rows, continued from the stage-one merged model at learning rate 2e-05.
- Method: LoRA rank 32, alpha 64, dropout 0.05, targeting attention and MLP projections; adapter merged after training.
- Schedule: 1.0 epoch, cosine learning-rate decay, peak learning rate 2e-05, effective batch size 64, maximum sequence length 1024.
- Precision: BF16 with gradient checkpointing; non-fused AdamW and maximum gradient norm 0.5.
- `training_config.json` records the resolved settings and training metrics.

Every reference program in the dataset was executed on two inputs. Paraphrases changed request wording only, never the program, inputs, or expected outputs.

## Execution and safety

The model itself produces text and does not execute anything. The optional CLI and Space use `awkweave.execution.run_awk`, which supplies input on stdin and rejects file/environment access, `system()`, `getline`, pipes, and output redirection. CPU, memory, output-file, and wall-clock limits are also applied. Review generated programs before use. A syntactically valid program can still implement the wrong request.

## Limitations

- English only; not a general chatbot or general shell assistant.
- POSIX-style `awk` on supplied text. No multi-file joins, quoted CSV, or external pipelines.
- Requests must be explicit about field positions or header names, filtering, output formatting, and ordering.
- Complex compositions outside the training families can fail. The small challenge split does not establish broad reliability.
- The execution guard is a safety layer, not a proof of sandboxing against every possible `awk` implementation exploit. Use a container for untrusted production workloads.

## License and attribution

Code and merged weights are Apache-2.0, matching the base model. See `LICENSE` and `NOTICE`. Training data is CC-BY-4.0; attribute Asterbraid when redistributing it.