本文整理匯總了Python中utils.TextLoader.read_dataset方法的典型用法代碼示例。如果您正苦於以下問題:Python TextLoader.read_dataset方法的具體用法?Python TextLoader.read_dataset怎麽用?Python TextLoader.read_dataset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類utils.TextLoader
的用法示例。
在下文中一共展示了TextLoader.read_dataset方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test
# 需要導入模塊: from utils import TextLoader [as 別名]
# 或者: from utils.TextLoader import read_dataset [as 別名]
def test(test_args):
start = time.time()
with open(os.path.join(test_args.save_dir, 'config.pkl')) as f:
args = cPickle.load(f)
data_loader = TextLoader(args, train=False)
test_data = data_loader.read_dataset(test_args.test_file)
args.word_vocab_size = data_loader.word_vocab_size
print "Word vocab size: " + str(data_loader.word_vocab_size) + "\n"
# Model
lm_model = WordLM
print "Begin testing..."
# If using gpu:
# gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.9)
# gpu_config = tf.ConfigProto(log_device_placement=False, gpu_options=gpu_options)
# add parameters to the tf session -> tf.Session(config=gpu_config)
with tf.Graph().as_default(), tf.Session() as sess:
initializer = tf.random_uniform_initializer(-args.init_scale, args.init_scale)
with tf.variable_scope("model", reuse=None, initializer=initializer):
mtest = lm_model(args, is_training=False, is_testing=True)
# save only the last model
saver = tf.train.Saver(tf.all_variables())
tf.initialize_all_variables().run()
ckpt = tf.train.get_checkpoint_state(args.save_dir)
if ckpt and ckpt.model_checkpoint_path:
saver.restore(sess, ckpt.model_checkpoint_path)
test_perplexity = run_epoch(sess, mtest, test_data, data_loader, tf.no_op())
print("Test Perplexity: %.3f" % test_perplexity)
print("Test time: %.0f" % (time.time() - start))