🚀 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 創建