Instructions to use thealper2/plbart-docstring-generation with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use thealper2/plbart-docstring-generation with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="thealper2/plbart-docstring-generation")# Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("thealper2/plbart-docstring-generation") model = AutoModelForSeq2SeqLM.from_pretrained("thealper2/plbart-docstring-generation", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use thealper2/plbart-docstring-generation with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "thealper2/plbart-docstring-generation" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "thealper2/plbart-docstring-generation", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/thealper2/plbart-docstring-generation
- SGLang
How to use thealper2/plbart-docstring-generation with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "thealper2/plbart-docstring-generation" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "thealper2/plbart-docstring-generation", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "thealper2/plbart-docstring-generation" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "thealper2/plbart-docstring-generation", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use thealper2/plbart-docstring-generation with Docker Model Runner:
docker model run hf.co/thealper2/plbart-docstring-generation
plbart-docstring-generation
uclanlp/plbart-base fully fine-tuned to generate English docstrings for Python functions, trained on semeru/code-text-python.
Usage
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.
| Split | BLEU | ROUGE-1 | ROUGE-2 | ROUGE-L | Loss |
|---|---|---|---|---|---|
| test | 5.94 | 34.79 | 12.67 | 32.04 | 2.6885 |
| validation | 5.46 | 33.95 | 12.33 | 31.28 | 3.8836 |
Mean generated length: 6.35 tokens (references: 11.20).
Training
| Hyperparameter | Value |
|---|---|
| max_train_samples | 50000 |
| num_epochs | 2.0 |
| learning_rate | 3e-05 |
| train_batch_size | 32 |
| gradient_accumulation_steps | 1 |
| weight_decay | 0.01 |
| warmup_ratio | 0.05 |
| lr_scheduler_type | linear |
| label_smoothing_factor | 0.1 |
| max_source_length | 512 |
| max_target_length | 128 |
| bf16 | True |
| seed | 42 |
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.
- Downloads last month
- -
Model tree for thealper2/plbart-docstring-generation
Base model
uclanlp/plbart-baseDataset used to train thealper2/plbart-docstring-generation
Evaluation results
- BLEU on semeru/code-text-pythontest set self-reported5.944
- ROUGE-1 on semeru/code-text-pythontest set self-reported34.786
- ROUGE-2 on semeru/code-text-pythontest set self-reported12.667
- ROUGE-L on semeru/code-text-pythontest set self-reported32.042