Пример #1
0
init = tf.global_variables_initializer()

# launch the graph
saver = tf.train.Saver(tf.global_variables(), max_to_keep=1)
tf.add_to_collection('accuracy', accuracy)
tf.add_to_collection('x1', x1)
tf.add_to_collection('x2', x2)
tf.add_to_collection('y', y)

with tf.Session() as sess:
    sess.run(init)
    step = 1
    model = data_helpers.load_model(
        './Data/GoogleNews-vectors-negative300.bin')
    if test == 'PDTB':
        sentences1, sentences2, labels = data_helpers.load_labels_and_data_PDTB(
            model, './Data/PDTB_implicit/train.txt')
    elif test == 'SICK':
        sentences1, sentences2, labels = data_helpers.load_data_SICK(
            model, './Data/SICK/train.txt')
    total = 0

    while total < training_iters:
        start = total % len(sentences1)
        end = (total + batch_size) % len(sentences1)
        if end <= start:
            end = len(sentences1)
        batch_x1 = sentences1[start:end]
        batch_x2 = sentences2[start:end]
        batch_y = labels[start:end]
        total += (len(batch_x1))
        sess.run(optimizer, feed_dict={x1: batch_x1, x2: batch_x2, y: batch_y})
Пример #2
0
# launch the graph
saver = tf.train.Saver(tf.global_variables(), max_to_keep=1)
tf.add_to_collection('accuracy', accuracy)
tf.add_to_collection('x1', x1)
tf.add_to_collection('x2', x2)
tf.add_to_collection('y', y)

with tf.Session() as sess:
    sess.run(init)
    step = 1
    model = data_helpers.load_model(
        './Data/GoogleNews-vectors-negative300.bin')
    if test == 'PDTB':
        sentences1, sentences2, labels, lengths1, lengths2 = \
            data_helpers.load_labels_and_data_PDTB(model, './Data/PDTB_implicit/train.txt', False, True, True)
    elif test == 'SICK':
        sentences1, sentences2, labels, lengths1, lengths2 = \
            data_helpers.load_data_SICK(model, './Data/SICK/train.txt', False, True, True)
    total = 0

    while total < training_iters:
        start = total % len(sentences1)
        end = (total + batch_size) % len(sentences1)
        if end <= start:
            end = len(sentences1)
        batch_x1 = sentences1[start:end]
        batch_x2 = sentences2[start:end]
        batch_x1_lengths = lengths1[start:end]
        batch_x2_lengths = lengths2[start:end]
        batch_y = labels[start:end]