Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you actually apply a trained model?

I've been slowly going through the tensorflow tutorials, and I assume I will have to again. I don't have a background in ML but am slowly pushing my way up.

Anyway, after reading through the RNN tutorial and running the training code, I am confused.

How does one actually apply the trained model so that it can be used to make language predictions?

I know this is a terrible noobish and simple question, but I believe it will be of use to others, as I have seen it asked and not answered in a satisfactory way.

like image 674
Christopher Reid Avatar asked Jan 19 '16 08:01

Christopher Reid


People also ask

How do training models work?

A training model is a dataset that is used to train an ML algorithm. It consists of the sample output data and the corresponding sets of input data that have an influence on the output. The training model is used to run the input data through the algorithm to correlate the processed output against the sample output.


1 Answers

In general, when you train a model, you first do a forward pass, and then a backward pass. The forward pass makes a prediction based on your input data, and the backward pass adjust your model based on how correct your prediction was.

So when you want to apply your model, you just do a forward pass with your new data as input.

In your particular example, using this code, you can see how it's done by looking at how they run the test set, starting line 286.

# They instantiate the model with is_training=False
mtest = PTBModel(is_training=False, config=eval_config)

# Then they can do a forward pass
test_perplexity = run_epoch(session, mtest, test_data, tf.no_op())
print("Test Perplexity: %.3f" % test_perplexity)

And if you want the actual prediction and not the perplexity, it is the state in the run_epoch function :

cost, state, _ = session.run([m.cost, m.final_state, eval_op],
                             {m.input_data: x,
                              m.targets: y,
                              m.initial_state: state})
like image 111
TheWalkingCube Avatar answered Sep 18 '22 14:09

TheWalkingCube