File size: 2,243 Bytes
ace238f
 
 
 
b257502
ace238f
 
 
 
 
 
 
 
b257502
ace238f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: mit
language: en
library_name: transformers
pipeline_tag: translation
base_model: google/t5-efficient-tiny
tags:
- cron
- scheduling
- t5
- transformers.js
- onnx
- cronlm
- text2text-generation
---

# cronlm

Tiny natural-language to cron model. Pluggable into [@huggingface/transformers](https://github.com/huggingface/transformers.js).

- Base: `google/t5-efficient-tiny` (~16M params)
- Shipped: INT8 ONNX (encoder + decoder + decoder-with-past), ~36 MB total
- Accuracy: **99.2%** on 4 000 fresh synthetic samples · **97.3%** on a hand-crafted adversarial set
- Validity: **100%** of outputs are parseable 5-field cron
- Latency: ~3 ms / item on a laptop CPU

## Usage

### Browser / Node — transformers.js

```js
import { pipeline } from "@huggingface/transformers";
const cron = await pipeline("text2text-generation", "pavstev/cronlm");
const out = await cron("every weekday at 9am".toLowerCase());
console.log(out[0].generated_text); // "0 9 * * 1-5"
```

Lowercase the input before passing — bumps accuracy on Title-Case inputs by ~2.5 pp.

### Python — transformers

```py
from transformers import pipeline
cron = pipeline("text2text-generation", model="pavstev/cronlm")
print(cron("every weekday at 9am")[0]["generated_text"])  # "0 9 * * 1-5"
```

## Examples

| Input | Output |
| --- | --- |
| every 5 minutes | `*/5 * * * *` |
| every weekday at 9am | `0 9 * * 1-5` |
| at 10:30 PM on Sundays | `30 22 * * 0` |
| every 15 minutes between 9 and 17 | `*/15 9-17 * * *` |
| every Mon and Wed at noon | `0 12 * * 1,3` |
| on the 1st of every month | `0 0 1 * *` |
| every quarter | `0 0 1 1,4,7,10 *` |
| at midnight | `0 0 * * *` |
| `@daily` | `0 0 * * *` |
| MWF at 9am | `0 9 * * 1,3,5` |
| every December 25 | `0 0 25 12 *` |
| from the 1st to the 5th at noon | `0 12 1-5 * *` |
| every 30 minutes during business hours | `*/30 9-17 * * 1-5` |

## Validation

A pure-Python validator/fixer is included in the [`cronlm`](https://github.com/pavstev/cronlm) package — wrap model output to catch any rare invalid generation:

```py
from cronlm import fix
fix("0 25 * * 1")  # "0 23 * * 1"
```

## Training

Source, dataset generator, and training scripts: <https://github.com/pavstev/cronlm>

## License

MIT