<jupyter_start><jupyter_text>DocRED dataset load<jupyter_code>train_set = BERTDGLREDataset(opt.train_set, opt.train_set_save, word2id, ner2id, rel2id, dataset_type='train',
                             opt=opt)
dev_set = BERTDGLREDataset(opt.dev_set, opt.dev_set_save, word2id, ner2id, rel2id, dataset_type='dev',
                           instance_in_train=train_set.instance_in_train, opt=opt)
# dataloaders
train_loader = DGLREDataloader(train_set, batch_size=opt.batch_size, shuffle=True,
                               negativa_alpha=opt.negativa_alpha)
dev_loader = DGLREDataloader(dev_set, batch_size=opt.test_batch_size, dataset_type='dev')
def train(model, train_loader):

    model = get_cuda(model)

    model.train()
    acc_NA, acc_not_NA, acc_total = Accuracy(), Accuracy(), Accuracy()

    start_epoch = 0
    for epoch in range(start_epoch, opt.epoch + 1):
        start_time = time.time()
        for acc in [acc_NA, acc_not_NA, acc_total]:
            acc.clear()

        for ii, d in enumerate(train_loader):
            relation_multi_label = d['relation_multi_label']
            relation_mask = d['relation_mask']
            relation_label = d['relation_label']

            predict = model(words=d['context_idxs'],
                src_lengths=d['context_word_length'],
                mask=d['context_word_mask'],
                entity_type=d['context_ner'],
                entity_id=d['context_pos'],
                mention_id=d['context_mention'],
                distance=None,
                entity2mention_table=d['entity2mention_table'],
                graphs=d['graphs'],
                h_t_pairs=d['h_t_pairs'],
                relation_mask=relation_mask,
                path_table=d['path_table'],
                entity_graphs=d['entity_graphs'],
                ht_pair_distance=d['ht_pair_distance']
            )
            print(predict)
            break
        break
train(model_original, train_loader)<jupyter_output>tensor([[[  -4.4753,  -43.2044,  -42.7028,  ...,  -31.9513,  -31.4520,
           -37.2508],
         [ -12.3107,  -54.4923,  -43.5470,  ...,  -41.5890,  -38.9031,
           -36.9920],
         [  -9.3263,  -67.7657,  -43.3337,  ...,  -58.3543,  -62.6477,
           -62.0271],
         ...,
         [ -19.6678, -133.6537, -139.1118,  ..., -141.7457, -149.0825,
          -150.9542],
         [ -11.6704, -151.5786, -153.3741,  ..., -148.8346, -162.9838,
          -169.6308],
         [ -19.8514, -153.4541, -135.7840,  ..., -181.8170, -167.2855,
          -192.5784]],

        [[  -8.0435,  -26.3091,    9.1803,  ...,  -24.8662,  -44.5049,
           -46.8739],
         [ -12.1401,   13.1404,  -34.0412,  ...,  -68.4048,  -68.7761,
           -74.8332],
         [ -19.3975,   21.9022,  -40.7421,  ...,  -60.0891,  -66.3379,
           -70.8801],
         ...,
         [ -29.8872, -261.7500, -197.6829,  ..., -282.1135, -296.5481,
          -286.5006],
         [ -14.4501, -280.8423, -218.345[...]<jupyter_text>Change OPT (DocRED -> SemEval)<jupyter_code>optSemEval = opt
optSemEval.train = "../SemEval2DocRED/train_annotated.json"
optSemEval.train_set = "../SemEval2DocRED/train_annotated.json"
optSemEval.train_set_save = "../SemEval2DocRED/train_BERT.pkl"

optSemEval.dev_set = "../SemEval2DocRED/dev.json"
optSemEval.dev_set_save = "../SemEval2DocRED/dev_BERT.pkl"

with open ("../SemEval2DocRED/DocRED_baseline_metadata/rel2id.json") as d:
    optSemEval.rel2id = json.load(d)
with open ("../SemEval2DocRED/DocRED_baseline_metadata/word2id.json") as d:
    optSemEval.word2id = json.load(d)

optSemEval.relation_nums = 10
optSemEval.relation_nums = 10
ner2id
train_set = BERTDGLREDataset(optSemEval.train_set, optSemEval.train_set_save, optSemEval.word2id, {"None":0}, optSemEval.rel2id, dataset_type='train',
                             opt=optSemEval)
dev_set = BERTDGLREDataset(optSemEval.dev_set, optSemEval.dev_set_save, optSemEval.word2id, {"None":0}, optSemEval.rel2id, dataset_type='dev',
                           instance_in_train=train_set.instance_in_train, opt=optSemEval)
# dataloaders
train_loader = DGLREDataloader(train_set, batch_size=optSemEval.batch_size, shuffle=True,
                               negativa_alpha=optSemEval.negativa_alpha)
dev_loader = DGLREDataloader(dev_set, batch_size=optSemEval.test_batch_size, dataset_type='dev')
model_semEval = GAIN_BERT(optSemEval)

model_semEval.bert = model_original.bert

for child in model_semEval.bert.children():
    for param in child.parameters():
        param.requires_grad = False
train(model_semEval, train_loader)<jupyter_output>tensor([[[ 0.0820,  0.0555,  0.1060,  ..., -0.1069, -0.2659,  0.2644],
         [-0.3910, -0.1363, -0.2390,  ...,  0.1367, -0.2156,  0.2055],
         [-0.8999, -0.0288, -0.0096,  ...,  0.1641, -0.0861,  0.4132],
         ...,
         [-1.1530, -0.0763,  0.2963,  ...,  0.4006, -0.6051,  1.2431],
         [-0.0294,  0.0123, -0.9427,  ..., -0.1362, -0.7850,  0.4324],
         [-0.4760,  0.3644, -0.7466,  ..., -0.0844,  0.3149, -0.0189]],

        [[ 0.1789,  0.4055,  0.0378,  ..., -0.0627, -0.3748,  0.2635],
         [-0.0723, -0.4669, -0.1513,  ...,  0.0471,  0.1920,  0.3797],
         [ 0.2763,  0.4738,  0.2147,  ...,  0.7542, -1.3142,  0.2215],
         ...,
         [-0.3469,  0.5495,  0.1965,  ...,  0.7479,  0.0550, -0.0234],
         [ 0.1589,  0.3491, -0.0970,  ...,  0.0991, -0.3902,  0.2634],
         [ 0.9001, -0.4232, -0.0416,  ...,  1.1210, -0.0956, -0.2757]],

        [[-0.2735,  0.0868, -0.0593,  ...,  0.2635, -0.0318,  0.2504],
         [-0.1859, -0.1550, -0.0871,  ...,  0[...]
StarcoderdataJupyterStructuredCleanDedup