aiXcoder 7B Base 在代码补全场景下是所有同等级参数量模型中效果最好的,主流多语言nl2code benchmark 平均上效果也超过codellama 34B 和StarCoder2 15B。
在我们持续推动代码大模型应用的探索过程中,aiXcoder 7B Base 模型的发布标志着一个重要的里程碑。当前版本的 aiXcoder 7B Base 是一个基础模型,专注于提升代码补全和代码生成的效率与准确性,旨在为开发人员在这些场景下提供强有力的支持。值得注意的是,这个版本尚未经过特别的instruct微调,意味着它在特定的高级任务如测试用例生成和代码调试方面可能还未达到最优表现。
> aiXcoder 7B surpasses mainstream models in nl2code benchmark. aiXcoder-7B is an enhancement of aiXcoder-7B-Base, fine-tuned on one hundred thousand data entries similar to Evol-instruct for one epoch.
<br>
<br>

> aiXcoder 7B Base surpasses mainstream models in code completion scenarios.
<br>
<br>
## 快速上手
### 运行环境
#### 选择一:构建一个运行环境
主要的环境依赖为:
- Python 3.8 or higher
- PyTorch 2.1.0 or higher
- sentencepiece 0.2.0 or higher
- transformers 4.34.1 or higher (if run inference by transformers library)
与其它自然语言大模型或代码大模型不同,在代码编程场景下, aiXcoder 考虑了代码本身的结构性特点,尽量让模型预测出完整的代码节点。简单而言,aiXcoder 训练任务结合了 fill in the middle(FIM, Bavarian et al., 2022) and parser generator tool,在构造训练数据时我们会将代码解析为抽象语法树,并随机截取一个完整的节点构造 FIM。这样做的原因首先我们需要保证输入数据相对完整,前序与后续都处于同一层级。其次,我们也需要模型预测结果更加完整,生成的代码具有完整层次结构。
```python
foriinrange(20):
ifi%5==0:
print("Hello World")
```

> 如上简单的代码能解析为抽象语法树,我们会根据抽象语法树的节点构造结构化的 FIM 训练任务。
<br>
<br>
假设我们选中了上述代码中的 IF 结点,那么我们将从 IF 结点及其子树构造出训练样本。如下两条例子是等价的:
```bash
# fill in the middle, SPM mode
"<s>▁<AIX-SPAN-PRE>▁<AIX-SPAN-POST> print(\"Hello World\")\n▁<AIX-SPAN-MIDDLE># the file path is: test.py\n# the code file is written by Python\nfor i in range(20):\n if i % 5 == 0:<\s>"
# fill in the middle, PSM mode
"<s>▁<AIX-SPAN-PRE># the file path is: test.py\n# the code file is written by Python\nfor i in range(20):\n if ▁<AIX-SPAN-POST> print(\"Hello World\")\n▁<AIX-SPAN-MIDDLE>i % 5 == 0:<\s>"
```
## 实验结果
### NL2Code 基准测试
表1 展示了 aiXcoder-7B Base 模型在独立方法生成基准上的表现,我们的模型在各大预训练基础模型中表现很好,在百亿级参数量下拥有当前最好的效果。

### 代码补全 (Fill in the Middle)
与 Table 1 的 Stand alone nl2code 不同,在实际编程场景中,我们更需要考虑光标上下文的代码补全能力。一般而言,各种开源代码大模型都会考虑在预训练中加入Fill in the middle(FIM) 模式,来强化模型在考虑代码上下文的场景下生成更准确的结果。为此,我们将以FIM为默认代码补全方式,评测各个模型在实际编程场景中的能力。
Table 3 展示了不同模型在不同语言上的平均生成效果,最终的评估结果是所有补全场景与评测样本的均值。aiXcoder 7B Base 模型在各大编程语言,各种评估标准下都是效果最好的,这表明aiXcoder 7B Base 在最基础的代码补全能力上是所有同量级开源模型最好的,最适合用于实际编程场景中提供代码补全能力的基础模型。
The source code in this repository is licensed under the [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0) License - see the LICENSE file for details.
The model weights are licensed under the [Model License](./MODEL_LICENSE) for academic research use; for commercial use, please apply by sending an email to support@aixcoder.com.
## Acknowledgments
We would like to thank all contributors to the open-source projects and datasets that made this work possible.
For any questions or issues, please open an issue on this repository.
Thank you for your interest in our Code Large Language Model. We look forward to your contributions and feedback!