How to switch to predict mode in Trax after training a model?

104
April 17, 2022, at 4:30 PM

I'm familiarizing myself with the Trax library for building deep learning models and one question that I can't find an answer to is how to switch from "train" mode to "eval" mode after model training is complete.

Consider this example with a transformer (modified from https://github.com/google/trax#1-run-a-pre-trained-transformer)

import trax
model = trax.models.Transformer(
    input_vocab_size=33300,
    d_model=512, d_ff=2048,
    n_heads=8, n_encoder_layers=6, n_decoder_layers=6,
    max_len=2048, mode='train')
# do the training

After the training, how can I switch the mode to be "predict"?

One idea that comes to mind (following the same example), is to train the model, then save it, re-initialize the model but this time with mode='train' and then load the weights by running model.init_from_file(file).

Is there a way to do it directly without having to re-init the model?

Rent Charter Buses Company
READ ALSO
Rotate point about another point in degrees python

Rotate point about another point in degrees python

If you had a point (in 2d), how could you rotate that point by degrees around the other point (the origin) in python?

195
Seaborn Lineplot- Displaying Values on top of the markers

Seaborn Lineplot- Displaying Values on top of the markers

We could display a values from dataframe to the graph using the brand new feature of the matplotlib in bar graph

85
Plotly: Scatter plot with dropdown menu and color by group

Plotly: Scatter plot with dropdown menu and color by group

I'm trying to make a scatter plot with 2 dropdown menus that select a data column (from a pandas data frame) to be plotted for x and y-axis, but I'm also wanting the points to be colored by a third categorical variable that is fixed (no dropdown needed...

129