thealper2 commited on
Commit
2617f02
·
verified ·
1 Parent(s): 8570008

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +95 -0
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.