NTUYG commited on
Commit
a96955c
1 Parent(s): 997a65d

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +63 -3
README.md CHANGED
@@ -1,3 +1,63 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # How To Use
2
+ ```PYTHON
3
+ from transformers import BartForConditionalGeneration, BartTokenizer
4
+ model = BartForConditionalGeneration.from_pretrained("NTUYG/ComFormer")
5
+ tokenizer = BartTokenizer.from_pretrained("NTUYG/ComFormer")
6
+ code = '''
7
+ public static void copyFile( File in, File out )
8
+ throws IOException
9
+ {
10
+ FileChannel inChannel = new FileInputStream( in ).getChannel();
11
+ FileChannel outChannel = new FileOutputStream( out ).getChannel();
12
+ try
13
+ {
14
+ // inChannel.transferTo(0, inChannel.size(), outChannel); // original -- apparently has trouble copying large files on Windows
15
+
16
+ // magic number for Windows, 64Mb - 32Kb)
17
+ int maxCount = (64 * 1024 * 1024) - (32 * 1024);
18
+ long size = inChannel.size();
19
+ long position = 0;
20
+ while ( position < size )
21
+ {
22
+ position += inChannel.transferTo( position, maxCount, outChannel );
23
+ }
24
+ }
25
+ finally
26
+ {
27
+ if ( inChannel != null )
28
+ {
29
+ inChannel.close();
30
+ }
31
+ if ( outChannel != null )
32
+ {
33
+ outChannel.close();
34
+ }
35
+ }
36
+ }
37
+ '''
38
+ code_seq, sbt = utils.transformer(code) #can find in https://github.com/NTDXYG/ComFormer
39
+ input_text = code_seq + sbt
40
+ input_ids = tokenizer.encode(input_text, return_tensors="pt", max_length=256, truncation=True)
41
+ summary_text_ids = model.generate(
42
+ input_ids=input_ids,
43
+ bos_token_id=model.config.bos_token_id,
44
+ eos_token_id=model.config.eos_token_id,
45
+ length_penalty=2.0,
46
+ max_length=30,
47
+ min_length=2,
48
+ num_beams=5,
49
+ )
50
+ comment = tokenizer.decode(summary_text_ids[0], skip_special_tokens=True)
51
+ print(comment)
52
+ ```
53
+ # BibTeX entry and citation info
54
+ ```
55
+ @misc{yang2021comformer,
56
+ title={ComFormer: Code Comment Generation via Transformer and Fusion Method-based Hybrid Code Representation},
57
+ author={Guang Yang and Xiang Chen and Jinxin Cao and Shuyuan Xu and Zhanqi Cui and Chi Yu and Ke Liu},
58
+ year={2021},
59
+ eprint={2107.03644},
60
+ archivePrefix={arXiv},
61
+ primaryClass={cs.SE}
62
+ }
63
+ ```