Team Ai
Modelpublic

thealper2/plbart-docstring-generation

sourceHugging Faceupdated 13d agoView on Hugging Face
0likes292downloads
Model Card

plbart-docstring-generation

`uclanlp/plbart-base` fully fine-tuned to generate English docstrings for Python functions, trained on `semeru/code-text-python`.

Usage

python
from transformers import AutoTokenizer, PLBartForConditionalGeneration

tokenizer = AutoTokenizer.from_pretrained("thealper2/plbart-docstring-generation", src_lang="python", tgt_lang="en_XX")
model = PLBartForConditionalGeneration.from_pretrained("thealper2/plbart-docstring-generation")

code = "def add(a, b):\n    return a + b"
inputs = tokenizer(" ".join(code.split()), max_length=512, truncation=True, return_tensors="pt")
out = model.generate(**inputs, num_beams=4, max_length=64,
                     decoder_start_token_id=model.config.decoder_start_token_id)
print(tokenizer.decode(out[0], skip_special_tokens=True))

Evaluation

Test split (14918 examples), beam search with 4 beams, max length 64.

SplitBLEUROUGE-1ROUGE-2ROUGE-LLoss
test5.9434.7912.6732.042.6885
validation5.4633.9512.3331.283.8836

Mean generated length: 6.35 tokens (references: 11.20).

Training

HyperparameterValue
maxtrainsamples50000
num_epochs2.0
learning_rate3e-05
trainbatchsize32
gradientaccumulationsteps1
weight_decay0.01
warmup_ratio0.05
lrschedulertypelinear
labelsmoothingfactor0.1
maxsourcelength512
maxtargetlength128
bf16True
seed42

Trained examples: 50000. Training time: 0.29 h on NVIDIA GeForce RTX 5060 Ti (15.9 GiB, sm_120).

Limitations

Generated docstrings are short, single-sentence summaries; they tend to be shorter than human-written references and may describe parameters or behaviour incorrectly. Review them before use.