少样本视觉大模型数控G代码验证:基于 VLM 的 G 代码与 HMI 联合校验

机械设计制造及其自动化 × 智能制造 × AI 视觉 —— 数控 G 代码验证精读材料
📄 原文:arXiv:2512.11296 🗓️ 2025年12月12日发布 🏫 arXiv 预印本(cs.CV · cs.AI · cs.HC) ✅ 少样本提示 × 视觉语言模型 × G代码校验 🔊 附英文摘要朗读音频

一、论文档案

英文标题Few-Shot VLM-Based G-Code and HMI Verification in CNC Machining
中文标题数控加工中基于少样本视觉语言模型的 G 代码与人机界面(HMI)联合校验
作者Yasaman Hashem Pour, Nazanin Mahjourian, Vinh Nguyen
发布时间2025年12月12日(v1)|分类:cs.CV(计算机视觉)· cs.AI · cs.HC
原文链接arxiv.org/abs/2512.11296 · 全文 HTML 版
一句话概括让视觉语言模型(VLM)同时「看」G 代码文本和机床 HMI 屏幕截图,用少量示例(few-shot)引导,学会发现程序错误、代码残缺与机床状态不一致。
💡 为什么选这篇给你:① 数控加工是机械设计制造及其自动化的看家本领,G 代码校验是真实车间里的刚需痛点;② 思路直接——给大模型加上「眼睛」(视觉模态),把纯文本检查升级为「代码 + 屏幕」联合检查,核心思想用文字就能读懂;③ 少样本提示(few-shot prompting)+ JSON 结构化输出是当前多模态大模型落地工程任务的通用套路,读完这篇就能举一反三。

二、核心术语表(先扫一遍再读正文)

英文术语中文大白话解释
G-codeG 代码数控机床的底层编程语言,用字母+数字指令(如 G01 直线插补)控制刀具运动轨迹。
CNC machining数控加工Computer Numerical Control,计算机数值控制加工——由计算机按程序控制机床自动加工。
HMI (Human-Machine Interface)人机界面机床的操作显示屏,显示机器状态、报警、坐标等参数,是操作员「看机床」的窗口。
LLM (Large Language Model)大语言模型只处理文本的大模型,能读代码但「看不见」屏幕上的图像信息。
VLM (Vision-Language Model)视觉语言模型能同时理解图像与文本的多模态大模型,如 GPT-4.1,是本论文的主角。
few-shot prompting少样本提示在提示词里给模型几个「对/错示例」再让它干活,不需要重新训练。
zero-shot (ZS)零样本不给任何示例,直接让模型完成任务——论文里作为对比基线。
JSON schemaJSON 模式一种结构化数据描述,规定模型输出必须包含哪些字段,让回答「可解析、可对齐」。
per-slot accuracy逐槽位准确率把 HMI 面板拆成一个个信息槽位(如坐标、夹紧状态),分别统计每个槽位的判断正确率。
PathPilotPathPilot 控制系统本论文所用车床(Lathe 15-L Slant Pro)的操作系统界面。
discrepancy不一致 / 偏差G 代码写的内容与 HMI 显示的实际状态对不上,比如代码说换刀但界面没反应。
semantic alignment语义对齐模型生成的文字描述与参考答案在「意思」上的接近程度。
cosine similarity / match rate余弦相似度 / 匹配率衡量输出与参考答案接近程度的两个指标:向量方向相似度、逐项匹配比例。
collet clamped / Ref X / Ref Z夹头夹紧 / X·Z 轴参考点HMI 面板上的具体状态指示槽位:工件是否夹紧、各轴参考点是否就位。

三、摘要中英对照(精读核心)

🎧 音频在文末,可先听一遍原文再读;每个英文句都配了逐句翻译。

摘要 Abstract

EN · 原文
Manual generation of G-code is important for learning the operation of CNC machines.
CN · 翻译
手工编写 G 代码对于学习数控机床的操作很重要。
EN · 原文
Prior work in G-code verification uses Large-Language Models (LLMs), which primarily examine errors in the written programming.
CN · 翻译
以往的 G 代码校验工作使用大语言模型(LLM),主要检查编写程序中的错误。
EN · 原文
However, CNC machining requires extensive use and knowledge of the Human-Machine Interface (HMI), which displays machine status and errors.
CN · 翻译
然而,数控加工需要大量使用并掌握人机界面(HMI)——它显示机器状态与错误信息。
EN · 原文
LLMs currently lack the capability to leverage knowledge of HMIs due to their inability to access the vision modality.
CN · 翻译
LLM 目前缺乏利用 HMI 知识的能力,因为它们无法访问视觉模态。
EN · 原文
This paper proposes a few-shot VLM-based verification approach that simultaneously evaluates the G-code and the HMI display for errors and safety status.
CN · 翻译
本文提出一种基于少样本 VLM 的校验方法,同时评估 G 代码与 HMI 显示中的错误与安全状态。
EN · 原文
The input dataset includes paired G-code text and associated HMI screenshots from a 15-slant-PRO lathe, including both correct and error-prone cases.
CN · 翻译
输入数据集包含来自一台 15-slant-PRO 车床的「G 代码文本 + 对应 HMI 截图」配对数据,既含正确案例也含易错案例。
EN · 原文
To enable few-shot learning, the VLM is provided with a structured JSON schema based on prior heuristic knowledge.
CN · 翻译
为支持少样本学习,模型被赋予一个基于先验启发知识的结构化 JSON 模式
EN · 原文
After determining the prompts, instances of G-code and HMI that either contain errors or are error free are used as few-shot examples to guide the VLM.
CN · 翻译
确定提示词后,含错与无错的 G 代码和 HMI 实例被用作少样本示例来引导 VLM。
EN · 原文
The model was then evaluated in comparison to a zero-shot VLM through multiple scenarios of incorrect G-code and HMI errors with respect to per-slot accuracy.
CN · 翻译
随后,模型与零样本 VLM 对比评估:在多种「错误 G 代码 + HMI 错误」场景下比较逐槽位准确率
EN · 原文
The VLM showed that few-shot prompting led to overall enhancement of detecting HMI errors and discrepancies with the G-code for more comprehensive debugging.
CN · 翻译
实验表明,少样本提示整体提升了对 HMI 错误及与 G 代码不一致之处的检出能力,使调试更全面。
EN · 原文
Therefore, the proposed framework was demonstrated to be suitable for verification of manually generated G-code that is typically developed in CNC training.
CN · 翻译
因此,该框架被证明适用于数控培训中典型的手工 G 代码校验任务。

关键词 Keywords:G-code Verification G 代码校验 | Human-Machine Interface 人机界面 | Few-Shot Learning 少样本学习 | Vision-Language Model 视觉语言模型 | CNC Machining 数控加工

四、引言精选(为什么这个问题重要)

① G 代码为什么难写:底层语言 + 环境知识

EN · 原文
While learning to write G-code is essential for understanding CNC machining, it can also be complex, error-prone, and time-consuming [Kamran2021]. This is because G-code is a low-level language that also requires knowledge of the environment in which the code is hosted, such as the machine's characteristics, process conditions, and the human-machine interface (HMI) display.
CN · 翻译
学会写 G 代码虽然对理解数控加工必不可少,但它复杂、易错、耗时。因为 G 代码是底层语言,还需要了解代码所依托的环境——如机床特性、工艺条件和人机界面(HMI)显示

② 手工调试的脆弱性:变量太多,必须认真校验

EN · 原文
In practice, manual G-code debugging is vulnerable to extraneous variables, including human error, incorrect coordinate systems, and missing tool calls. This is because troubleshooting these errors demands spatial and technical reasoning [jignasu2023foundationalaimodelsadditive]. Therefore, careful verification of the G-code is key to avoiding costly errors and facilitating safe and precise operation. Intelligent verification systems can help analyze and detect potential G-code problems before machining begins [BADINI2023278, 11021219].
CN · 翻译
实践中,手工调试 G 代码容易受外部变量干扰:人为失误、坐标系错误、漏掉换刀指令等。排错需要空间与技术推理。因此,认真校验 G 代码是避免代价高昂的错误、保障安全与精密加工的关键——智能校验系统能在加工开始前就分析并发现潜在问题。

③ LLM 的局限:只能看文本,看不见机床屏幕

EN · 原文
However, despite their effectiveness in text-based reasoning, the implementation of LLMs in CNC machining faces significant limitations. Current LLM systems are mainly based on tokenized text and cannot process visual or sensory feedback that characterizes the machining environment [Jignasu2024, XuanLiu2025].
CN · 翻译
然而,尽管 LLM 在文本推理上有效,把它们用到数控加工中仍面临显著局限:现有 LLM 主要基于分词后的文本,无法处理表征加工环境的视觉或传感反馈
EN · 原文
Hence, LLMs are incapable of aligning G-code with actual machine behavior since they operate offline without interfacing with key monitoring devices, alarms, feedrates, and spindle activity [He2025]. Consequently, verification using LLMs is restricted to syntax correction and G-code optimization [XuanLiu2025].
CN · 翻译
因此,LLM 无法把 G 代码与真实机床行为对齐——它们离线运行,不接监控设备、报警、进给率和主轴活动。结果是:基于 LLM 的校验只能停留在语法修正与代码优化层面。

④ 本文思路:多模态框架,代码与屏幕一起查

EN · 原文
This study introduces a multimodal VLM-based framework that jointly examines G-code syntax alongside visual information extracted from HMI panels to detect discrepancies, incomplete code segments, and machine-state mismatches. A paired dataset was constructed from G-code programs and their corresponding HMI screenshots to enable the model to infer associations between program commands and virtual cues. Through this integration, the framework can detect both textual and visual inconsistencies that provide a more comprehensive basis for debugging and safety assurance during manual G-code development.
CN · 翻译
本文提出一个多模态 VLM 框架:联合检查 G 代码语法与从 HMI 面板提取的视觉信息,发现不一致、残缺代码段与机床状态失配。作者构建了「G 代码程序 + 对应 HMI 截图」的配对数据集,让模型学会关联程序指令与界面线索;通过这种集成,框架能同时检出文本与视觉上的不一致,为手工 G 代码开发期的调试与安全保障提供更全面的依据。
💡 这是全文最有味道的一句“However, no current study explicitly links G-code text with HMI data to verify machining G-code or the status indicators displayed on the HMI.”——现有研究没有一篇把「代码文本」和「屏幕状态」真正连起来校验,这就是本文要填的坑:先找到研究空白,再谈方法。

五、论文贡献(3 个要点)

EN · 原文
1. A joint G-code + HMI verification framework. This paper proposes a few-shot VLM-based verification approach that simultaneously evaluates the G-code and the HMI display for errors and safety status.
CN · 翻译
1. G 代码 + HMI 联合校验框架。提出基于少样本 VLM 的校验方法,同时评估 G 代码与 HMI 显示中的错误与安全状态——这是首次把两个模态放进同一个校验流程。
EN · 原文
2. Structured output via JSON schema. To enable few-shot learning, the VLM is provided with a structured JSON schema based on prior heuristic knowledge.
CN · 翻译
2. 用 JSON 模式约束结构化输出。基于先验启发知识设计结构化 JSON 模式提供给 VLM,让少样本学习变得可行、输出可解析。
EN · 原文
3. Few-shot beats zero-shot in debugging. The VLM showed that few-shot prompting led to overall enhancement of detecting HMI errors and discrepancies with the G-code for more comprehensive debugging.
CN · 翻译
3. 少样本提示优于零样本。实验证明少样本提示整体提升了 HMI 错误与 G 代码不一致的检出能力,调试更全面。

六、结论中英对照

EN · 原文
This study introduces a multimodal framework for the simultaneous verification of G-code and HMI states in CNC machining. The proposed approach addresses the current gap in LLM-based frameworks, which lack multimodal understanding to interpret visual indicators of machine state. This was achieved by integrating paired G-codes and HMI screenshots from the PathPilot Lathe 15-L Slant Pro as textual and visual inputs to a vision-language model (GPT-4.1). These data were organized into eight scenarios, each with two instances, and processed within a JSON schema to ensure interpretability.
CN · 翻译
本研究提出一个同时校验 G 代码与 HMI 状态的多模态框架,填补了现有 LLM 框架缺乏多模态理解、无法解读机床状态视觉指示的空白。做法是把来自 PathPilot Lathe 15-L Slant Pro 车床的配对「G 代码 + HMI 截图」作为文本与视觉输入交给视觉语言模型(GPT-4.1)。数据被组织成八个场景、每个场景两个实例,并在 JSON 模式内处理以保证可解释性。
EN · 原文
The framework was evaluated and tested under ZS and FS prompting conditions, with alternative views of the interface display, including full and clustered crops of the control panel. The findings emphasize that FS prompting led to overall enhancement of G-code and HMI compliance accuracy, whereas G-code validity remained consistent and stable beyond ZS Full configuration.
CN · 翻译
框架在零样本(ZS)与少样本(FS)两种提示条件下评估,并测试了界面显示的不同视图——控制面板的完整截图与局部裁剪图。结果强调:FS 提示整体提升了 G 代码与 HMI 的符合性准确率,而 G 代码有效性在 ZS Full 配置之外保持了一致稳定。
EN · 原文
Additionally, the state indicator slots, Ref X, achieved the highest accuracy under FS +Clust for 0.938, while Ref Z performed best under FS Full mode. In contrast, collet clamped remained most accurate under ZS configuration. In terms of semantic alignment, cosine similarity and match rate, increases were observed across all natural language error fields under FS prompting. Among these fields, correction (match rate up to 0.479; similarity up to 0.680) and HMI-aware content (including HMI Error similarity up to 0.740) had the most substantial increase.
CN · 翻译
具体数字上:状态指示槽位 Ref X 在 FS +Clust 下准确率最高,达 0.938Ref Z 在 FS Full 下表现最佳;而 collet clamped(夹头夹紧)在 ZS 配置下最准。语义对齐方面,FS 提示下所有自然语言错误字段的余弦相似度与匹配率都有提升,其中 correction 字段(匹配率最高 0.479、相似度最高 0.680)与 HMI 感知内容(含 HMI Error 相似度最高 0.740)增幅最大。
EN · 原文
These results suggest that FS prompting promotes a more stable language generation, while cropping the interface enhances the local visual cues that matter for axis references. Overall, the results suggest that multimodal reasoning improves a safer G-code verification while supporting a more transparent human-machine interaction.
CN · 翻译
这些结果说明:FS 提示带来更稳定的语言生成,而界面裁剪放大了对轴参考(axis references)至关重要的局部视觉线索。总体而言,多模态推理让 G 代码校验更安全,也支持更透明的人机交互。
EN · 原文
The key limitation of this study is the task-specific dataset which restricts broader generalization to other machine types and unseen operating conditions. Moreover, this framework is sensitive to the design of the prompt. Therefore, making stable prompts is essential as minor adjustments in the phrasing of the prompt can result in different reasoning paths. Future extensions can address these limitations by expanding dataset size and scenario diversity, incorporating sensor feedback, and exploring prompt standardization strategies to enhance reliability and generalization in practical manufacturing environments.
CN · 翻译
本研究的关键局限是任务特定数据集——限制了对其他机床类型和未见运行条件的泛化。此外,框架对提示词设计敏感:措辞的微小调整就可能改变推理路径,因此稳定的提示词至关重要。未来扩展方向:扩大数据集规模与场景多样性、融入传感器反馈、探索提示词标准化策略,以提升实际制造环境中的可靠性与泛化能力。

