首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Karpathy 教他的 nanochat 数单词里有几个“r”

Karpathy 教他的 nanochat 数单词里有几个“r”

作者头像
用户11563501
发布2026-06-23 10:21:47
发布2026-06-23 10:21:47
780
举报

Andrej Karpathy 刚刚分享了一件挺有意思的事:教他的超小型语言模型 nanochat d32 数单词里有几个字母 r。

这听起来简单,但对一个"大脑只有蜜蜂大小"的模型来说,难度不小。要知道,连 ChatGPT 这样的大模型都经常在这种任务上翻车。

Karpathy 的解决方案很实用:创建一个叫 SpellingBee 的合成任务(代码见文末),生成大量用户询问字母计数的例子,然后用这些数据对模型进行微调。

Screenshot displays a conversation where a user asks the model to find the number of r in strawberry using a manual approach. The model responds by standardizing the word in quotes spelling it out letter by letter and iterating with an explicit counter: starting at 0 incrementing for each r found reaching 3. Includes Python code snippet for verification using a function to count occurrences.
Screenshot displays a conversation where a user asks the model to find the number of r in strawberry using a manual approach. The model responds by standardizing the word in quotes spelling it out letter by letter and iterating with an explicit counter: starting at 0 incrementing for each r found reaching 3. Includes Python code snippet for verification using a function to count occurrences.

关键在于细节。对小模型来说,你得把任务拆得很细:先把单词标准化加引号,然后逐字母拼出来(避免分词问题),最后用显式计数器一个个数过去。还得教模型用两种方法解决:手工计算和调用 Python 解释器验证。

这种做法有点像填鸭式教学。如果模型够大,这种能力可能会自然涌现。但对于参数量极小的 nanochat,你只能通过在数据中过度表示这类任务,强迫它早点学会。

有人质疑这是不是过拟合。Karpathy 在回复中提到,目前所有解决方案都是"干净的",没有错误示例。理想情况下,应该加入一些错误和恢复的例子,或者用强化学习让它更鲁棒。

图像
图像

不过,有用户测试发现,这个功能在多轮对话中不太稳定,Karpathy说需要清空对话历史重新开始才最可靠。这从侧面说明小模型的上下文处理能力还是有限的。

Karpathy 用这个例子现场示范了在资源受限的情况下,针对性的数据增强仍然是让小模型掌握特定能力的有效方法。虽然不够优雅,但确实管用。

代码见:https://github.com/karpathy/nanochat/blob/8892470f2975d80e6ef8c2f25d72d890beb50398/tasks/spellingbee.py

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2025-10-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 AI工程化 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档