Пример #1
0
    for trace in trace_list:
        #for i in range(nbatches):
        #data = [event2id[record[0]]for record in trace_list[trace]]
        data = [[event2id[record[0]] for record in trace_list[trace]]]
        #data = torch.from_numpy(np.random.randint(1, V, size=(batch, 10))).cuda()
        #data[:, 0] = 1
        #print(data)
        data = torch.Tensor(data).cuda()
        src = Variable(data, requires_grad=False)
        tgt = Variable(data, requires_grad=False)
        #print(batch,nbatches,tgt.size())
        yield Batch(src, tgt, 0)


for epoch in range(10):
    model.train()
    print()
    run_epoch(data_gen(Data_test.trace_data, Data_test.event2id, 1), model,
              SimpleLossCompute(model.generator, criterion, model_opt))

    model.eval()

    print(
        run_epoch(data_gen(V, 30, 5), model,
                  SimpleLossCompute(model.generator, criterion, None)))

model.eval()
src = Variable(torch.LongTensor([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]).cuda())
src_mask = Variable(torch.ones(1, 1, 10))
print(greedy_decode(model, src, src_mask, max_len=10, start_symbol=1))
            tgt = torch.Tensor(tgt_batch_temp).cuda()
            src = Variable(src, requires_grad=False)
            tgt = Variable(tgt, requires_grad=False)
            #print(src.size())
            yield Batch(src, tgt, padding_dix)
            src_batch_temp = list()
            tgt_batch_temp = list()
    print('xxxxxxxx')


for epoch in range(10):
    print(epoch)
    model.train()
    run_epoch(
        data_gen(Data_test.trace_data,
                 Data_test.event2id,
                 batch_size=1000,
                 padding_dix=0), model,
        SimpleLossCompute(model.generator, criterion, model_opt))

    model.eval()

    print(
        run_epoch(
            data_gen(Data_test.trace_data,
                     Data_test.event2id,
                     batch_size=1,
                     padding_dix=0), model,
            SimpleLossCompute(model.generator, criterion, None)))

model.eval()
src = Variable(torch.LongTensor([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]).cuda())
Пример #3
0
            tgt = torch.Tensor(tgt_batch_temp).cuda()
            src = Variable(src, requires_grad=False)
            tgt = Variable(tgt, requires_grad=False)
            #print(src.size())
            yield Batch(src, tgt, padding_dix)
            src_batch_temp = list()
            tgt_batch_temp = list()


for epoch in range(10):
    print(epoch)
    model.train()
    # run_epoch(data_gen(train_list, Data_test.event2id, batch_size=200, padding_dix=0), model,
    #           SimpleLossCompute(model.generator, criterion, model_opt))
    run_epoch(
        data_gen(train_list, Data_test.event2id, batch_size=500,
                 padding_dix=0), model, TempLossCompute(criterion, model_opt))

    model.eval()

    print(
        run_epoch(
            data_gen(test_list,
                     Data_test.event2id,
                     batch_size=500,
                     padding_dix=0), model, TempLossCompute(criterion, None)))

model.eval()
print(
    eval_model(
        data_gen(test_list, Data_test.event2id, batch_size=500, padding_dix=0),