The programming assigment has an error in 186
should be
#for line in eval_lines[1:3]:
eval_text = "\n".join(eval_lines)
eval_ids = line_to_tensor(eval_text, vocab)
input_ids, target_ids = split_input_target(eval_ids)
preds, status = model(tf.expand_dims(input_ids, 0), training=False, states=None, return_state=True)
#Get the log perplexity
log_ppx = log_perplexity(preds, tf.expand_dims(target_ids, 0))
print(f'The log perplexity and perplexity of your model are {log_ppx} and {np.exp(log_ppx)} respectively')
instead of
eval_text = "\n".join(eval_lines)
eval_ids = line_to_tensor([eval_text], vocab)
input_ids, target_ids = split_input_target(tf.squeeze(eval_ids, axis=0))
preds, status = model(tf.expand_dims(input_ids, 0), training=False, states=None, return_state=True)
#Get the log perplexity
log_ppx = log_perplexity(preds, tf.expand_dims(target_ids, 0))
print(f'The log perplexity and perplexity of your model are {log_ppx} and {np.exp(log_ppx)} respectively')
note line_to_tensor get a string (concat lines with ā\nā) and no squeez is necessary