示例#1
0
    def __init__(self):
        self.Config = main.Config()
        self.vocab_size = self.Config.vocab_size
        self.special_chars = self.Config.special_chars
        self.num_of_questions = self.Config.total_examples
        self.num_of_paragraphs = self.Config.num_of_paragraphs
        self.glove_dimensionality = self.Config.glove_dimensionality

        self.largest_num_of_sentences = 0
        self.largest_num_of_words = 0
        self.glove_lookup = self.initialise_glove_embeddings()
        self.glove_lookup_dict = {}

        for entry in self.glove_lookup:
            index = entry[0]
            vector = entry[1]
            self.glove_lookup_dict[index] = vector

        self.glove_lookup_dict_reversed = {}
        self.questions_list, self.paragraphs_list, self.answers_list = self.read_squad(
        )
        self.largest_num_of_sentences, self.largest_num_of_words, self.largest_num_of_words_any_paragraph = self.count_words_paragraphs_in_squad(
        )
        self.largest_num_of_words_in_answer = self.get_largest_num_of_words_in_answer(
        )
示例#2
0
    def __init__(self):
        self.Config = main.Config()
        self.d = self.Config.d
        self.num_of_batches = self.Config.num_of_batches
        self.l_rate = self.Config.l_rate
        self.total_examples = self.Config.total_examples
        self.examples_per_batch = self.total_examples / self.num_of_batches
        self.clip_norm = self.Config.clip_norm
        self.num_of_epochs = self.Config.num_of_epochs

        self.util = Data.Util()
        self.unk_answer = self.util.get_one_hot_encoded_from_glove("<unk>")
        self.largest_num_of_words_any_paragraph = self.util.largest_num_of_words_any_paragraph
        self.largest_num_of_words_in_answer = self.util.get_largest_num_of_words_in_answer(
        )
        self.largest_num_of_words_in_question = self.util.get_largest_num_of_words_in_question(
        )

        self.question = tf.placeholder(
            tf.float32,
            shape=(self.largest_num_of_words_in_question,
                   self.util.glove_dimensionality),
            name="question")
        self.text = tf.placeholder(
            tf.float32,
            shape=(self.largest_num_of_words_any_paragraph,
                   self.util.glove_dimensionality),
            name="text")
        self.answer = tf.placeholder(
            tf.float32,
            shape=(self.largest_num_of_words_in_answer, self.util.vocab_size))
示例#3
0
import tensorflow as tf
import numpy as np
import main

Config = main.Config()
glove_dimensionality = Config.glove_dimensionality
d = Config.d


class Memory:
    def __init__(self, text, util):
        self.A = tf.Variable(tf.random_normal([
            util.largest_num_of_words_any_paragraph, util.glove_dimensionality,
            d
        ],
                                              stddev=0.1),
                             name="A")
        self.C = tf.Variable(tf.random_normal([
            util.largest_num_of_words_any_paragraph, util.glove_dimensionality,
            d
        ],
                                              stddev=0.1),
                             name="C")

        self.m = tf.squeeze(tf.matmul(text, self.A), 1)
        self.c = tf.squeeze(tf.matmul(text, self.C), 1)
示例#4
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu May 10 15:48:14 2018

@author: hellcat
"""

import main
import tensorflow as tf
from general_net import net
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image

opt = main.Config()
slim = tf.contrib.slim
config = tf.ConfigProto()
config.gpu_options.allow_growth = True

text_img = './000000000036.jpg'
model_path = "./logs/model"

img_raw = tf.gfile.FastGFile(text_img, 'rb').read()
img = tf.image.decode_jpeg(img_raw)
if img.dtype != tf.float32:
    img = tf.image.convert_image_dtype(img, dtype=tf.float32)
generated = net(tf.expand_dims(img, axis=0), training=False)

with tf.Session() as sess:
    saver = tf.train.Saver()
示例#5
0
 def test_init(self):
     config = main.Config('testserver', 'testnick')
     self.assertEqual(config.nickname, 'testnick')
     self.assertEqual(config.server, 'testserver')