Пример #1
0
    return np.exp(loss / label.size)


if __name__ == '__main__':
    batch_size = 128
    buckets = [10, 20, 30, 40, 50, 60]
    num_hidden = 200
    num_embed = 200
    num_lstm_layer = 2

    num_epoch = 2
    learning_rate = 0.01
    momentum = 0.0

    contexts = [mx.context.gpu(i) for i in range(1)]
    vocab = default_build_vocab(os.path.join(data_dir, 'ptb.train.txt'))

    init_h = [
        mx.io.DataDesc('LSTM_state', (num_lstm_layer, batch_size, num_hidden),
                       layout='TNC')
    ]
    init_c = [
        mx.io.DataDesc('LSTM_state_cell',
                       (num_lstm_layer, batch_size, num_hidden),
                       layout='TNC')
    ]
    init_states = init_c + init_h

    data_train = BucketSentenceIter(os.path.join(data_dir, 'ptb.train.txt'),
                                    vocab,
                                    buckets,
Пример #2
0
    return data


batch_size = 20
seq_len = 35
num_hidden = 400
num_embed = 200
num_lstm_layer = 8
num_round = 25
learning_rate = 0.1
wd = 0.
momentum = 0.0
max_grad_norm = 5.0
update_period = 1

dic = default_build_vocab("./data/ptb.train.txt")
vocab = len(dic)

# static buckets
buckets = [8, 16, 24, 32, 60]

init_c = [('l%d_init_c' % l, (batch_size, num_hidden))
          for l in range(num_lstm_layer)]
init_h = [('l%d_init_h' % l, (batch_size, num_hidden))
          for l in range(num_lstm_layer)]
init_states = init_c + init_h

X_train_batch = BucketSentenceIter("./data/ptb.train.txt",
                                   dic,
                                   buckets,
                                   batch_size,
Пример #3
0
    #buckets = [32]
    num_hidden = 200
    num_embed = 200
    num_lstm_layer = 2

    #num_epoch = 25
    num_epoch = 2
    learning_rate = 0.01
    momentum = 0.0

    # dummy data is used to test speed without IO
    dummy_data = False

    contexts = [mx.context.gpu(i) for i in range(1)]

    vocab = default_build_vocab(os.path.join(data_dir, "ptb.train.txt"))

    init_c = [('l%d_init_c'%l, (batch_size, num_hidden)) for l in range(num_lstm_layer)]
    init_h = [('l%d_init_h'%l, (batch_size, num_hidden)) for l in range(num_lstm_layer)]
    init_states = init_c + init_h

    data_train = BucketSentenceIter(os.path.join(data_dir, "ptb.train.txt"), vocab,
                                    buckets, batch_size, init_states)
    data_val = BucketSentenceIter(os.path.join(data_dir, "ptb.valid.txt"), vocab,
                                  buckets, batch_size, init_states)

    if dummy_data:
        data_train = DummyIter(data_train)
        data_val = DummyIter(data_val)

    state_names = [x[0] for x in init_states]
Пример #4
0
    buckets = []
    num_hidden = 200
    num_embed = 200
    num_lstm_layer = 2

    num_epoch = 25
    learning_rate = 0.01
    momentum = 0.0

    # dummy data is used to test speed without IO
    dummy_data = False

    #contexts = [mx.context.gpu(i) for i in range(1)]
    contexts = mx.context.cpu()

    vocab = default_build_vocab("./data/ptb.train.txt")

    def sym_gen(seq_len):
        return gru_unroll(num_lstm_layer, seq_len, len(vocab),
                           num_hidden=num_hidden, num_embed=num_embed,
                           num_label=len(vocab))

    init_h = [('l%d_init_h'%l, (batch_size, num_hidden)) for l in range(num_lstm_layer)]

    data_train = BucketSentenceIter("./data/ptb.train.txt", vocab,
                                    buckets, batch_size, init_h)
    data_val = BucketSentenceIter("./data/ptb.valid.txt", vocab,
                                  buckets, batch_size, init_h)

    if dummy_data:
        data_train = DummyIter(data_train)
Пример #5
0
stream = p.open(format=p.get_format_from_width(2),
                channels=1,
                rate=44100,
                output=True)

if __name__ == '__main__':
    batch_size = 1
    buckets = 30
    num_hidden = 2500
    num_label = 1500
    num_lstm_layer = 2
    num_epoch = 326

    print(batch_size, buckets, num_hidden, num_lstm_layer, num_epoch)

    img_data, wave_data = default_build_vocab("./data/data/2.mp4",
                                              "./data/data/2.mp3")

    init_c = [('l%d_init_c' % l, (batch_size, num_hidden))
              for l in range(num_lstm_layer)]
    init_h = [('l%d_init_h' % l, (batch_size, num_hidden))
              for l in range(num_lstm_layer)]
    init_states = init_c + init_h
    data_train = BucketSentenceIter(img_data, wave_data, buckets, batch_size,
                                    init_states, num_label)
    model = mx.model.FeedForward.load('model/lip',
                                      num_epoch,
                                      ctx=mx.context.gpu(1),
                                      num_epoch=500,
                                      learning_rate=0.5)
    import logging
    head = '%(asctime)-15s %(message)s'
Пример #6
0
    buckets = [32]
    #buckets = []
    num_hidden = 200
    num_embed = 200
    num_lstm_layer = 2

    num_epoch = 25
    learning_rate = 0.01
    momentum = 0.0

    # dummy data is used to test speed without IO
    dummy_data = False

    contexts = [mx.context.gpu(i) for i in range(N)]

    vocab = default_build_vocab("./data/sherlockholmes.train.txt")

    def sym_gen(seq_len):
        return lstm_unroll(num_lstm_layer, seq_len, len(vocab),
                           num_hidden=num_hidden, num_embed=num_embed,
                           num_label=len(vocab))

    init_c = [('l%d_init_c'%l, (batch_size, num_hidden)) for l in range(num_lstm_layer)]
    init_h = [('l%d_init_h'%l, (batch_size, num_hidden)) for l in range(num_lstm_layer)]
    init_states = init_c + init_h

    data_train = BucketSentenceIter("./data/sherlockholmes.train.txt", vocab,
                                    buckets, batch_size, init_states)
    data_val = BucketSentenceIter("./data/sherlockholmes.valid.txt", vocab,
                                  buckets, batch_size, init_states)
Пример #7
0
    return np.exp(loss / label.size)


if __name__ == '__main__':
    batch_size = 128
    buckets = [10, 20, 30, 40, 50, 60]
    num_hidden = 200
    num_embed = 200
    num_lstm_layer = 2

    num_epoch = 2
    learning_rate = 0.01
    momentum = 0.0

    contexts = [mx.context.gpu(i) for i in range(4)]
    vocab = default_build_vocab(
        os.path.join(data_dir, 'sherlockholmes.train.txt'))

    init_h = [('LSTM_init_h', (batch_size, num_lstm_layer, num_hidden))]
    init_c = [('LSTM_init_c', (batch_size, num_lstm_layer, num_hidden))]
    init_states = init_c + init_h

    data_train = BucketSentenceIter(
        os.path.join(data_dir, 'sherlockholmes.train.txt'), vocab, buckets,
        batch_size, init_states)
    data_val = BucketSentenceIter(
        os.path.join(data_dir, 'sherlockholmes.valid.txt'), vocab, buckets,
        batch_size, init_states)

    def sym_gen(seq_len):
        data = mx.sym.Variable('data')
        label = mx.sym.Variable('softmax_label')
Пример #8
0
    return loss / pred.shape[0]


if __name__ == '__main__':
    batch_size = 1
    buckets = 15
    num_hidden = 1500
    num_label = 1764
    num_lstm_layer = 2
    num_epoch = 500
    learning_rate = 1
    momentum = 0.0
    print(batch_size, buckets, num_hidden, num_lstm_layer, num_epoch,
          learning_rate)
    contexts = [mx.context.gpu(0)]
    img_data, wave_data = default_build_vocab("./data/train_x_2.mp4",
                                              "./data/train_y_2.mp3")
    img_data1, wave_data1 = default_build_vocab("./data/train_x_2.mp4",
                                                "./data/train_y_2.mp3")

    def sym_gen(seq_len):
        return bi_lstm_unroll(num_lstm_layer,
                              seq_len,
                              len(img_data),
                              num_hidden=num_hidden,
                              num_label=num_label)

    init_c = [('l%d_init_c' % l, (batch_size, num_hidden))
              for l in range(num_lstm_layer)]
    init_h = [('l%d_init_h' % l, (batch_size, num_hidden))
              for l in range(num_lstm_layer)]
    init_states = init_c + init_h
Пример #9
0
    buckets = []
    num_hidden = 200
    num_embed = 200
    num_lstm_layer = 2

    num_epoch = 25
    learning_rate = 0.01
    momentum = 0.0

    # dummy data is used to test speed without IO
    dummy_data = False

    #contexts = [mx.context.gpu(i) for i in range(1)]
    contexts = mx.context.cpu()

    vocab = default_build_vocab("./data/sherlockholmes.train.txt")

    def sym_gen(seq_len):
        return gru_unroll(num_lstm_layer, seq_len, len(vocab),
                           num_hidden=num_hidden, num_embed=num_embed,
                           num_label=len(vocab))

    init_h = [('l%d_init_h'%l, (batch_size, num_hidden)) for l in range(num_lstm_layer)]

    data_train = BucketSentenceIter("./data/sherlockholmes.train.txt", vocab,
                                    buckets, batch_size, init_h)
    data_val = BucketSentenceIter("./data/sherlockholmes.valid.txt", vocab,
                                  buckets, batch_size, init_h)

    if dummy_data:
        data_train = DummyIter(data_train)
Пример #10
0
    return np.exp(loss / label.size)


if __name__ == '__main__':
    batch_size = 128
    buckets = [10, 20, 30, 40, 50, 60]
    num_hidden = 200
    num_embed = 200
    num_lstm_layer = 2

    num_epoch = 2
    learning_rate = 0.01
    momentum = 0.0

    contexts = [mx.context.gpu(i) for i in range(4)]
    vocab = default_build_vocab(os.path.join(data_dir, 'sherlockholmes.train.txt'))

    init_h = [('LSTM_init_h', (batch_size, num_lstm_layer, num_hidden))]
    init_c = [('LSTM_init_c', (batch_size, num_lstm_layer, num_hidden))]
    init_states = init_c + init_h

    data_train = BucketSentenceIter(os.path.join(data_dir, 'sherlockholmes.train.txt'),
                                    vocab, buckets, batch_size, init_states)
    data_val = BucketSentenceIter(os.path.join(data_dir, 'sherlockholmes.valid.txt'),
                                  vocab, buckets, batch_size, init_states)

    def sym_gen(seq_len):
        data = mx.sym.Variable('data')
        label = mx.sym.Variable('softmax_label')
        embed = mx.sym.Embedding(data=data, input_dim=len(vocab),
                                 output_dim=num_embed, name='embed')
Пример #11
0
    return loss / pred.shape[0]


if __name__ == '__main__':
    batch_size = 1
    buckets = 30
    num_hidden = 2500
    num_label = 1445
    num_lstm_layer = 2
    num_epoch = 500
    learning_rate = 1
    momentum = 0.0
    print(batch_size, buckets, num_hidden, num_lstm_layer, num_epoch,
          learning_rate)
    contexts = [mx.context.gpu(0)]
    img_data, wave_data = default_build_vocab("./data/4.mkv", "./data/4.mp3")

    def sym_gen(seq_len):
        return lstm_unroll(num_lstm_layer,
                           seq_len,
                           len(img_data),
                           num_hidden=num_hidden,
                           num_label=num_label)

    init_c = [('l%d_init_c' % l, (batch_size, num_hidden))
              for l in range(num_lstm_layer)]
    init_h = [('l%d_init_h' % l, (batch_size, num_hidden))
              for l in range(num_lstm_layer)]
    init_states = init_c + init_h

    data_train = BucketSentenceIter(img_data, wave_data, buckets, batch_size,
    batch_size = args.batch_size
    buckets = [args.seq_len]
    num_hidden = args.num_hidden
    num_embed = args.num_embed
    num_lstm_layer = args.lstm_layer

    num_epoch = 1
    learning_rate = 0.01
    momentum = 0.0

    # dummy data is used to test speed without IO
    dummy_data = False

    contexts = [mx.context.gpu(i) for i in range(1)]

    vocab = default_build_vocab(args.data_path+"/ptb.train.txt")

    def sym_gen(seq_len):
        return lstm_unroll(num_lstm_layer, seq_len, 10000,
                           num_hidden=num_hidden, num_embed=num_embed,
                           num_label=10000)

    init_c = [('l%d_init_c'%l, (batch_size, num_hidden)) for l in range(num_lstm_layer)]
    init_h = [('l%d_init_h'%l, (batch_size, num_hidden)) for l in range(num_lstm_layer)]
    init_states = init_c + init_h

    data_train = BucketSentenceIter(args.data_path+"/ptb.train.txt", vocab,
                                    buckets, batch_size, args.num_batch, init_states)

    if dummy_data:
        data_train = DummyIter(data_train)