本文整理匯總了Python中data_utils.LM1BDataset方法的典型用法代碼示例。如果您正苦於以下問題:Python data_utils.LM1BDataset方法的具體用法?Python data_utils.LM1BDataset怎麽用?Python data_utils.LM1BDataset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類data_utils
的用法示例。
在下文中一共展示了data_utils.LM1BDataset方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _EvalModel
# 需要導入模塊: import data_utils [as 別名]
# 或者: from data_utils import LM1BDataset [as 別名]
def _EvalModel(dataset):
"""Evaluate model perplexity using provided dataset.
Args:
dataset: LM1BDataset object.
"""
sess, t = _LoadModel(FLAGS.pbtxt, FLAGS.ckpt)
current_step = t['global_step'].eval(session=sess)
sys.stderr.write('Loaded step %d.\n' % current_step)
data_gen = dataset.get_batch(BATCH_SIZE, NUM_TIMESTEPS, forever=False)
sum_num = 0.0
sum_den = 0.0
perplexity = 0.0
for i, (inputs, char_inputs, _, targets, weights) in enumerate(data_gen):
input_dict = {t['inputs_in']: inputs,
t['targets_in']: targets,
t['target_weights_in']: weights}
if 'char_inputs_in' in t:
input_dict[t['char_inputs_in']] = char_inputs
log_perp = sess.run(t['log_perplexity_out'], feed_dict=input_dict)
if np.isnan(log_perp):
sys.stderr.error('log_perplexity is Nan.\n')
else:
sum_num += log_perp * weights.mean()
sum_den += weights.mean()
if sum_den > 0:
perplexity = np.exp(sum_num / sum_den)
sys.stderr.write('Eval Step: %d, Average Perplexity: %f.\n' %
(i, perplexity))
if i > FLAGS.max_eval_steps:
break
示例2: main
# 需要導入模塊: import data_utils [as 別名]
# 或者: from data_utils import LM1BDataset [as 別名]
def main(unused_argv):
vocab = data_utils.CharsVocabulary(FLAGS.vocab_file, MAX_WORD_LEN)
if FLAGS.mode == 'eval':
dataset = data_utils.LM1BDataset(FLAGS.input_data, vocab)
_EvalModel(dataset)
elif FLAGS.mode == 'sample':
_SampleModel(FLAGS.prefix, vocab)
elif FLAGS.mode == 'dump_emb':
_DumpEmb(vocab)
elif FLAGS.mode == 'dump_lstm_emb':
_DumpSentenceEmbedding(FLAGS.sentence, vocab)
else:
raise Exception('Mode not supported.')