blog: on-device LLM × novel DSL — Grammar Prompting at 1.5B (ja + en) - #8
Draft
piroz wants to merge 17 commits into
Draft
blog: on-device LLM × novel DSL — Grammar Prompting at 1.5B (ja + en)#8piroz wants to merge 17 commits into
piroz wants to merge 17 commits into
Conversation
…–§4) First-pass long-form article targeting HN / r/LocalLLaMA, kept on its own docs/blog-grammar-prompting branch so main stays free of in-progress prose. ~1,220 words covering: - Hook with the multi-model ablation table (Qwen 85%, Gemma 75%, Llama 0%) - 2026 framing — native structured-output APIs cover JSON Schema but not CFG; on-device small models need the layer noroshi sits in - A recap of Wang et al.'s Grammar Prompting and the four pieces that make it work, with a worked prompt anatomy - The noroshi-creative DSL (the bench target) shown in full - The five-cell ablation ladder + reproduction one-liner §5 (per-row commentary, centerpiece) onward is flagged with TODO markers and will land in follow-up commits on this branch. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The centrepiece section of the article. One paragraph per ablation row, plus a closing paragraph diagnosing why the Llama-3.2-1B row is exactly 0% across every column — the model emits the literal token "start" as the first token of every completion, anchored on the grammar's leading rule name, and neither retry nor best-of-N can dislodge it. Running total ~1,690 words. §6 (code walk-through) next.
Completes the first-pass draft of the article (~2,680 words total). - §7 names four boundaries: Llama-row unsolved, latency cost, grammar guarantee is soft, single-domain bench - §8 ships two minimal code snippets (StubAdapter, FetchAdapter + GrammarAwareRanker) plus repo / example / license links - §9 closes on the ablation-curve-survives-100x-shrink framing, on-device-era context, and a low-key CTA for follow-up benches Draft-status callout updated to reflect first-pass-complete state. Pre-publish editing pass (hook tightening, lead image, byline, etc.) still pending.
- Hook §0: replace 52-word setup with "0% vs 85%" cold open. Two short contrast sentences before the table; ~30 words. Optimised for the HN front-page scan where the first line decides scroll-vs-leave. - assets/lead-image.svg: three-pane diagram (TASK | VALIDATED DSL | p5 CANVAS) at 800×280, monospaced, syntax-tinted DSL, three pink dots rendered on the right pane. Self-contained SVG (no embedded bitmaps) so it sits naturally inside the repo. - Embedded above the §0 heading so it shows up as the article's social-card / OG image when cross-posted.
Full Japanese version of the article — same nine sections, same lead image (the SVG is language-agnostic), same code blocks unchanged. Style choices for the JP translation: - だ・である調 base, softened in §0 hook and §9 closing for readability - Technical terms left in English where standard in JP technical writing (Grammar Prompting / few-shot / ablation / best-of-N / DSL / on-device) - Validator error strings and CLI snippets unchanged from the EN version so the reader can grep through the repo without translating back Target venues: Zenn (primary), note (secondary cross-post). Plan is to publish 1-2 weeks after the English version goes up, with reciprocal cross-links.
- 「0% と 85%。」 → 「0%。85%。」 (英語版 cold open `0% vs 85%` の機械的等価) - 「HTTP コールの向こう側にいる」 → 「OpenAI 互換 API の向こうで動いている」 - 「具体的で示唆に富む形」 → 「具体的で学びの多い形」 - 「すべてのセルを 1 行ずつ」 → 「カラムを 1 つずつ、ステップバイステップで」 すべて修辞磨きで意味変更なし、英語版は据え置き。
- 「同時に立ち上がっています」 → 「同時に重なり始めています」 - 「構造化出力を吐けるようになってきた」 → 「構造化出力を提供するようになってきた」 - 「Claude には … が来ている」 → 「Claude にも … が追加された」 - 「彼らの手法は」 → 「Grammar Prompting は」 (人称代名詞を避けて主語明示) - 「(2023 年時点ではそういう構図で語られていなかったとはいえ)」 → 「(2023 年当時は、そういう枠組みでは語られていなかったが)」 すべて修辞磨きで意味変更なし、英語版は据え置き。
- 「論文の主張を 1 行で言えば:」 → 「論文の主張を要約すれば:」 (実は 1 行で収まっていないため) - 「4 つの可動部品で動いています」 → 「4 つの構成要素で動いています」 (機械比喩を抜く) - 「derivation 先行の few-shot 例」 → 「derivation 付きの few-shot 例」 (直訳→自然訳) - 「構造化された "考える手順"」 → 「構造化された思考プロセス」 - 「その失敗をどう活かすかが次の話です。」 → 「…が、後続のセクションのテーマです。」 すべて修辞磨きで意味変更なし、英語版は据え置き。
- 「ほぼ見ていないであろう」 → 「見ていないと思われる」 (古典口調を抜く) - 「文法全体が 20 行で収まります:」 → 「文法全体は 20 行で書けます:」 - 「モデルにはこんな出力をしてほしい:」 → 「モデルに期待する出力はこんな形:」 - 「これが bench の DSL 軸です。Task 軸は …」 → 「ここまでが bench の DSL 側の話。Task 側は …」 (axis 直訳→「側」) - 「プロンプトに乗っている 4 つの few-shot 例」 → 「プロンプトに含まれる 4 つの few-shot 例」 すべて修辞磨きで意味変更なし、英語版は据え置き。
ja-only (修辞磨き): - 「5 セル。各セルは…」 → 「5 つの ablation セル。それぞれが…」 - 「+ 4 つの derivation 先行例」 → 「+ 4 つの derivation 付き few-shot 例」 (§2 と整合) - 「カウントされる、ということ。」 → 「…ちゃんと pass としてカウントされる。」 - 「ローカル Ollama 上の 3 モデル」 → 「ローカル Ollama で動かす 3 モデル」 ja + en (意味整合): - §4 末 / §5 タイトルの "row by row" → "column by column"。§5 本文を再読すると ablation (= 列) を 1 つずつ読み解く構成 (Llama 行の診断は最後の段落のみ) なので、 英語版の "row by row" は不正確だった。日本語側も §3 で「カラムを 1 つずつ」と 揃えたので、両方を column 表記に統一する。
- 「Python 片」 → 「Python の断片」 (baseline) - 「ケースが少数。」 → 「ケースが少数だけ起きる。」 (+grammar、体言止めをほどく) - 「derivation 先行の例」 → 「derivation 付きの例」 (+few-shot、§2/§4 と統一) - 「DSL の表面を教える主役です。」 → 「DSL の表面を教える決め手です。」 (+few-shot、擬人化を抑える) - 「retry が直せないやつ」 → 「retry で直らないケース」 (+rerank、口語抜き) - 「(b) なければパースが最も深く進んだ失敗 を選ぶ」 → スペーシング修正 (+rerank) - 「diversity を買ってくれる」 → 「diversity を稼ぎやすい」 (+rerank、英語直訳「buys」をほどく) すべて修辞磨きで意味変更なし、英語版は据え置き。
- イントロ「画面 1 つに収まる量です」 → 「画面 1 つに収まるサイズです」 - 6.1 タイトル「derivation 先行 few-shot」 → 「derivation 付き few-shot」 (§2/§4/§5 と統一) - 6.1 「chat メッセージのスキャフォールディング」 → 「chat メッセージの足場づくり」 - 6.3 「3 つのピース」 → 「3 つの部品」 (§6 イントロと統一) - 6.3 「短いハルシネーションのほうがマシ」 → 「短い hallucination のほうが害が小さい」 すべて修辞磨きで意味変更なし、英語版は据え置き。
- 「明示的に名前を付けておきたい境界」 → 「明示的に挙げておきたい限界」 - 「フォローアップ記事ネタとしてあり得る open question。」 → 「フォローアップ記事のネタになりそうな open question です。」(体言止めを抜く) - 「壁時計時間」 → 「実時間」 - 「正解、届く環境では不正解」 → 「正しい選択、届く環境ではそうではない」 - 「別の経験的問題です」 → 「別の経験的に検証すべき問題です」 すべて修辞磨きで意味変更なし、英語版は据え置き。
…a + en) ja-only (修辞磨き): - §8 「形だけ見るため:」 → 「形を確認するため:」 - §8 「実ループ。」 → 「実 LLM 向けループ。」 - §8 「リポ:」 → 「リポジトリ:」 - §9 「derivation 先行 few-shot」 → 「derivation 付き few-shot」 (§2/§4/§5/§6 と統一) - §9 「技術自体は一般的です。」 → 「技術自体は普遍的です。」 ja + en (数値整合): - §9 末「§6 の 4 ピース」 / `the four pieces in §6` → 「§6 の 3 つの部品」 / `the three pieces in §6` §6 は subsection が 3 個 (buildPrompt / retry / GrammarAwareRanker) で、§6 自体が冒頭・末尾とも "Three pieces" と書いている。§9 末で "four pieces in §6" と書いていたのは数値の誤り。 (§9 前半の 4 要素列挙 (BNF プロンプト / derivation 付き few-shot / retry / best-of-N) は機能単位で別カウント。)
- ja: 「Llama の行はこの表で最も興味深いセルで、」 → 「この表で最も興味深いのは Llama の行で、」 - en: 「The Llama row is the most interesting cell of the table」 → 「The most interesting row in the table is Llama's」 英語版にも同じ "row vs cell" の不整合があったので両方を「row」に揃える。 意味は完全に同じ、表現の整合修正のみ。
… en) - §2: 誤引用 "Wang, Hu, Saparov, Kim, and Wang" → "Wang et al." (実在しない Hu/Saparov を除去、本文他箇所の表記に統一) - §3 (en): "Twenty-token grammar" → "Twenty-line grammar" (文法は 20 行。日本語版は既に "20 行の文法" で正しかった) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the long-form blog post on running Wang et al.'s Grammar Prompting on 1–3B on-device LLMs, backed by the frozen
noroshi-creativebenchmark (Qwen2.5-1.5B 85% / Gemma-2-2B 75% / Llama-3.2-1B 0%).Contents
docs/blog/2026-05-on-device-grammar-prompting.md— English, ~2,680 words (§0–§9)docs/blog/2026-05-on-device-grammar-prompting.ja.md— Japanese translationdocs/blog/assets/lead-image.svg— lead image (task → DSL → canvas)Review fixes already in this branch
Wang, Hu, Saparov, Kim, and Wang→Wang et al.Verified against arXiv:2305.19234; actual authors are Bailin Wang, Zi Wang, Xuezhi Wang, Yuan Cao, Rif A. Saurous, Yoon Kim (Hu/Saparov were not authors).Twenty-token grammar→Twenty-line grammar(the ja version was already correct).Still pending before publish (from the in-post draft note)
Kept as draft until the pre-publish editing pass lands.
🤖 Generated with Claude Code