O'Reilly logo

Hands-On Natural Language Processing with Python by Rajalingappaa Shanmugamani, Rajesh Arumugam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Inference

Next, a function is created to perform the inference for the test data. The model was stored as a checkpoint in the preceding step, and it is used here for inference. The placeholders for the input data are defined, and a saver object is also defined, as follows:

def inference(test_x1, max_sent_len, batch_size=1024):    with tf.name_scope('Placeholders'):        x_pls1 = tf.placeholder(tf.int32, shape=[None, max_sent_len])        keep_prob = tf.placeholder(tf.float32)  # Dropout    predict = model(x_pls1, keep_prob)    saver = tf.train.Saver()    ckpt_path = tf.train.latest_checkpoint('.') 

Next, a session is created and the model is restored:

with tf.Session() as sess:        sess.run(tf.global_variables_initializer())        saver.restore(sess, ckpt_path)        print("Model ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required