示例#1
0
def execute(trial, n_epochs, timetags, word2vec, roles, coref):
    train_stories, dev_stories, test_stories = load_data(coref)
    all_stories = train_stories + test_stories + dev_stories

    if timetags:
        d = 556
    else:
        d = 300
    model = WeakMemoryNetwork(
        d, all_stories, timetags=timetags, word2vec=word2vec, roles=roles,
        coref=coref, path=path)

    pre_train_acc = compute_accuracy(train_stories, model)
    pre_test_acc = compute_accuracy(test_stories, model)

    for _ in range(n_epochs):
        for story in train_stories + dev_stories:
            model.train(story)

    post_train_acc = compute_accuracy(train_stories, model)
    post_test_acc = compute_accuracy(test_stories, model)

    return {
        'pre_train_acc': pre_train_acc,
        'pre_test_acc': pre_test_acc,
        'post_train_acc': post_train_acc,
        'post_test_acc': post_test_acc,
    }
示例#2
0
def execute(trial, n_epochs, timetags, shift, word2vec, roles, coref, preinit):
    train_stories, dev_stories, test_stories = load_data(coref)
    all_stories = train_stories + test_stories + dev_stories

    if coref:
        pos_file = 'coref_pos.pkl'
    else:
        pos_file = 'pos.pkl'

    model = WeakMemoryNetwork(
        300, 256, all_stories, timetags=timetags, word2vec=word2vec,
        roles=roles, coref=coref, preinit=preinit, shift=shift, path=path,
        pos_file=pos_file)

    pre_train_acc = compute_accuracy(train_stories, model)
    pre_test_acc = compute_accuracy(test_stories, model)

    for _ in range(n_epochs):
        for story in train_stories + dev_stories:
            model.train(story)

    post_train_acc = compute_accuracy(train_stories, model)
    post_test_acc = compute_accuracy(test_stories, model)

    return {
        'pre_train_acc': pre_train_acc,
        'pre_test_acc': pre_test_acc,
        'post_train_acc': post_train_acc,
        'post_test_acc': post_test_acc,
    }
示例#3
0
文件: run_best.py 项目: pblouw/memNN
with open('MCTest/mc160.dev.coref','rb') as f:
    dev_stories = clean(pickle.load(f))

with open('MCTest/mc160.train.coref','rb') as f:
    train_stories = clean(pickle.load(f))

with open('MCTest/mc160.test.coref','rb') as f:
    test_stories = clean(pickle.load(f))


all_stories = train_stories + test_stories + dev_stories

# initialize with all stories to get full vocab
model = WeakMemoryNetwork(
    300, 256, all_stories, timetags=True, word2vec=True, roles=True, coref=True,
    preinit=False, pos_file='coref_pos.pkl')

print 'Training Accuracy prior to training: ', compute_accuracy(train_stories, model)
print 'Testing Accuracy prior to training: ', compute_accuracy(test_stories, model)

# Train for a certain number of epochs
count = 0
for i in range(30):
    for story in train_stories + dev_stories:
        model.train(story)
    print 'Iteration ', count, ' complete!'
    count += 1


# Test for good generalization