This repository has been archived by the owner on Aug 22, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved polciy to own model to allow it getting persisted properly
- Loading branch information
Showing
3 changed files
with
39 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
import logging | ||
|
||
from rasa_core.policies.keras_policy import KerasPolicy | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class RestaurantPolicy(KerasPolicy): | ||
def model_architecture(self, num_features, num_actions, max_history_len): | ||
"""Build a Keras model and return a compiled model.""" | ||
from keras.layers import LSTM, Activation, Masking, Dense | ||
from keras.models import Sequential | ||
|
||
n_hidden = 32 # size of hidden layer in LSTM | ||
# Build Model | ||
batch_shape = (None, max_history_len, num_features) | ||
|
||
model = Sequential() | ||
model.add(Masking(-1, batch_input_shape=batch_shape)) | ||
model.add(LSTM(n_hidden, batch_input_shape=batch_shape)) | ||
model.add(Dense(input_dim=n_hidden, output_dim=num_actions)) | ||
model.add(Activation('softmax')) | ||
|
||
model.compile(loss='categorical_crossentropy', | ||
optimizer='adam', | ||
metrics=['accuracy']) | ||
|
||
logger.debug(model.summary()) | ||
return model |