标签:
- 摘要生成
微件:
- 文本: '''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 ) '''
用于Python源代码摘要的CodeTrans模型
该预训练模型基于T5基础架构,专为Python编程语言设计。首次发布于此代码库。本模型针对分词后的Python代码函数进行训练,在分词后的Python函数上表现最佳。
模型描述
此CodeTrans模型基于t5-base
模型,拥有独立的SentencePiece词汇模型。采用单任务训练方式,在Python源代码摘要数据集上完成训练。
使用场景与限制
可用于生成Python函数的功能描述,或针对其他Python代码任务进行微调。支持非解析和非分词的原始Python代码,但对分词后的代码处理效果更优。
使用方法
通过Transformers的SummarizationPipeline生成Python函数文档:
from transformers import AutoTokenizer, AutoModelWithLMHead, SummarizationPipeline
pipeline = SummarizationPipeline(
model=AutoModelWithLMHead.from_pretrained("SEBIS/code_trans_t5_base_source_code_summarization_python"),
tokenizer=AutoTokenizer.from_pretrained("SEBIS/code_trans_t5_base_source_code_summarization_python", 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笔记本中运行此示例。
训练数据
监督训练任务数据集可从此链接下载
评估结果
不同模型在源代码摘要任务中的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 |
CODE-NN |
-- |
18.40 |
20.50 |
由Ahmed Elnaggar | LinkedIn和Wei Ding | LinkedIn创建