🚀 CodeTrans模型:用于Python源代码摘要生成
CodeTrans模型基于t5-large
架构,在Python编程语言上进行预训练,可用于生成Python函数的描述或在其他Python代码任务上进行微调,为Python代码摘要生成提供了有效的解决方案。
🚀 快速开始
以下是使用Transformers的SummarizationPipeline
来使用此模型生成Python函数文档的示例:
from transformers import AutoTokenizer, AutoModelWithLMHead, SummarizationPipeline
pipeline = SummarizationPipeline(
model=AutoModelWithLMHead.from_pretrained("SEBIS/code_trans_t5_large_source_code_summarization_python_multitask_finetune"),
tokenizer=AutoTokenizer.from_pretrained("SEBIS/code_trans_t5_large_source_code_summarization_python_multitask_finetune", skip_special_tokens=True),
device=0
)
tokenized_code = '''with open ( CODE_STRING , CODE_STRING ) as in_file : buf = in_file . readlines ( ) with open ( CODE_STRING , CODE_STRING ) as out_file : for line in buf : if line == " ; Include this text " : line = line + " Include below " out_file . write ( line ) '''
pipeline([tokenized_code])
你可以在colab notebook中运行此示例。
✨ 主要特性
- 架构基础:基于
t5-large
模型构建,拥有自己的SentencePiece词汇模型。
- 多任务训练:在软件开发领域的13个监督任务和7个无监督数据集上进行多任务训练。
- 微调优化:针对Python代码片段的源代码摘要任务进行了微调。
📦 安装指南
文档未提及具体安装步骤,暂无法提供。
💻 使用示例
基础用法
from transformers import AutoTokenizer, AutoModelWithLMHead, SummarizationPipeline
pipeline = SummarizationPipeline(
model=AutoModelWithLMHead.from_pretrained("SEBIS/code_trans_t5_large_source_code_summarization_python_multitask_finetune"),
tokenizer=AutoTokenizer.from_pretrained("SEBIS/code_trans_t5_large_source_code_summarization_python_multitask_finetune", skip_special_tokens=True),
device=0
)
tokenized_code = '''with open ( CODE_STRING , CODE_STRING ) as in_file : buf = in_file . readlines ( ) with open ( CODE_STRING , CODE_STRING ) as out_file : for line in buf : if line == " ; Include this text " : line = line + " Include below " out_file . write ( line ) '''
pipeline([tokenized_code])
📚 详细文档
模型描述
此CodeTrans模型基于t5-large
模型,具备自己的SentencePiece词汇模型。它在软件开发领域的13个监督任务和7个无监督数据集上进行多任务训练,然后针对Python代码片段的源代码摘要任务进行微调。
预期用途与限制
该模型可用于生成Python函数的描述,或在其他Python代码任务上进行微调。它可以处理未解析和未标记化的Python代码,但如果代码经过标记化处理,性能会更好。
训练数据
监督训练任务的数据集可从此处下载。
训练过程
多任务预训练
模型在单个TPU Pod V3 - 8上总共训练了500,000步,使用序列长度为512(批量大小为4096)。它总共有约2.2亿个参数,采用编码器 - 解码器架构进行训练。预训练使用的优化器是AdaFactor,学习率采用逆平方根调度。
微调
该模型随后在单个TPU Pod V2 - 8上针对仅包含Python代码的数据集进行了100步的微调,使用序列长度为512(批量大小为256)。
评估结果
对于源代码摘要任务,不同模型在不同编程语言上取得了以下BLEU分数的结果:
语言 / 模型 |
Python |
SQL |
C# |
CodeTrans - ST - Small |
8.45 |
17.55 |
19.74 |
CodeTrans - ST - Base |
9.12 |
15.00 |
18.65 |
CodeTrans - TF - Small |
10.06 |
17.71 |
20.40 |
CodeTrans - TF - Base |
10.94 |
17.66 |
21.12 |
CodeTrans - TF - Large |
12.41 |
18.40 |
21.43 |
CodeTrans - MT - Small |
13.11 |
19.15 |
22.39 |
CodeTrans - MT - Base |
13.37 |
19.24 |
23.20 |
CodeTrans - MT - Large |
13.24 |
19.40 |
23.57 |
CodeTrans - MT - TF - Small |
12.10 |
18.25 |
22.03 |
CodeTrans - MT - TF - Base |
10.64 |
16.91 |
21.40 |
CodeTrans - MT - TF - Large |
12.14 |
19.98 |
21.10 |
CODE - NN |
-- |
18.40 |
20.50 |
🔧 技术细节
该模型基于t5-large
架构,使用SentencePiece词汇模型。在多任务训练阶段,结合了软件开发领域的多个监督和无监督任务。微调阶段则专注于Python代码的摘要生成任务,通过在特定数据集上的训练来优化模型性能。
📄 许可证
文档未提及许可证信息,暂无法提供。
此项目由 Ahmed Elnaggar | LinkedIn 和 Wei Ding | LinkedIn 创建。