Course 3 Week 1 Excercise 8 - Test passed in notebook but not in grader

Hi!

Im having issues in excercise 8. I believe the problem might be that the function takes model as input but I dont know how to predict using the serial model as we’d been using the training_loop object to predict. I used:

Make predictions using the inputs
pred = training_loop.eval_model(inputs)

and got all test passed, but it seems wrong.

Thanks!

Hi @beren_erchamion

Yes, it is the incorrect way because you are using the global variable training_loop inside test_model() function.

The correct way to get predictions is just use the model argument your function gets:
pred = model(inputs)

Cheers

Thanks a lot for your answer!
So, do I generally need to train using the training loop abstraction and then extract the model using training_loop.eval_model?

Yes, you generally train using trax.supervised.training (docs). After training you can access the trained model by training_loop.model or training_loop.eval_model. The latter is faster if all you want is just the predictions.

So the creators of the course wanted you to implement test_model() function that returns accuracy of your model. They had in mind that one of the arguments this function takes is model (and that is why you should always pay close attention to what arguments the function receives).

In the cell bellow the model variable is assigned model = training_loop.eval_model, which means that this variable is assigned the model tuned for predictions and this is the one you supposed to use as you pass this variable to the test_model() function.

Generally you could use training_loop.model or training_loop.eval_model depending on your needs but you should always pay attention to the scope of the variables (are they inside the function or outside).

Cheers

Great explanation. Makes a lot of sense, the design of Trax is growing on me. Though a more explicit explanation like the one you just gave with regards to extracting the model or eval_model from the training loop would be a good addition to the course I believe (maybe in the first notebook we encounter these abstractions?)

1 Like