🚀 CodeTrans模型:用于Go代码文档生成
CodeTrans模型基于T5基础架构,在Go编程语言上进行预训练。它能为Go函数生成描述,也可在其他Go代码任务上进行微调。该模型在CodeSearchNet语料库的Go数据集上进行单任务训练,对标记化的Go代码函数效果最佳。
🚀 快速开始
模型简介
此CodeTrans模型基于t5-base
模型构建,拥有自己的SentencePiece词汇模型。它在CodeSearchNet语料库的Go数据集上进行单任务训练。
预期用途与限制
该模型可用于生成Go函数的描述,或在其他Go代码任务上进行微调。它可以处理未解析和未标记化的Go代码,但如果代码经过标记化处理,性能会更好。
使用方法
以下是使用Transformers的SummarizationPipeline来生成Go函数文档的示例:
from transformers import AutoTokenizer, AutoModelWithLMHead, SummarizationPipeline
pipeline = SummarizationPipeline(
model=AutoModelWithLMHead.from_pretrained("SEBIS/code_trans_t5_base_code_documentation_generation_go"),
tokenizer=AutoTokenizer.from_pretrained("SEBIS/code_trans_t5_base_code_documentation_generation_go", skip_special_tokens=True),
device=0
)
tokenized_code = "func ( pr * Progress ) needSnapshotAbort ( ) bool { return pr . State == ProgressStateSnapshot && pr . Match >= pr . PendingSnapshot }"
pipeline([tokenized_code])
你可以在Colab笔记本中运行此示例。
📦 安装指南
本部分未提及具体安装步骤,暂不展示。
💻 使用示例
基础用法
from transformers import AutoTokenizer, AutoModelWithLMHead, SummarizationPipeline
pipeline = SummarizationPipeline(
model=AutoModelWithLMHead.from_pretrained("SEBIS/code_trans_t5_base_code_documentation_generation_go"),
tokenizer=AutoTokenizer.from_pretrained("SEBIS/code_trans_t5_base_code_documentation_generation_go", skip_special_tokens=True),
device=0
)
tokenized_code = "func ( pr * Progress ) needSnapshotAbort ( ) bool { return pr . State == ProgressStateSnapshot && pr . Match >= pr . PendingSnapshot }"
pipeline([tokenized_code])
📚 详细文档
训练数据
有监督训练任务的数据集可以从这里下载。
评估结果
对于代码文档任务,不同模型在不同编程语言上取得了以下结果(以BLEU分数衡量):
语言 / 模型 |
Python |
Java |
Go |
Php |
Ruby |
JavaScript |
CodeTrans - ST - Small |
17.31 |
16.65 |
16.89 |
23.05 |
9.19 |
13.7 |
CodeTrans - ST - Base |
16.86 |
17.17 |
17.16 |
22.98 |
8.23 |
13.17 |
CodeTrans - TF - Small |
19.93 |
19.48 |
18.88 |
25.35 |
13.15 |
17.23 |
CodeTrans - TF - Base |
20.26 |
20.19 |
19.50 |
25.84 |
14.07 |
18.25 |
CodeTrans - TF - Large |
20.35 |
20.06 |
19.54 |
26.18 |
14.94 |
18.98 |
CodeTrans - MT - Small |
19.64 |
19.00 |
19.15 |
24.68 |
14.91 |
15.26 |
CodeTrans - MT - Base |
20.39 |
21.22 |
19.43 |
26.23 |
15.26 |
16.11 |
CodeTrans - MT - Large |
20.18 |
21.87 |
19.38 |
26.08 |
15.00 |
16.23 |
CodeTrans - MT - TF - Small |
19.77 |
20.04 |
19.36 |
25.55 |
13.70 |
17.24 |
CodeTrans - MT - TF - Base |
19.77 |
21.12 |
18.86 |
25.79 |
14.24 |
18.62 |
CodeTrans - MT - TF - Large |
18.94 |
21.42 |
18.77 |
26.20 |
14.19 |
18.83 |
现有最优水平 |
19.06 |
17.65 |
18.07 |
25.16 |
12.16 |
14.90 |
📄 许可证
本部分未提及许可证信息,暂不展示。
由Ahmed Elnaggar | LinkedIn 和 Wei Ding | LinkedIn 创建