Text Generation
Transformers
Safetensors
English
code
plbart
text2text-generation
code-summarization
docstring-generation
python
Eval Results (legacy)
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")# pip install -U transformers accelerate # 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
Upload folder using huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
- code
|
| 5 |
+
library_name: transformers
|
| 6 |
+
pipeline_tag: text2text-generation
|
| 7 |
+
base_model: uclanlp/plbart-base
|
| 8 |
+
datasets:
|
| 9 |
+
- semeru/code-text-python
|
| 10 |
+
tags:
|
| 11 |
+
- plbart
|
| 12 |
+
- code-summarization
|
| 13 |
+
- docstring-generation
|
| 14 |
+
- python
|
| 15 |
+
metrics:
|
| 16 |
+
- bleu
|
| 17 |
+
- rouge
|
| 18 |
+
model-index:
|
| 19 |
+
- name: thealper2/plbart-docstring-generation
|
| 20 |
+
results:
|
| 21 |
+
- task:
|
| 22 |
+
type: text2text-generation
|
| 23 |
+
name: Python docstring generation
|
| 24 |
+
dataset:
|
| 25 |
+
name: semeru/code-text-python
|
| 26 |
+
type: semeru/code-text-python
|
| 27 |
+
split: test
|
| 28 |
+
metrics:
|
| 29 |
+
- type: bleu
|
| 30 |
+
value: 5.9444
|
| 31 |
+
name: BLEU
|
| 32 |
+
- type: rouge1
|
| 33 |
+
value: 34.7862
|
| 34 |
+
name: ROUGE-1
|
| 35 |
+
- type: rouge2
|
| 36 |
+
value: 12.6668
|
| 37 |
+
name: ROUGE-2
|
| 38 |
+
- type: rougeL
|
| 39 |
+
value: 32.0423
|
| 40 |
+
name: ROUGE-L
|
| 41 |
+
---
|
| 42 |
+
|
| 43 |
+
# plbart-docstring-generation
|
| 44 |
+
|
| 45 |
+
[`uclanlp/plbart-base`](https://huggingface.co/uclanlp/plbart-base) fully fine-tuned to generate English docstrings for Python functions, trained on [`semeru/code-text-python`](https://huggingface.co/datasets/semeru/code-text-python).
|
| 46 |
+
|
| 47 |
+
## Usage
|
| 48 |
+
|
| 49 |
+
```python
|
| 50 |
+
from transformers import AutoTokenizer, PLBartForConditionalGeneration
|
| 51 |
+
|
| 52 |
+
tokenizer = AutoTokenizer.from_pretrained("thealper2/plbart-docstring-generation", src_lang="python", tgt_lang="en_XX")
|
| 53 |
+
model = PLBartForConditionalGeneration.from_pretrained("thealper2/plbart-docstring-generation")
|
| 54 |
+
|
| 55 |
+
code = "def add(a, b):\n return a + b"
|
| 56 |
+
inputs = tokenizer(" ".join(code.split()), max_length=512, truncation=True, return_tensors="pt")
|
| 57 |
+
out = model.generate(**inputs, num_beams=4, max_length=64,
|
| 58 |
+
decoder_start_token_id=model.config.decoder_start_token_id)
|
| 59 |
+
print(tokenizer.decode(out[0], skip_special_tokens=True))
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
## Evaluation
|
| 63 |
+
|
| 64 |
+
Test split (14918 examples), beam search with 4 beams, max length 64.
|
| 65 |
+
|
| 66 |
+
| Split | BLEU | ROUGE-1 | ROUGE-2 | ROUGE-L | Loss |
|
| 67 |
+
|---|---|---|---|---|---|
|
| 68 |
+
| test | 5.94 | 34.79 | 12.67 | 32.04 | 2.6885 |
|
| 69 |
+
| validation | 5.46 | 33.95 | 12.33 | 31.28 | 3.8836 |
|
| 70 |
+
|
| 71 |
+
Mean generated length: 6.35 tokens (references: 11.20).
|
| 72 |
+
|
| 73 |
+
## Training
|
| 74 |
+
|
| 75 |
+
| Hyperparameter | Value |
|
| 76 |
+
|---|---|
|
| 77 |
+
| max_train_samples | 50000 |
|
| 78 |
+
| num_epochs | 2.0 |
|
| 79 |
+
| learning_rate | 3e-05 |
|
| 80 |
+
| train_batch_size | 32 |
|
| 81 |
+
| gradient_accumulation_steps | 1 |
|
| 82 |
+
| weight_decay | 0.01 |
|
| 83 |
+
| warmup_ratio | 0.05 |
|
| 84 |
+
| lr_scheduler_type | linear |
|
| 85 |
+
| label_smoothing_factor | 0.1 |
|
| 86 |
+
| max_source_length | 512 |
|
| 87 |
+
| max_target_length | 128 |
|
| 88 |
+
| bf16 | True |
|
| 89 |
+
| seed | 42 |
|
| 90 |
+
|
| 91 |
+
Trained examples: 50000. Training time: 0.29 h on NVIDIA GeForce RTX 5060 Ti (15.9 GiB, sm_120).
|
| 92 |
+
|
| 93 |
+
## Limitations
|
| 94 |
+
|
| 95 |
+
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.
|