任务
优化CodeBERT,使得其更加适合长代码的任务。
CodeBERT:
Idea
- 借鉴Longformer的sparse attention思路,考虑Global+sliding attention+Random attention,提升self-attetion的效率
- Top-k attetion is all you need:对于每个词(代码 片段),统计这个词attend到其他词的attention scores,看是不是对于每个词只需要top-k的attention就够了。参考文章:top-k attention https://openreview.net/pdf?id=Hye87grYDH
- Graph attention for code semantics:code变量之间是有graph依赖关系的,每个node只需要attend一个subgraph即可,可以用这个subgraph做filtering,减少不必要的attention。可以参考这篇文章:https://arxiv.org/pdf/2012.13915.pdf 或者latticeBERT:https://arxiv.org/abs/2104.07204
模型图
+top-k attention+code structure attention(需要图)
下游任务
具体见CodeXGLUE benchmark:https://github.com/microsoft/CodeXGLUE
实验结果(Overview)
| Defect-detection | POJ-104 | ||
|---|---|---|---|
| CodeBERT | |||
| CodeBERT w/ sparse-att | |||
| CodeBERT w/ sparse-att + topk-att | |||
| CodeBERT w/ sparse-att+topk-att+graph-att |
Actions
统计数据集中的code length | | [0, 512] | [512, ] | | —- | —- | —- | | Defect-detection | 18563 | 8755 | | Clone-detection-POJ-104 | 49947 | 2053 | | Clone-detection-BigCloneBench | 7697 | 1429 | | code-refinement | 58350+65454 | | | code-to-code-trans | 11800 | | | CodeCompletion-line | 2145+5524 | 855+4476 |
统计top-k attention这个想法是不是成立?能不能画一个long-tail的图?
- 细化Graph attention,先尝试简单的filtering,看效果怎么样?
- 扩大更多的数据,在所有CodeBERT的数据里面做实验
实验结果(详细)
参考文献
- ETC
- Longformer
- BigBird O(n*k)
具体实现过程中的问题:
- sliding window:修改self-attention部分,可以通过分块来优化,只需要计算部分的attention score,可以增加max_sequence_length
- top-k 需要执行full self-attention之后获得,无法提速,也无法增加可以处理的max_sequence_length,对于长代码仍然无法处理
- code structure 形成一个矩阵M,处理方法一般是A’= M·A,也是需要执行full self-attention之后获得[相关工作:Code Summarization with Structure-induced Transformer https://arxiv.org/pdf/2012.14710v2.pdf]
- top-k和sliding window的重合度?(见POJ04的attention visualization)
