View source: R/piece_transformer.R
| pt_forward | R Documentation |
Reads a state, or a batch of them, and returns a value per action.
pt_forward(model, state)
model |
A |
state |
Colours in |
For one state, a numeric vector of n_actions values, one per
move. For a batch, a matrix with one row per state and one column per
action.
A batch is not a convenience here, it is the way to get the work done quickly. Every layer but the attention treats a row on its own, so a batch of states is the same arithmetic on taller matrices — and a tall matmul is what BLAS is good at, where a short one spends its time in the call rather than the multiply. Scoring the ten states of a beam in one call is several times faster than scoring them one after another.
pt_transformer_load
## Not run:
model <- pt_transformer_load("model.pth")
solved <- rep(0:5, each = 16)
pt_forward(model, solved) # 24 values
pt_forward(model, rbind(solved, solved)) # 2 x 24
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.