Update README.md
Browse files
README.md
CHANGED
@@ -20,7 +20,32 @@ It achieves the following results on the evaluation set:
|
|
20 |
|
21 |
More information needed
|
22 |
|
23 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
More information needed
|
26 |
|
|
|
20 |
|
21 |
More information needed
|
22 |
|
23 |
+
## Driectly uses
|
24 |
+
|
25 |
+
```Python
|
26 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
27 |
+
from transformers import pipeline
|
28 |
+
from transformers import GenerationConfig
|
29 |
+
additional_special_tokens = {'additional_special_tokens':['<|begin_of_java_code|>','<|end_of_java_code|>'\
|
30 |
+
,'<|begin_of_c-sharp_code|>','<|end_of_c-sharp_code|>',\
|
31 |
+
'<|translate|>']}
|
32 |
+
basemodel = "ljcnju/CodeBertForCodeTrans"
|
33 |
+
tokenizer = AutoTokenizer.from_pretrained(basemodel)
|
34 |
+
tokenizer.pad_token = tokenizer.eos_token
|
35 |
+
config = AutoConfig.from_pretrained(basemodel)
|
36 |
+
config.is_decoder = True
|
37 |
+
model = AutoModelForCausalLM.from_pretrained(basemodel,config=config)
|
38 |
+
device = torch.device("cuda") if torch.cuda.is_available() else torch.device('cpu')
|
39 |
+
model.to(device)
|
40 |
+
|
41 |
+
ger = pipeline(task='text-generation',model= model,tokenizer=tokenizer,config=GenerationConfig(pad_token_id = tokenizer.eos_token_id))
|
42 |
+
code = "public void serialize(LittleEndianOutput out) {out.writeShort(field_1_vcenter);}\n"
|
43 |
+
prefix = additional_special_tokens['additional_special_tokens'][0]
|
44 |
+
input_str = prefix + code +additional_special_tokens['additional_special_tokens'][1] + additional_special_tokens['additional_special_tokens'][2]
|
45 |
+
input_str = tokenizer.bos_token + input_str
|
46 |
+
|
47 |
+
print(ger(input_str,max_new_tokens = 256))
|
48 |
+
```
|
49 |
|
50 |
More information needed
|
51 |
|