luffy19 commited on
Commit
ffd7a98
·
verified ·
1 Parent(s): a78361f

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +137 -0
README.md ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Agri-SLM — inference
2
+
3
+ A 134M-parameter Qwen3-style decoder trained from scratch on Indian agriculture
4
+ text (11.8B tokens, 3 epochs). Two variants differing only in tokenizer.
5
+
6
+ `agri_slm.py` is self-contained: it needs `torch` and `tokenizers` only, and has
7
+ no dependency on the training code. It is verified bit-for-bit identical to the
8
+ training implementation.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ pip install torch tokenizers
14
+ pip install huggingface_hub # only if loading from the Hub
15
+ ```
16
+
17
+ ## Run
18
+
19
+ ```bash
20
+ # download and generate
21
+ python agri_slm.py --prompt "Rice blast disease is caused by"
22
+
23
+ # interactive, streaming
24
+ python agri_slm.py --interactive
25
+
26
+ # local files
27
+ python agri_slm.py --ckpt final.pt --tokenizer tokenizer_final.json --interactive
28
+ ```
29
+
30
+ As a library:
31
+
32
+ ```python
33
+ from agri_slm import AgriSLM
34
+
35
+ slm = AgriSLM.from_pretrained("luffy19/custom_tokenizer")
36
+ print(slm.generate("Integrated pest management in cotton involves"))
37
+
38
+ # or from local files
39
+ slm = AgriSLM.from_files("final.pt", "tokenizer_final.json")
40
+ ```
41
+
42
+ ## Decoding — read this before reporting results
43
+
44
+ **This model loops badly under greedy decoding.** That is a property of greedy
45
+ search on small base models, not a defect in the weights: `argmax` has no way out
46
+ of a high-probability cycle. A repetition penalty fixes it completely.
47
+
48
+ Measured over 300-token generations on 4 prompts:
49
+
50
+ | setting | repeat-4gram | longest verbatim loop | distinct-2 | sentences well-formed |
51
+ |---|---|---|---|---|
52
+ | greedy, no penalty | 0.636 | **37 tokens** | 0.285 | 91% |
53
+ | greedy + rep 1.2 | 0.023 | 0 | 0.884 | 84% |
54
+ | greedy + rep 1.2 + no-repeat-4gram | 0.000 | 0 | 0.939 | 78% |
55
+ | T 0.7 | 0.173 | 0 | 0.633 | 89% |
56
+ | T 0.7 + rep 1.15 | 0.011 | 0.8 | 0.919 | 80% |
57
+ | T 0.9 + rep 1.15 + ng4 | 0.000 | 0 | 0.902 | 85% |
58
+ | **T 1.0 + rep 1.1** | **0.006** | **0** | **0.910** | **87%** |
59
+
60
+ A repetition penalty alone takes greedy from a 37-token loop to essentially zero
61
+ repetition — a 27x reduction.
62
+
63
+ ### Presets
64
+
65
+ ```bash
66
+ python agri_slm.py --preset balanced # T=1.0 top_p=0.95 rep=1.10 (default)
67
+ python agri_slm.py --preset safe # T=0.9 top_p=0.95 rep=1.15 ngram=4 (zero loops)
68
+ python agri_slm.py --preset focused # T=0.7 top_p=0.90 rep=1.15 (deterministic-ish)
69
+ python agri_slm.py --preset greedy # T=0 rep=1.20 ngram=3 (reproducible)
70
+ python agri_slm.py --preset raw-greedy # no penalty — demonstrates the loop
71
+ ```
72
+
73
+ Any preset value can be overridden: `--temperature`, `--top-k`, `--top-p`,
74
+ `--repetition-penalty`, `--no-repeat-ngram`.
75
+
76
+ **`balanced` is the recommended default.** Use `safe` when you need a hard
77
+ guarantee of no repetition; it costs a little naturalness. `raw-greedy` exists
78
+ only to reproduce the failure.
79
+
80
+ ## Models
81
+
82
+ | repo | tokenizer | notes |
83
+ |---|---|---|
84
+ | `luffy19/custom_tokenizer` | hybrid 40k (KG + AGROVOC entity injection) | `hybrid40k/final.pt` |
85
+ | `luffy19/agri-slm_qwen40k` | Qwen BPE pruned 151k→40k | `qwen40k/final.pt` |
86
+
87
+ Both: 133,476,480 params, 40,000 vocab, 20 layers, 640-dim, GQA (10 heads /
88
+ 5 KV groups), SwiGLU, RMSNorm, RoPE base 1e6, rank-256 factorized embedding tied
89
+ to the output head.
90
+
91
+ ### Measured differences
92
+
93
+ On 2,000 identical held-out documents (3.72M characters):
94
+
95
+ | metric | Qwen 40k | Hybrid 40k | delta |
96
+ |---|---|---|---|
97
+ | bits per character | 0.9208 | **0.9168** | **−0.43%** |
98
+ | fertility (tok/1k chars) | 229.16 | **212.76** | **−7.16%** |
99
+ | tokens for same text | 853,383 | **792,312** | **−7.16%** |
100
+ | agriculture probe | 14/15 | **15/15** | +1 |
101
+ | perplexity | 16.20 | 19.82 | *not comparable* |
102
+
103
+ **Do not compare the two models by perplexity.** It is per-token, and the hybrid's
104
+ tokens each carry ~7% more text, so it is predicting harder units. Bits-per-char
105
+ normalises this and reverses the apparent ordering. The 7.16% fertility gain is
106
+ the large, robust effect; the 0.43% BPC difference is small and comes from single
107
+ runs with one seed, so treat it as directional rather than significant.
108
+
109
+ ## What this model is and is not
110
+
111
+ It is a **base language model**: it continues text. It is not instruction-tuned
112
+ and does not answer questions. Prompt it with sentence openings a textbook would
113
+ contain ("Rice blast disease is caused by"), not questions ("What causes rice
114
+ blast?").
115
+
116
+ Known limitations, all measured:
117
+
118
+ - **Confidently wrong on some facts.** It defined Minimum Support Price as "a
119
+ measure of the quality of a product", which is incorrect. Domain-term recall is
120
+ strong (14–15 of 15 probes) but definitions can be wrong.
121
+ - **Invents citations.** ~11% of the training corpus is citation-dense academic
122
+ text, so it produces plausible-looking references like "(Khan et al., 2015)"
123
+ that may not exist.
124
+ - **Drifts into thesis format.** ~13% of the corpus is dissertation text, so long
125
+ generations can wander into "REVIEW OF LITERATURE / Chapter II".
126
+ - **Reproduces a PDF extraction artifact.** ~1% of training documents contain
127
+ doubled letters from bad PDF extraction ("RREEVVIIEEWW"); the model occasionally
128
+ emits this.
129
+ - **No KV cache.** Generation recomputes the full sequence each step, so cost
130
+ grows with length. Fine to a few hundred tokens; slow beyond that.
131
+
132
+ Do not use its output as agricultural advice without verification.
133
+
134
+ ## Performance
135
+
136
+ ~25 tokens/sec on an H200 at ~1 GB in bf16. Runs on CPU (fp32) at a few tokens
137
+ per second.