You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was planning to try and make a model learn to play a game as a way to teach myself so ML.
I'm trying to make a network that takes the game state in and outputs the probabilities for the desired moves.
This seems at first to be possible with KotlinDL but I've run into a problem that I can't find any documentation to solve.
For any given board state, only some moves are actually valid. I need to mask the output of the network to set these to 0 probability.
I originally looked for a way to do this in the network with some kind of masking layer but it doesn't seem to exist.
I then thought I'd just output the raw values, set the invalid ones to -inf and run it through a softmax manually after.
However, the only way I see to run the network is to use the .predictSoftly() method which seems like it already runs the output through a softmax.
My question is, is this possible? Either, is it possible to mask some output values before the softmax or is it possible to get the raw activations of the last layer.
I had hope that .predictAndGetActivations() would give me access to them but this seems like it give the activations for every layer except the last.
makeNetwork().use {
it.compile(
optimizer =Adam(),
loss =Losses.SOFT_MAX_CROSS_ENTROPY_WITH_LOGITS,
metric =Metrics.ACCURACY
)
it.init()
val pred = it.predictSoftly(FloatArray(inputDim){1.0f})
println(pred.contentToString()) // output is softmaxed
it.setPredOp(false)
val pred2 = it.predictSoftly(FloatArray(inputDim){1.0f})
println(pred2.contentToString()) // output is raw
}
EDIT4: Sorry for the long saga, but I found a less hacky way.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I was planning to try and make a model learn to play a game as a way to teach myself so ML.
I'm trying to make a network that takes the game state in and outputs the probabilities for the desired moves.
This seems at first to be possible with KotlinDL but I've run into a problem that I can't find any documentation to solve.
For any given board state, only some moves are actually valid. I need to mask the output of the network to set these to 0 probability.
I originally looked for a way to do this in the network with some kind of masking layer but it doesn't seem to exist.
I then thought I'd just output the raw values, set the invalid ones to -inf and run it through a softmax manually after.
However, the only way I see to run the network is to use the
.predictSoftly()
method which seems like it already runs the output through a softmax.My question is, is this possible? Either, is it possible to mask some output values before the softmax or is it possible to get the raw activations of the last layer.
I had hope that
.predictAndGetActivations()
would give me access to them but this seems like it give the activations for every layer except the last.EDIT: Digging into the code I found the section
That makes it clear the softmax is because I was using
Losses.SOFT_MAX_CROSS_ENTROPY_WITH_LOGITS
as my loss function.This loss function makes sense during training when I don't need to mask anything. Is it possible then to remove the
predictionOp
after training?EDIT2: I found a solution but it is very slow and inefficient to switch between the networks.
EDIT3: I have a very hacky workaround using reflection to change the output.
Using it like this works.
EDIT4: Sorry for the long saga, but I found a less hacky way.
This adds a "raw_output" op that can be accessed by providing
predictionTensorName = "raw_output"
topredictSoftly()
You can then get the raw output or the softmaxed output without any modifications.
Beta Was this translation helpful? Give feedback.
All reactions