简体   繁体   中英

Conitional output in keras LSTM

Maybe it is a dummy question but I'd like to know whether I can have my output vector to meet specific requirements.

I have multiple outputs (that are not binary) and I want their sum to be 1. I want my model to do some kind of evaluation in order for my output vector to meet this requirement.

You can either:

  • Add a softmax activation at the end of your model, or
  • Create a custom normalizing function

Softmax:

Just add Activation('softmax') at the end of the model.
This will perform some log operations though, and may be adding some extra conditions you do not want.

Custom normalizing:

Simply add this layer:

import keras.backend as K

Lambda(lambda x: x / K.sum(x), output_shape=optional_with_tensorflow)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM