一句话:用预训练代码大模型 CodeT5 对 OCR 结果做后处理,显著提升录屏与截图中的代码抽取准确率。
从教程视频中准确抽取代码对希望复用视频代码的开发者至关重要,但现有基于 OCR 的方法因代码复杂度高和录屏格式多样而常常出错。为此,作者提出 CodeT5-OCRfix:利用预训练的代码感知大语言模型 CodeT5 对 OCR 后的代码进行后处理修正。他们从 GitHub 上 1 万余个 Java 项目中采集源码截图,用 Tesseract 做 OCR,得到超过 58.5 万对 OCR 文本与真实代码配对数据,并据此微调 CodeT5。在截图与录屏帧上的实证评估表明,CodeT5-OCRfix 优于基线代码抽取模型,且时间效率更高,从而推进了从录屏与图像中抽取代码的技术水平。
Accurate automatic code extraction from tutorial videos is crucial for software developers seeking to reuse the code contained in these videos. Current methods using optical character recognition (OCR) often yield inaccurate results due to code complexity and variations in screencast formats. To address this issue, we introduce CodeT5-OCRfix, an approach that leverages the pre-trained code-aware large language model CodeT5 to enhance code extraction accuracy by post-processing OCRed code. We first collect a large and diverse dataset of source code screenshots captured from more than 10K Java projects from GitHub. We then apply the most widely used OCR engine for the task of code extraction from videos, Tesseract, on these screenshots and collect the OCRed code along with the ground truth code extracted from the Java files. We built a training dataset of more than 585K pairs of OCRed and ground truth code pairs, which we then used to fine-tune CodeT5, obtaining our model CodeT5-OCRfix. An empirical evaluation on both screenshots and screencast frames shows that CodeT5-OCRfix outperforms baseline code extraction models and is also more time-efficient. Our approach therefore improves the state-of-the-art in code extraction techniques from screencasts and images.