if __name__ == '__main__': parser = argparse.ArgumentParser( description='Sample from a trained SeqGAN model.') parser.add_argument('sample_len', metavar='N', type=int, help='length of sample to generate') parser.add_argument('-t', '--dictionary', default='dictionary.pkl', type=str, help='path to dictionary file') parser.add_argument('-d', '--logdir', default='model/', type=str, help='directory of the trained model') parser.add_argument('-c', '--only_cpu', default=True, action='store_true', help='if set, only build weights on cpu') args = parser.parse_args() if not os.path.exists(args.dictionary): raise ValueError('No dictionary file found: "%s". To build it, ' 'run train.py' % args.dictionary) _, rev_dict = utils.get_dictionary(None, dfile=args.dictionary) num_classes = len(rev_dict) sess = tf.Session() model = SeqGAN(sess, num_classes, logdir=args.logdir, only_cpu=args.only_cpu) model.build() model.load(ignore_missing=True) g = model.generate(args.sample_len) print('Generated text:', utils.detokenize(g, rev_dict))
type=int, help='learning phase (None for synchronized)') parser.add_argument('-d', '--logdir', default='model/', type=str, help='where to store the trained model') args = parser.parse_args() # Turns on logging. import logging root = logging.getLogger() root.setLevel(logging.DEBUG) dictionary, rev_dict = utils.get_dictionary(args.text) num_classes = len(dictionary) iterator = utils.tokenize(args.text, dictionary, batch_size=args.batch_size, seq_len=args.seq_len) sess = tf.Session() model = SeqGAN(sess, num_classes, logdir=args.logdir, learn_phase=args.learn_phase, only_cpu=args.only_cpu) model.build() model.load(ignore_missing=True)
import logging import gensim import nltk from gensim.models import Word2Vec from nltk.data import load import numpy as np import utils dictionary = utils.get_dictionary() lemma_dictionary = utils.get_lemma_dictionary() ''' A vector denoting a single feature of a word ''' class FeatureVector(object): def get_vector(self): self.generate_vector() return self.vector def generate_vector(self): self.vector = [] def __init__(self, entity, document=None): self.entity = entity self.vector = [] self.document = document '''