File size: 3,574 Bytes
bc81432
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23d31af
 
bc81432
 
 
23d31af
bc81432
f2c556c
 
 
f5ea9eb
f2c556c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f5ea9eb
 
 
 
f2c556c
 
bc81432
 
 
 
 
 
 
 
 
 
 
 
23d31af
bc81432
 
 
 
 
 
 
23d31af
bc81432
 
 
23d31af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bc81432
 
 
 
23d31af
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
---
base_model: microsoft/codebert-base
tags:
- generated_from_trainer
model-index:
- name: CodeBertForCodeTrans
  results: []
---

<!-- This model card has been generated automatically according to the information the Trainer had access to. You
should probably proofread and complete it, then remove this comment. -->

# CodeBertForCodeTrans

This model is a fine-tuned version of [microsoft/codebert-base](https://huggingface.co/microsoft/codebert-base) on an unknown dataset.
It achieves the following results on the evaluation set:
- Loss: 0.0006

## Model description

More information needed

## Driectly uses

```Python

from transformers import AutoTokenizer, AutoModelForCausalLM
additional_special_tokens = {'additional_special_tokens':['<|begin_of_java_code|>','<|end_of_java_code|>'\
                                                           ,'<|begin_of_c-sharp_code|>','<|end_of_c-sharp_code|>',\
                                                            '<|translate|>']}
basemodel = "ljcnju/CodeBertForCodeTrans"
tokenizer = AutoTokenizer.from_pretrained(basemodel)
tokenizer.pad_token = tokenizer.eos_token
config = AutoConfig.from_pretrained(basemodel)
config.is_decoder = True
model = AutoModelForCausalLM.from_pretrained(basemodel,config=config)
device = torch.device("cuda") if torch.cuda.is_available() else torch.device('cpu') 
model.to(device)

code = "public void serialize(LittleEndianOutput out) {out.writeShort(field_1_vcenter);}\n"
prefix =  additional_special_tokens['additional_special_tokens'][0] 
input_str = prefix + code +additional_special_tokens['additional_special_tokens'][1] + additional_special_tokens['additional_special_tokens'][2]
input = tokenizer(input_str,return_tensors = "pt")
output = model.generate(**input, max_length = 256)
outputs_str = tokenizer.decode(output[0])
print(outputs_str)

```

More information needed

## Training and evaluation data

More information needed

## Training procedure

### Training hyperparameters

The following hyperparameters were used during training:
- learning_rate: 5e-05
- train_batch_size: 16
- eval_batch_size: 16
- seed: 42
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
- lr_scheduler_type: linear
- lr_scheduler_warmup_steps: 12354.0
- num_epochs: 20
- mixed_precision_training: Native AMP

### Training results

| Training Loss | Epoch | Step  | Validation Loss |
|:-------------:|:-----:|:-----:|:---------------:|
| 5.7169        | 1.0   | 644   | 4.5075          |
| 3.0571        | 2.0   | 1288  | 2.1423          |
| 0.7391        | 3.0   | 1932  | 0.2866          |
| 0.1028        | 4.0   | 2576  | 0.0219          |
| 0.0158        | 5.0   | 3220  | 0.0047          |
| 0.0065        | 6.0   | 3864  | 0.0024          |
| 0.0036        | 7.0   | 4508  | 0.0020          |
| 0.0028        | 8.0   | 5152  | 0.0014          |
| 0.0018        | 9.0   | 5796  | 0.0010          |
| 0.0023        | 10.0  | 6440  | 0.0017          |
| 0.002         | 11.0  | 7084  | 0.0009          |
| 0.002         | 12.0  | 7728  | 0.0012          |
| 0.0015        | 13.0  | 8372  | 0.0020          |
| 0.0028        | 14.0  | 9016  | 0.0010          |
| 0.0015        | 15.0  | 9660  | 0.0007          |
| 0.0027        | 16.0  | 10304 | 0.0015          |
| 0.002         | 17.0  | 10948 | 0.0007          |
| 0.0011        | 18.0  | 11592 | 0.0009          |
| 0.0019        | 19.0  | 12236 | 0.0007          |
| 0.0003        | 20.0  | 12880 | 0.0006          |


### Framework versions

- Transformers 4.37.2
- Pytorch 2.1.2+cu121
- Datasets 2.15.0
- Tokenizers 0.15.0