Exemple #1
0
def div3_bin_seq():
    train = read_file('data/train_div3_bin')
    dev = read_file('data/dev_div3_bin')

    vocab = ['0', '1']
    labels = ['0', '1']
    w2i = {w: i for i, w in enumerate(vocab)}
    l2i = {l: i for i, l in enumerate(labels)}

    dynet_model = DynetModel(w2i, l2i, 64, layers=16)
    dynet_model.train(train, dev, iter_num=20)
Exemple #2
0
def credit_card_seq():
    train = read_file('data/train_credit_card')
    dev = read_file('data/dev_credit_card')

    vocab = [str(i) for i in range(10)] + ['-']
    labels = ['0', '1']
    w2i = {w: i for i, w in enumerate(vocab)}
    l2i = {l: i for i, l in enumerate(labels)}

    dynet_model = DynetModel(w2i, l2i, layers=4)
    dynet_model.train(train, dev, iter_num=20)
Exemple #3
0
def anbn_seq():
    train = read_file('data/train_anbn')
    dev = read_file('data/dev_anbn')

    vocab = ['a', 'b']
    labels = ['0', '1']
    w2i = {w: i for i, w in enumerate(vocab)}
    l2i = {l: i for i, l in enumerate(labels)}

    dynet_model = DynetModel(w2i, l2i, layers=8)
    dynet_model.train(train, dev, iter_num=10)
Exemple #4
0
def pow_2_seq():
    train = read_file('data/train_pow')
    dev = read_file('data/dev_pow')

    vocab = ['a', 'b']
    labels = ['0', '1']
    w2i = {w: i for i, w in enumerate(vocab)}
    l2i = {l: i for i, l in enumerate(labels)}

    dynet_model = DynetModel(w2i, l2i)
    dynet_model.train(train, dev, iter_num=2)
Exemple #5
0
def even_seq():
    train = read_file('data/train_even')
    dev = read_file('data/dev_even')

    vocab = ['a']
    labels = ['0', '1']
    w2i = {w: i for i, w in enumerate(vocab)}
    l2i = {l: i for i, l in enumerate(labels)}

    dynet_model = DynetModel(w2i, l2i, 128, 64, 32)
    dynet_model.train(train, dev, iter_num=10)
Exemple #6
0
from part1.DynetModel import DynetModel


def read_file(filename):
    f = open(filename, 'r')
    lines = f.read().splitlines()
    f.close()
    return lines


if __name__ == '__main__':
    print 'start'

    train = read_file('train_set')
    test = read_file('test_set')

    vocab = map(str, range(1, 10)) + ['a', 'b', 'c', 'd']
    labels = ['pos', 'neg']
    w2i = {w: i for i, w in enumerate(vocab)}  # map letter to index
    l2i = {l: i for i, l in enumerate(labels)}  # map label to index

    net = DynetModel(w2i, l2i)
    net.train(train, test)