-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
4,924 additions
and
605 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
python run.py \ | ||
--output_dir=./saved_models \ | ||
--tokenizer_name=microsoft/codebert-base \ | ||
--model_name_or_path=microsoft/codebert-base \ | ||
--do_eval \ | ||
--do_test \ | ||
--train_data_file=../dataset/train.jsonl \ | ||
--eval_data_file=../dataset/valid.jsonl \ | ||
--test_data_file=../dataset/test.jsonl \ | ||
--num_train_epochs 1 \ | ||
--block_size 64 \ | ||
--train_batch_size 8 \ | ||
--eval_batch_size 16 \ | ||
--learning_rate 2e-5 \ | ||
--max_grad_norm 1.0 \ | ||
--seed 123456 2>&1 | tee test.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
import copy | ||
|
||
import torch | ||
import torch.nn as nn | ||
import torch.nn.functional as F | ||
from torch.autograd import Variable | ||
from torch.nn import CrossEntropyLoss, MSELoss | ||
|
||
|
||
class Model(nn.Module): | ||
def __init__(self, encoder, config, tokenizer, args): | ||
super(Model, self).__init__() | ||
self.encoder = encoder | ||
self.config = config | ||
self.tokenizer = tokenizer | ||
self.args = args | ||
|
||
def forward(self, input_ids=None, labels=None): | ||
logits = self.encoder(input_ids, attention_mask=input_ids.ne(1))[0] | ||
prob = torch.softmax(logits, -1) | ||
if labels is not None: | ||
loss_fct = nn.CrossEntropyLoss(ignore_index=-1) | ||
loss = loss_fct(logits, labels) | ||
return loss, prob | ||
else: | ||
return prob |
Oops, something went wrong.