当前位置:网站首页>【AI4Code】《Pythia: AI-assisted Code Completion System》(KDD 2019)
【AI4Code】《Pythia: AI-assisted Code Completion System》(KDD 2019)
2022-07-25 11:11:00 【chad_lee】
代码补全
补全属性/方法,在一个给定集合内推荐item,最简单的方法就是按字母排序,缺点是用户下拉菜单的时间可能要长于直接打代码的时间。用户可以多打几个前缀帮助补全。

基于模型的代码补全
- 基于抽象语法树(AST)——Pythia等
- 基于代码文本——Deep TabNine 、Galois等
数据:AST和代码文本
AST是源代码语法结构的一种抽象表示。它以树状的形式表现编程语言的语法结构,树上的每个节点都表示源代码中的一种结构。之所以说语法是“抽象”的,是因为这里的语法并不会表示出真实语法中出现的每个细节。比如,嵌套括号被隐含在树的结构中,并没有以节点的形式呈现;而类似于 if-condition-then 这样的条件跳转语句,可以使用带有三个分支的节点来表示。

一种是将代码解析为抽象语法树(AST),每个节点包括两个属性:type和value,所以每个节点需要两个embedding。然后使用深度优先遍历把AST的每个节点flatten成序列。
一种是直接将代码处理成文本,包含空格、换行符、缩进符等。
Pythia(KDD’19)
Pythia收集了Github上 Stars 前2700个Python项目的代码,一共包含了1600万个方法调用作为训练数据。

任务是给定一个长为 T T T的代码片段 C C C ,其中每个token为 c t c_t ct,以及一个特殊token “.”,预测token m ∗ m^{*} m∗。所以这个任务就是给定一个序列,根据这个序列的表征预测一个token,很适合用LSTM:
x t = L c t h t = f ( x t , h t − 1 ) P ( m ∣ C ) = y t = softmax ( W h t + b ) m ∗ = argmax ( P ( m ∣ C ) ) \begin{aligned} x_{t} &=L c_{t} \\ h_{t} &=f\left(x_{t}, h_{t-1}\right) \\ P(m \mid C) &=y_{t}=\operatorname{softmax}\left(W h_{t}+b\right) \\ m^{*} &=\operatorname{argmax}(P(m \mid C)) \end{aligned} xthtP(m∣C)m∗=Lct=f(xt,ht−1)=yt=softmax(Wht+b)=argmax(P(m∣C))
即在LSTM的输出后面接一个分类器。这里还用了tying embedding,LSTM的输出经过一个线性层后,直接和候选集里的token的embedding做内积,然后对内积结果做softmax。
Pythia已经作为VSCode的一个插件:

所以代码补全任务和session-based推荐任务和方法是相同的,不过代码补全任务的候选集更小。
DeepTabNine和Galois
这类方法和Pythia类似,只不过数据格式和模型与Pythia不同,在输入数据上用的是代码文本,模型用的是GPT(只有Transformer的Decoder,少一层Attention)而不是LSTM:

但是这两个方法是收费使用的插件,没有开源技术细节和论文。
边栏推荐
- JaveScript循环
- 软件测试阶段的风险
- 小程序image 无法显示base64 图片 解决办法 有效
- Innovation and breakthrough! AsiaInfo technology helped a province of China Mobile complete the independent and controllable transformation of its core accounting database
- Brpc source code analysis (VI) -- detailed explanation of basic socket
- 基于TCP/IP在同一局域网下的数据传输
- W5500 upload temperature and humidity to onenet platform
- flink sql client 连接mysql报错异常,如何解决?
- Power BI----这几个技能让报表更具“逼格“
- PL/SQL入门,非常详细的笔记
猜你喜欢

硬件连接服务器 tcp通讯协议 gateway

"Mqtt protocol explanation and Practice (access to onenet)" of wiznet w5500 series training activities

GPT plus money (OpenAI CLIP,DALL-E)

brpc源码解析(二)—— brpc收到请求的处理过程

浅谈低代码技术在物流管理中的应用与创新

W5500 upload temperature and humidity to onenet platform

LeetCode 50. Pow(x,n)

Teach you how to configure S2E as the working mode of TCP client through MCU

【GCN-RS】Are Graph Augmentations Necessary? Simple Graph Contrastive Learning for RS (SIGIR‘22)
![[imx6ull notes] - a preliminary exploration of the underlying driver of the kernel](/img/0f/a0139be99c61fde08e73a5be6d6b4c.png)
[imx6ull notes] - a preliminary exploration of the underlying driver of the kernel
随机推荐
Signal and slot mechanism ==pyqt5
return 和 finally的执行顺序 ?各位大佬请看过来,
【高并发】SimpleDateFormat类到底为啥不是线程安全的?(附六种解决方案,建议收藏)
30 sets of Chinese style ppt/ creative ppt templates
W5500 upload temperature and humidity to onenet platform
winddows 计划任务执行bat 执行PHP文件 失败的解决办法
session和cookie有什么区别??小白来告诉你
dirReader. Readentries compatibility issues. Exception error domexception
Management of software defects
Varest blueprint settings JSON
JS process control
[cloud co creation] what is the role of AI in mathematics? What will be the disruptive impact on the mathematical world in the future?
Arrays in JS
Differences in usage between tostring() and new string()
小程序image 无法显示base64 图片 解决办法 有效
flink sql client 连接mysql报错异常,如何解决?
What is the global event bus?
Qin long, a technical expert of Alibaba cloud: a prerequisite for reliability assurance - how to carry out chaos engineering on the cloud
Brpc source code analysis (I) -- the main process of RPC service addition and server startup
Various controls ==pyqt5