Gemma-4-E4B-it LaTeX copy-editor (v4)
A local model for always-on language feedback while writing LaTeX: inline grammar, spelling, punctuation and word-usage suggestions for scientific paragraphs, like a writing assistant's inline suggestions but running entirely on your machine (Ollama, ~0.8 s per paragraph on an M1 Pro).
It answers with an edit list, not a rewrite. The edits are applied to your own text, so math, \cite, \ref and
\label outside the edited words cannot be damaged:
user: In this paper we proposes a new method for sparse regression, which leverage a convex relaxation ...
assistant: proposes => propose
leverage => leverages
or NO_ERRORS. Each line quotes a few words of the paragraph exactly (original => corrected).
Files
| File | What |
|---|---|
gemma-4-E4B-it-latex-copyedit-v4.Q4_K_M.gguf | merged model, Q4_K_M (5.3 GB), text only |
Modelfile | Ollama model with the exact training chat format and system prompt, greedy decoding |
adapter/ | the QLoRA adapter (PEFT, for unsloth/gemma-4-E4B-it-unsloth-bnb-4bit) + tokenizer / chat template |
vscode-extension/latex-copyedit-0.4.1.vsix | VS Code extension that shows the suggestions as diagnostics + quick fixes |
eval/ | evaluation reports, confidence sweep and training summary |
Use
hf download michelinolinolino/gemma-4-E4B-it-latex-copyedit --local-dir latex-copyedit
cd latex-copyedit && ollama create latex-copyedit -f Modelfile
code --install-extension vscode-extension/latex-copyedit-0.4.1.vsix # optional: VS Code integration
Send the paragraph as the only user message (/api/chat, "think": false); the Modelfile supplies the system prompt
the model was trained with: Copy-edit this LaTeX paragraph: one correction per line as `original words => corrected words`, or NO_ERRORS. Raw prompt format (Gemma 4): <bos><|turn>system\n{prompt}<turn|>\n<|turn>user\n{paragraph}<turn|>\n<|turn>model\n,
stop at <turn|>.
Apply the edits with guards (as the VS Code extension and the evaluation do): drop an edit whose quoted words are
not found exactly once in the paragraph, that would change math / \cite / \ref / \label, delete more than 8
words, add punctuation right after a display formula, or insert a word that is already next to it.
Confidence: with Ollama's logprobs, score each line by its least likely token and hide lines below 0.4
(the extension's default). Lower it (0.3) for more fixes and more false alarms.
Evaluation
AESW gold edits are one editor's choices and are incomplete, so the precision numbers are pessimistic: many suggestions counted as wrong are valid corrections the editor did not make. False edits = share of already-correct paragraphs that receive any suggestion.
Q4_K_M GGUF in Ollama on an M1 Pro, held-out test split of copyedit v4 (1,874 paragraphs + 12 hand-written), with the guards above:
| confidence filter | edit P / R / F0.5 | false edits on correct text | suggestions per correct paragraph | damaged | hand-written checks |
|---|---|---|---|---|---|
| none | 0.40 / 0.26 / 0.359 | 26% | 0.55 | 0% | 18/29 |
| ≥ 0.3 | 0.46 / 0.21 / 0.372 | 22% | 0.36 | 0% | 18/29 |
| ≥ 0.4 (default) | 0.53 / 0.15 / 0.355 | 16% | 0.21 | 0% | 16/29 |
| ≥ 0.5 | 0.58 / 0.11 / 0.308 | 9% | 0.12 | 0% | 15/29 |
The threshold was chosen on the validation split (eval/threshold_sweep_validation.md). Latency (sequential, one
paragraph per request): median 0.84 s, p90 1.8 s, p99 3.2 s.
Against the prompted base model (4-bit, Kaggle T4, same 380 test paragraphs, no confidence filter):
| model | edit P / R / F0.5 | false edits on correct text | suggestions per correct paragraph | malformed answers |
|---|---|---|---|---|
| Gemma-4-E4B-it (prompted with full instructions) | 0.18 / 0.21 / 0.182 | 73% | 2.42 | 6% |
| this model | 0.42 / 0.29 / 0.386 | 23% | 0.47 | 0% |
It replaces the earlier Gemma-4-E2B v3 model (same test split, its best filter 0.25: 0.44 / 0.13 / 0.301, false edits 19%, 0.46 suggestions per correct paragraph): ΔF0.5 at 0.4 vs that model +0.054 [95% CI +0.030, +0.076].
Training
QLoRA (r 32, α 32, dropout 0) on the attention and MLP projections of the language model of
unsloth/gemma-4-E4B-it-unsloth-bnb-4bit (vision/audio untouched), loss on the answer only, short system prompt (25
tokens), 1 epoch over the 82,889 training rows of copyedit v4 (dataset revision copyedit-v4): batch 4 × 2
accumulation × 2 GPUs (DDP), lr 2e-4 cosine, 60 warm-up steps, AdamW 8-bit, max 1,024 tokens; Unsloth 2026.10.11,
Transformers 5.16.1, two Kaggle T4s, 5,181 steps in 7.8 h (Gemma 4 runs in float32 on T4s). Train loss 0.55. Merged
and quantised to Q4_K_M with Unsloth / llama.cpp.
Limitations
- English scientific prose (AESW: physics, mathematics, engineering, CS, 2006–2013 journal articles); house style of
one copy-editing company (e.g. serial commas,
e.g.,, hyphenated compounds). - Moderate recall: at the default filter it leaves many paragraphs the editors changed untouched (58%). It catches clear errors (agreement, articles, typos, confusables) much better than optional style edits.
- Not a rewriting / paraphrasing model, and it does not check math or citations.
Licence and attribution
The training data is CC-BY-NC-SA-4.0, so this model is released under CC-BY-NC-SA-4.0 (non-commercial, share-alike); the base model (Gemma 4) is Apache-2.0. The AESW data set carries additional restrictions that also apply here: no direct or indirect data engineering or mining aimed at detecting the personal identity of the authors of the texts, and no derivative data that facilitates it.
- AESW — Vidas Daudaravicius (2016). Automated Evaluation of Scientific Writing Data Set (Version 1.2). VTeX. http://textmining.lt/aesw/
- EarlySciRev — https://huggingface.co/datasets/taln-ls2n/EarlySciRev; proof-pile-2 — https://huggingface.co/datasets/EleutherAI/proof-pile-2