七、编者解读:这篇论文到底讲了什么(大白话版)

  1. 问题:数控培训里学生要手工写 G 代码,很容易出错。以前的 AI 校验工具(LLM)只会看代码文本,但机床上的毛病常常「写」在屏幕上——报警、坐标、夹紧状态都在 HMI 面板上显示。文本模型看不见这些,等于瞎子摸象。
  2. 做法:把「G 代码程序」和「对应时刻的 HMI 屏幕截图」配对成数据集,交给能看图的视觉语言模型(VLM,这里用的 GPT-4.1);再设计一个 JSON 输出格式约束它逐槽位汇报状态,最后在提示词里塞几个「对/错示例」(few-shot),教它怎么找毛病。
  3. 结果:少样本提示(FS)整体比零样本(ZS)更能发现 HMI 错误和代码不一致;把屏幕裁剪成局部图(clustered crops)对识别 X/Z 轴参考点这类小细节特别有效——Ref X 在 FS+Clust 下准确率最高(0.938)。
  4. 最值钱的观点:「代码写得对」不等于「机床状态对得上」。真正的校验必须跨模态——文本和屏幕一起看。而「用结构化 JSON 约束大模型输出 + 少量示例引导」这套工程配方,是当前所有大模型落地任务的通用打法。
  5. 边界(论文自己承认的):数据只有一台 PathPilot 车床、八个场景,泛化到别的机床存疑;而且结果对提示词措辞很敏感——换个说法,推理路径可能就变了。所以「稳定提示词」本身就是一门学问。
🎯 对保研/求职的启示:这篇论文示范了「多模态 AI × 传统制造业」的切入点——不重新发明模型,而是把现有大模型的能力与一个真实的工艺痛点(数控校验)结合,并给出可量化的评估协议(逐槽位准确率)。面试时能讲清「研究空白在哪、数据怎么造、指标怎么定」,比堆模型名词更有说服力。

八、给新手的阅读路线图 & 延伸方向

📖 怎么读这篇论文(三遍法)

  1. 第一遍(10 分钟):只读摘要和术语表,回答三个问题——问题是什么?(G 代码校验缺视觉)方法是什么?(few-shot VLM + JSON schema)结果是什么?(FS 比 ZS 更全面)。
  2. 第二遍(20 分钟):读引言 + 结论,重点体会「LLM 看不见 HMI」这个研究空白,以及「FS vs ZS」「Full vs Clust」两套对比设计为什么这样搭。
  3. 第三遍(30 分钟):读方法文字部分——配对数据集怎么构造、JSON schema 里有哪些槽位、few-shot 示例怎么选;跳过所有编号引用和细节表格,只看文字描述;遇到不懂的术语回查术语表。

🚀 这个方向你能延伸做什么

九、英文摘要朗读(练听力用)

先盲听一遍→再看对照稿→再听一遍。目标是听出每个数字(15-slant-PRO 车床、eight scenarios)和术语(G-code、HMI、few-shot、VLM、JSON schema、per-slot accuracy)。