Exemple #1
0
def main():
    """Reads the data and separates it into training data, validation data and
    testing data"""
    raw_data = reader.read_raw_data(vocab_size, data_dir)
    train_data, val_data, test_data, word_to_id, id_to_word, voc_size = raw_data

    print("Actual size of vocabulary: ", voc_size)

    start_time = time.time()
    if action == TRAIN:
        print("\n---------------Training start---------------")
        train_model(raw_data)
        # make_sentences(model, id_to_words)
        print("----------------Training end----------------\n")
    elif action == EVALUATE:
        print("\n---------------Evaluating start---------------")
        evaluate_model_from_file(
            test_data, "{0}/lang_model-{1}.meta".format(ckpt_dir, hidden_size),
            ckpt_dir)
        print("----------------Evaluating end----------------\n")
    elif action == BOTH:
        print("\n---------------Train/eval start---------------")
        train_model(raw_data)
        print("----------------Train/eval end----------------\n")
    elif action == GEN_SENTENCES:
        print("\n---------------Generate sentences begin---------------")
        do_sentence_completion(id_to_word)
        print("\n---------------Generate sentences end  ---------------")
    end_time = time.time()
    print("Total time: {0}".format(end_time - start_time))
Exemple #2
0
def main(_):

    # get config
    config = get_config('Train')
    test_config = get_config('Test')

    raw_data, columns_name, norlizer = reader.read_raw_data("data/raw.txt")
    miss_data = reader.read_missing_data("data/miss_data.txt", norlizer,
                                         FLAGS.embedding_size)

    os.environ['CUDA_VISIBLE_DEVICES'] = '0'
    gpu_config = tf.ConfigProto()
    gpu_config.gpu_options.allow_growth = True

    with tf.Session(config=gpu_config) as session:
        initializer = tf.random_uniform_initializer(-config.init_scale,
                                                    config.init_scale)

        with tf.variable_scope("LIMELSTM", reuse=None,
                               initializer=initializer):
            model = LIMELSTM(is_training=True, config=config,
                             FLAGS=FLAGS)  #train model,is_trainable=True
        with tf.variable_scope("LIMELSTM", reuse=True,
                               initializer=initializer):
            test_model = LIMELSTM(is_training=False,
                                  config=test_config,
                                  FLAGS=FLAGS)  #test model,is_trainable=False

        tf.initialize_all_variables().run()
        model._lr = 0.01
        new_lr = model._lr
        for i in xrange(120):
            print 'Number of iterations:', i
            _ = run_epoch(session, model, miss_data, model.train_op)
            if i >= 10 and i % 10 == 0:
                if new_lr > 0.005: new_lr = new_lr - 0.003
                else: new_lr = new_lr * 0.5
                model.assign_lr(session, new_lr)
        prediction = run_epoch(session, test_model, miss_data, tf.no_op())
        print 'RMSE:', reader.RMSE_Metric(
            raw_data,
            miss_data,
            np.concatenate(
                (miss_data[0, :].reshape(1, -1), np.array(prediction)),
                axis=0),
            missing_flag=FLAGS.missing_flag)
Exemple #3
0
from __future__ import print_function, division
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
import reader

data, size, color_dict = reader.read_raw_data()
out_size = len(color_dict)
num_epochs = 500
lenx, leny = data.shape
num_classes = size + 1
total_series_length = lenx * (leny - 1)
truncated_backprop_length = leny - 1
state_size = 1
echo_step = 1
batch_size = 5
#batch_size = 3
num_layers = 4
num_batches = total_series_length // batch_size // truncated_backprop_length


def one_hot(num):
    arr = np.zeros(out_size)
    arr[num] = 1
    return arr


def generateData():
    x = data[:, 0:leny - 1]
    y = data[:, leny - 1:leny]
    x = x.reshape((lenx * (leny - 1), 1))
Exemple #4
0
#  See the License for the specific language governing permissions and
#  limitations under the License.
"""Convolutional Neural Network Estimator for MNIST, built with tf.layers."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import numpy as np
import tensorflow as tf
import reader
import math

tf.logging.set_verbosity(tf.logging.INFO)

data, labels, class_num = reader.read_raw_data()  # Returns np.array
CLASS_NUM = class_num
lenx, leny = data.shape
LAYER_SHAPE_X = int(math.sqrt(leny))
LAYER_SHAPE_Y = int(math.sqrt(leny))
TRAIN_DATA = data[0 : lenx - 20, :]
TRAIN_LABELS = labels[0 : lenx - 20, :]
#train_labels = reader.readtrainlabel("train")
PRED_DATA = data[lenx - 20 : lenx, :]
PRED_LABELS = labels[lenx - 20 : lenx, :]  # Returns np.array
#print(train_data.shape)


def cnn_model_fn(features, labels, mode):
  """Model function for CNN."""
  # Input Layer