Skip to content

How to do inference on a single sentence #30

@parulsingh23

Description

@parulsingh23

I am running this model in a Google Colab notebook. However, after following the steps in the ReadMe file to train the model, I'm not sure how I can apply the model to provide an inference on a given sentence. So for example, what command would I provide to execute the model on a negative sentence of "I do not like this food" to generate a positive sentiment of "I like this food". Or is there no such command and would I need to place my input (negative sentiment) sentence in a file and call a function?

I had tried creating a directory called 'evaluatingWithNegative' located in 'data/evaluatingWithNegative' (adjacent to the Yelp dataset). In that directory, I placed a file named "x.0" where I put the sentence "i do not like this food ."
I then ran the commands

%cd classifier
!python textcnn.py --mode evaluate

And besides some warning statements, it outputted:

Saving classifier result at: /content/DualRL/tmp/cls_result_yelp.txt
Test accuracy: 96.40

I then ran

%cd nmt
!python nmt.py --mode inference --nmt_direction 0-1

Which outputted:

WARNING: The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
  * https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
  * https://github.com/tensorflow/addons
If you depend on functionality not listed there, please file an issue.

A=0, B=1
Vocabulary size:src:9353
Use x'->y to update model f(x->y)
WARNING:tensorflow:From ../utils/data.py:61: group_by_window (from tensorflow.contrib.data.python.ops.grouping) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.data.experimental.group_by_window(...)`.
WARNING:tensorflow:From ../utils/data.py:23: to_int64 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.cast instead.
WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/tensorflow/python/data/ops/dataset_ops.py:1419: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
Prepare for model saver
('Model save path:', '/content/DualRL/tmp/model/yelp/nmt_template/0-1/')
Adopt bilstm as encoder and decoder
RNN Decoder CopyBridge
WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/function.py:1007: calling create_op (from tensorflow.python.framework.ops) with compute_shapes is deprecated and will be removed in a future version.
Instructions for updating:
Shapes are always computed; don't use the compute_shapes as it has no effect.
WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/opennmt/utils/cell.py:47: __init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.
Instructions for updating:
This class is equivalent as tf.keras.layers.LSTMCell, and will be replaced by that in Tensorflow 2.0.
WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/opennmt/encoders/rnn_encoder.py:133: bidirectional_dynamic_rnn (from tensorflow.python.ops.rnn) is deprecated and will be removed in a future version.
Instructions for updating:
Please use `keras.layers.Bidirectional(keras.layers.RNN(cell))`, which is equivalent to this API
WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/rnn.py:443: dynamic_rnn (from tensorflow.python.ops.rnn) is deprecated and will be removed in a future version.
Instructions for updating:
Please use `keras.layers.RNN(cell)`, which is equivalent to this API
WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/rnn.py:626: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.cast instead.
/content/DualRL/tmp/model/yelp/nmt_template/0-1/
('Loading nmt model from', '/content/DualRL/tmp/model/yelp/nmt_template/0-1/')
WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py:1266: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.
Instructions for updating:
Use standard file APIs to check for files with this prefix.
('Error! Loading nmt model from', '/content/DualRL/tmp/model/yelp/nmt_template/0-1/')
('Again! Loading nmt model from', u'/content/DualRL/tmp/model/yelp/nmt_template//0-1/-2300')
Adopt bilstm as encoder and decoder
RNN Decoder CopyBridge
Reuse parameters.
Result save path:/content/DualRL/tmp/output/yelp_template/test.0-1.tsf, /content/DualRL/tmp/output/yelp_template/test.0.tsf
INFERENCE---Total N batch:17	Generate probs:-11.8581542969	Cost time:5.07563018799

But I am very confused if I am following the right commands to get an inference, and where I can find the output 'positive' sentiment sentence.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions