embedding_size = embedding.embedding_matrix.shape[1]

    print('Building model.')
    model = Manhattan_LSTM(args.data_name,
                           args.hidden_size,
                           embedding.embedding_matrix,
                           use_embedding=True,
                           train_embedding=True)
    if use_cuda: model = model.cuda()

    model.init_weights()

    print("Training Network.")
    train_network = Train_Network(model, data.index2word)

    run_iterations = Run_Iterations(args.data_name,
                                    train_network,
                                    data.x_train,
                                    data.y_train,
                                    data.index2word,
                                    args.batch_size,
                                    args.num_iters,
                                    args.learning_rate,
                                    tracking_pair=args.tracking_pair,
                                    x_val=data.x_val,
                                    y_val=data.y_val)
    run_iterations.train_iters()
    run_iterations.evaluate_randomly()

    torch.save(model.state_dict(), './manhattan_lstm.pt')
Exemplo n.º 2
0
    if use_cuda:
        encoder = encoder.cuda()
        decoder = decoder.cuda()

    print("Training Network.")

    train_network = Train_Network(encoder,
                                  decoder,
                                  index2word,
                                  num_layers=num_layers)

    run_iterations = Run_Iterations(train_network,
                                    train_in_seq,
                                    train_out_seq,
                                    train_lengths,
                                    train_speakers,
                                    train_addressees,
                                    index2word,
                                    batch_size,
                                    num_iters,
                                    learning_rate,
                                    tracking_pair=tracking_pair,
                                    dev_in_seq=dev_in_seq,
                                    dev_out_seq=dev_out_seq,
                                    dev_input_lengths=dev_lengths,
                                    dev_speakers=dev_speakers,
                                    dev_addressees=dev_addressees)

    run_iterations.train_iters()
    run_iterations.evaluate_randomly()
Exemplo n.º 3
0
        decoder = decoder.cuda()

    print("Training Network.")

    train_network = Train_Network(encoder,
                                  decoder,
                                  data_p.index2word,
                                  num_layers=args.num_layers)

    run_iterations = Run_Iterations(train_network,
                                    data_p.x_train,
                                    data_p.y_train,
                                    data_p.train_lengths,
                                    data_p.index2word,
                                    args.batch_size,
                                    args.num_iters,
                                    args.learning_rate,
                                    fold_size=args.fold_size,
                                    track_minor=args.track_minor,
                                    tracking_pair=args.tracking_pair,
                                    val_in_seq=data_p.x_val,
                                    val_out_seq=data_p.y_val,
                                    val_lengths=data_p.val_lengths)
    run_iterations.train_iters()
    run_iterations.evaluate_randomly()

    if not args.encoder_parameters.endswith('.pt'):
        args.encoder_parameters += '.pt'
    if not args.decoder_parameters.endswith('.pt'):
        args.decoder_parameters += '.pt'

    torch.save(encoder.state_dict(), args.encoder_parameters)
Exemplo n.º 4
0
    print('--------------------------------------\n')

    print('Reading Data.')
    data = Data(args.data_name, args.data_file, args.training_ratio, args.max_len)

    print('\n')
    print('Number of training samples        :', len(data.x_train))
    print('Number of validation samples      :', len(data.x_val))
    print('Maximum sequence length           :', args.max_len)
    print('\n')

    print('Building Embedding Matrix')
    embedding = Get_Embedding(args.embd_file, data.word2index,args)
    embedding_size = embedding.embedding_matrix.shape[1]

    print('Building model.')
    model = Manhattan_LSTM(embedding.embedding_matrix, args)
    if use_cuda: model = model.cuda()

    model.init_weights() # set weights to be same in lstm1 and lstm2

    print("Training Network.")
    train_network = Train_Network(model, data.index2word)
    run_iterations = Run_Iterations(train_network, data.x_train, data.x_train_char, data.y_train, data.index2word,
                                    args.batch_size, args.num_iters, args.learning_rate,
                                    tracking_pair=args.tracking_pair, x_val=data.x_val, x_val_char = data.x_val_char, y_val=data.y_val)
    run_iterations.train_iters()
    #run_iterations.evaluate_randomly()

    torch.save(model.state_dict(), './manhattan_lstm.pt')