AI 与机器学习2025arxiv.org
基于类型约束的语言模型代码生成
Type-constrained code generation with language models
进阶 · 约 45 分钟读完前置知识:编程语言类型系统、LLM 约束解码、语法引导生成
导读
这篇论文研究如何用类型约束来引导语言模型生成代码:在生成过程中引入类型系统的约束(很可能基于约束解码/语法引导生成),让模型输出在类型层面合法的代码,以减少类型错误。论文的核心主张是把目前常见的 JSON schema 约束扩展到编程语言的类型结构上。
HN 关注点:HN 读者把它看作“约束解码从 JSON 扩展到完整语言语法/类型系统”的必然一步,讨论焦点是嵌套语言识别与回溯等尚未解决的难题。
HN 评论精选
这几条评论里:补充 4
补充约束解码扩展到语言语法是必然趋势,难点在于嵌套语言切换和回溯。
这是显而易见的下一步。现有产品最多只能把 token 预测限制在合法 JSON 或特定 JSON schema 内,没有理由约束输出模式只支持这一种语法。真正的挑战是让它自动识别并切换语言——比如代码片段里注释中的 LaTeX 公式、字符串字面量里的 SQL,还有 shell 脚本里的正则等等。再下一步显然是回溯:模型可能生成了一个合法 token,但之后再也无法生成任何合法续写,也就是把自己逼进死角。据我所知目前没有任何在线 LLM 服务做回溯,都是只追加的前向模式。
jiggawatts查看英文原文
This was an obvious next step. Most current products can only restrict the token prediction to valid JSON or a specific JSON schema at best. There's no reason that this should be the only grammar available for constrained output mode. The real challenge will be to make this detect and switch languages automatically. For example, a snippet of code could include a LaTeX formula in a comment and SQL in a string literal. There are many more examples, such as regex inside a shell script, and so on. The obvious next step after that is back-tracking. It's possible to emit a token that is valid, but then allows no further completions that are valid. In other words, the model can paint itself into a corner. To my knowledge, no current online LLM service uses any kind of backtracking, they run in append ("forwards") mode only.
补充小实验室可专攻单一编程语言做出最强模型,数据稀缺的小语种反而是机会。
如果我是小型 AI 实验室,我会这么干:不去造一个全面超越所有基准的前沿 LLM,而是做世界上最好的、专精某一门编程语言的 LLM,把全部资源投入针对该语言的 RL 流水线。如果 GitHub 上该语言的人类训练数据还很稀缺就更好了,因为所有竞争对手都会很弱。Google 在最新的 Gemini-2.5 Pro 里对 JavaScript 多少做了类似的事,但小语种呢?Google 不会去做,可需求仍然很大。
energy123查看英文原文
This is what I'd consider doing if I was a small AI lab. Don't try to build a frontier LLM that beats all benchmarks. Try to make the world's best LLM at one programming language. Create your RL pipeline that puts all your resources into making the LLM the best at that language. Even better if there's a dearth of human-created training data on Github, since all your competitors will be bad at it. Google somewhat did this with javascript in their latest Gemini-2.5 Pro release. But what about doing it for a smaller language? Google isn't going to do that, but there is still a lot of demand.
补充TypeScript 的数据量加类型系统使其成为最适合 LLM 的语言。
我认为 TypeScript 处于独特的位置,是最适合 LLM 的语言:海量训练数据(还能沾所有 JS 示例的光),加上可供 LLM 遵循的类型结构,以及能强制执行类型的工具链。
ArcaneMoose查看英文原文
I think TypeScript is uniquely positioned to be the optimal language for LLMs. Tons of training data (benefiting from all the JS examples as well) plus the structure of types for LLMs to follow and tools to enforce.
补充库文档应针对 LLM 消费优化,直接粘贴即可使用。
如果各个库能把文档整理成便于复制粘贴进 LLM 的形式来托管,靠“vibe coding”写代码的群体受益会大得多。
koakuma-chan查看英文原文
The vibe code society would benefit way more if libraries hosted their docs in a way that's easy to copy and paste into an LLM.
相关资源
从这篇论文所有 HN 讨论帖的全部评论里整理出来的链接。
历次讨论
- 2025Hacker News 讨论帖257 分 · 127 评
同领域还值得读
DeepSeek-R1:通过强化学习激励 LLM 的推理能力
DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via RL
研究如何用强化学习激励大语言模型的推理能力,提出 DeepSeek-R1,并探讨 RL 训练对模型推理表现的影响。
AI 与机器学习2025 · 1,351 分 · 1,056 评 · 引用 30进阶 · 约 80 分钟编辑精选1-bit LLM 时代:面向低成本计算的三值参数
The Era of 1-bit LLMs: ternary parameters for cost-effective computing
提出用三值参数 {-1, 0, 1} 替代 LLM 中的浮点权重,即所谓“1-bit LLM”。
AI 与机器学习2024 · 1,040 分 · 447 评 · 引用 19进阶 · 约 45 分钟编辑精选DeepSeek-V3.2:推进开放大语言模型的前沿
DeepSeek-v3.2: Pushing the frontier of open large language models
这是 DeepSeek-V3.2 的技术报告,延续了 DeepSeek 开源权重模型的路线,目标是让开放模型继续逼近甚至追平前沿闭源模型。
AI 与机器学习2025 · 982 分 · 465 评进阶 · 约 90 分钟编辑精选通过自我对弈与通用强化学习掌握国际象棋和将棋(AlphaZero)
Mastering Chess and Shogi by Self-Play with General Reinforcement Learning
DeepMind 的 AlphaZero 论文:用通用强化学习算法(自我博弈 + MCTS + 神经网络),从零开始仅数小时训练便在国际象棋和将棋上击败了世界顶级引擎 Stock…
AI 与机器学习2017 · 539 分 · 270 评 · 引用 13进阶 · 约 90 分钟编辑精选用强化学习发现更快的矩阵乘法算法
Discovering faster matrix multiplication algorithms with reinforcement learning
论文提出 AlphaTensor,用强化学习搜索矩阵乘法算法。
AI 与机器学习2022 · 518 分 · 111 评专业 · 约 90 分钟编辑精选