Recurrent neural network multiple types of input Keras The Next CEO of Stack Overflow2019 Community Moderator ElectionCan TF turn a given graph into a recursive one?Accuracy drops if more layers trainable - weirdUnevenly stretched sequences with LSTM/GRUNeural network accuracy for simple classificationAnomaly detection using RNN LSTMProperly using activation functions of neural networkMetrics values are equal while training and testing a modelArchitecture help for multivariate input and output LSTM modelsHow is this tensorflow command interpreted?Understanding LSTM structure
How easy is it to start Magic from scratch?
What is the point of a new vote on May's deal when the indicative votes suggest she will not win?
Unreliable Magic - Is it worth it?
Fastest way to shutdown Ubuntu Mate 18.10
Rotate a column
Can a single photon have an energy density?
Describing a person. What needs to be mentioned?
What is meant by a M next to a roman numeral?
Return of the Riley Riddles in Reverse
How to write papers efficiently when English isn't my first language?
Visit to the USA with ESTA approved before trip to Iran
Increase performance creating Mandelbrot set in python
How long to clear the 'suck zone' of a turbofan after start is initiated?
Why were Madagascar and New Zealand discovered so late?
How to disable updates in WordPress theme
Why didn't Theresa May consult with Parliament before negotiating a deal with the EU?
+1 instead of double roll for advantage
How to start emacs in "nothing" mode
Can a caster that cast Polymorph on themselves stop concentrating at any point even if their Int is low?
How do we know the LHC results are robust?
Is there a good way to store credentials outside of a password manager?
Apart from "berlinern", do any other German dialects have a corresponding verb?
How can a function with a hole (removable discontinuity) equal a function with no hole?
Can I replace a Shimano FC-MT500 26/36 crankset with a Shimano Ultegra FC-R8000 36/46 set?
Recurrent neural network multiple types of input Keras
The Next CEO of Stack Overflow2019 Community Moderator ElectionCan TF turn a given graph into a recursive one?Accuracy drops if more layers trainable - weirdUnevenly stretched sequences with LSTM/GRUNeural network accuracy for simple classificationAnomaly detection using RNN LSTMProperly using activation functions of neural networkMetrics values are equal while training and testing a modelArchitecture help for multivariate input and output LSTM modelsHow is this tensorflow command interpreted?Understanding LSTM structure
$begingroup$
For a project I want to use recurrent neural networks, however my knowledge on this subject is still somewhat limited. I do have some experience with convolutional nets and traditional neural networks. I need to predict a probability distribution over one of the inputs of the next step. Most of my sequences are relatively short, with some big outliers in there. There is more than enough data so that should not be an issue.
I'm using Keras for this task, using either LSTM or GRU layers.
My input exists of sequences of categorical input $x_A$, $x_B$ and a few numerical values $x_1$ to $x_11$. I'm trrying to predict $x_A$ of the last step that is not trained on. For the high cardinality categorical features I'm using an embedding layer to map them to a dense space and then merge the three different types of input into one layer. My issue is merging them together before going to the softmax layer to do the one-hot encoding prediction of the last step. I cannot seem to get the inputs to match. I pad the shorter sequences to 10 steps plus the label and truncate the longer sequences cutting off the start. I've attempted both the Graph and the Sequential interface.
def build_graph_model(n_A, n_B, max_length, batch_size):
g = Graph()
g.add_input(name='A', input_shape=(max_length, ), dtype='int')
g.add_node(Embedding(n_A, 32, input_length=max_length, mask_zero=True), name='embedding_A', input='A')
g.add_input(name='B', input_shape=(max_length, ), dtype='int')
g.add_node(Embedding(n_B, 32, input_length=max_length, mask_zero=True), name='embedding_B', input='B')
g.add_input(name='rest', input_shape=(max_length, 11))
g.add_node(Dense(30, activation='relu'), name='rest_dense', input='rest')
g.add_node(LSTM(100), name='lstm', inputs=['embedding_A', 'embedding_B', 'rest_dense'])
g.add_node(Dense(n_dest, activation='softmax'), name='softm', input='lstm')
g.add_output(name='output', input='softm')
g.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
This gives an assertion error for having the wrong input dimensions. If I remove the $x_1$ to $x_11$ thing completely it works. If I change the Dense layer into TimeDistributed(Dense) I still get the same error although I think that should work. Inserting the rest input directly into the merge doesn't work because the merge cannot be the first layer. I'm uncertain how to fix this issue.
EDIT: This guy asks the same question but much more concise (https://groups.google.com/forum/#!topic/keras-users/zCuS4xdv5QY)
python deep-learning rnn keras
$endgroup$
add a comment |
$begingroup$
For a project I want to use recurrent neural networks, however my knowledge on this subject is still somewhat limited. I do have some experience with convolutional nets and traditional neural networks. I need to predict a probability distribution over one of the inputs of the next step. Most of my sequences are relatively short, with some big outliers in there. There is more than enough data so that should not be an issue.
I'm using Keras for this task, using either LSTM or GRU layers.
My input exists of sequences of categorical input $x_A$, $x_B$ and a few numerical values $x_1$ to $x_11$. I'm trrying to predict $x_A$ of the last step that is not trained on. For the high cardinality categorical features I'm using an embedding layer to map them to a dense space and then merge the three different types of input into one layer. My issue is merging them together before going to the softmax layer to do the one-hot encoding prediction of the last step. I cannot seem to get the inputs to match. I pad the shorter sequences to 10 steps plus the label and truncate the longer sequences cutting off the start. I've attempted both the Graph and the Sequential interface.
def build_graph_model(n_A, n_B, max_length, batch_size):
g = Graph()
g.add_input(name='A', input_shape=(max_length, ), dtype='int')
g.add_node(Embedding(n_A, 32, input_length=max_length, mask_zero=True), name='embedding_A', input='A')
g.add_input(name='B', input_shape=(max_length, ), dtype='int')
g.add_node(Embedding(n_B, 32, input_length=max_length, mask_zero=True), name='embedding_B', input='B')
g.add_input(name='rest', input_shape=(max_length, 11))
g.add_node(Dense(30, activation='relu'), name='rest_dense', input='rest')
g.add_node(LSTM(100), name='lstm', inputs=['embedding_A', 'embedding_B', 'rest_dense'])
g.add_node(Dense(n_dest, activation='softmax'), name='softm', input='lstm')
g.add_output(name='output', input='softm')
g.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
This gives an assertion error for having the wrong input dimensions. If I remove the $x_1$ to $x_11$ thing completely it works. If I change the Dense layer into TimeDistributed(Dense) I still get the same error although I think that should work. Inserting the rest input directly into the merge doesn't work because the merge cannot be the first layer. I'm uncertain how to fix this issue.
EDIT: This guy asks the same question but much more concise (https://groups.google.com/forum/#!topic/keras-users/zCuS4xdv5QY)
python deep-learning rnn keras
$endgroup$
$begingroup$
You may want to use the Keras functional API(keras.io/getting-started/functional-api-guide/…) to build such a network!
$endgroup$
– Victor Chen
Nov 21 '16 at 2:28
add a comment |
$begingroup$
For a project I want to use recurrent neural networks, however my knowledge on this subject is still somewhat limited. I do have some experience with convolutional nets and traditional neural networks. I need to predict a probability distribution over one of the inputs of the next step. Most of my sequences are relatively short, with some big outliers in there. There is more than enough data so that should not be an issue.
I'm using Keras for this task, using either LSTM or GRU layers.
My input exists of sequences of categorical input $x_A$, $x_B$ and a few numerical values $x_1$ to $x_11$. I'm trrying to predict $x_A$ of the last step that is not trained on. For the high cardinality categorical features I'm using an embedding layer to map them to a dense space and then merge the three different types of input into one layer. My issue is merging them together before going to the softmax layer to do the one-hot encoding prediction of the last step. I cannot seem to get the inputs to match. I pad the shorter sequences to 10 steps plus the label and truncate the longer sequences cutting off the start. I've attempted both the Graph and the Sequential interface.
def build_graph_model(n_A, n_B, max_length, batch_size):
g = Graph()
g.add_input(name='A', input_shape=(max_length, ), dtype='int')
g.add_node(Embedding(n_A, 32, input_length=max_length, mask_zero=True), name='embedding_A', input='A')
g.add_input(name='B', input_shape=(max_length, ), dtype='int')
g.add_node(Embedding(n_B, 32, input_length=max_length, mask_zero=True), name='embedding_B', input='B')
g.add_input(name='rest', input_shape=(max_length, 11))
g.add_node(Dense(30, activation='relu'), name='rest_dense', input='rest')
g.add_node(LSTM(100), name='lstm', inputs=['embedding_A', 'embedding_B', 'rest_dense'])
g.add_node(Dense(n_dest, activation='softmax'), name='softm', input='lstm')
g.add_output(name='output', input='softm')
g.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
This gives an assertion error for having the wrong input dimensions. If I remove the $x_1$ to $x_11$ thing completely it works. If I change the Dense layer into TimeDistributed(Dense) I still get the same error although I think that should work. Inserting the rest input directly into the merge doesn't work because the merge cannot be the first layer. I'm uncertain how to fix this issue.
EDIT: This guy asks the same question but much more concise (https://groups.google.com/forum/#!topic/keras-users/zCuS4xdv5QY)
python deep-learning rnn keras
$endgroup$
For a project I want to use recurrent neural networks, however my knowledge on this subject is still somewhat limited. I do have some experience with convolutional nets and traditional neural networks. I need to predict a probability distribution over one of the inputs of the next step. Most of my sequences are relatively short, with some big outliers in there. There is more than enough data so that should not be an issue.
I'm using Keras for this task, using either LSTM or GRU layers.
My input exists of sequences of categorical input $x_A$, $x_B$ and a few numerical values $x_1$ to $x_11$. I'm trrying to predict $x_A$ of the last step that is not trained on. For the high cardinality categorical features I'm using an embedding layer to map them to a dense space and then merge the three different types of input into one layer. My issue is merging them together before going to the softmax layer to do the one-hot encoding prediction of the last step. I cannot seem to get the inputs to match. I pad the shorter sequences to 10 steps plus the label and truncate the longer sequences cutting off the start. I've attempted both the Graph and the Sequential interface.
def build_graph_model(n_A, n_B, max_length, batch_size):
g = Graph()
g.add_input(name='A', input_shape=(max_length, ), dtype='int')
g.add_node(Embedding(n_A, 32, input_length=max_length, mask_zero=True), name='embedding_A', input='A')
g.add_input(name='B', input_shape=(max_length, ), dtype='int')
g.add_node(Embedding(n_B, 32, input_length=max_length, mask_zero=True), name='embedding_B', input='B')
g.add_input(name='rest', input_shape=(max_length, 11))
g.add_node(Dense(30, activation='relu'), name='rest_dense', input='rest')
g.add_node(LSTM(100), name='lstm', inputs=['embedding_A', 'embedding_B', 'rest_dense'])
g.add_node(Dense(n_dest, activation='softmax'), name='softm', input='lstm')
g.add_output(name='output', input='softm')
g.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
This gives an assertion error for having the wrong input dimensions. If I remove the $x_1$ to $x_11$ thing completely it works. If I change the Dense layer into TimeDistributed(Dense) I still get the same error although I think that should work. Inserting the rest input directly into the merge doesn't work because the merge cannot be the first layer. I'm uncertain how to fix this issue.
EDIT: This guy asks the same question but much more concise (https://groups.google.com/forum/#!topic/keras-users/zCuS4xdv5QY)
python deep-learning rnn keras
python deep-learning rnn keras
edited Aug 4 '16 at 16:01
Jan van der Vegt
asked Aug 4 '16 at 15:48
Jan van der VegtJan van der Vegt
6,6301839
6,6301839
$begingroup$
You may want to use the Keras functional API(keras.io/getting-started/functional-api-guide/…) to build such a network!
$endgroup$
– Victor Chen
Nov 21 '16 at 2:28
add a comment |
$begingroup$
You may want to use the Keras functional API(keras.io/getting-started/functional-api-guide/…) to build such a network!
$endgroup$
– Victor Chen
Nov 21 '16 at 2:28
$begingroup$
You may want to use the Keras functional API(keras.io/getting-started/functional-api-guide/…) to build such a network!
$endgroup$
– Victor Chen
Nov 21 '16 at 2:28
$begingroup$
You may want to use the Keras functional API(keras.io/getting-started/functional-api-guide/…) to build such a network!
$endgroup$
– Victor Chen
Nov 21 '16 at 2:28
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
Kera's functional API allows arbitrary models to be combined like you are describing.
One option is to define a model very similar to the documentation linked above: define a "main input" that is categorical and then define an "auxiliary input" that is numerical. Both of those sub-models can be merged into a single network with additional layers.
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "557"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f13198%2frecurrent-neural-network-multiple-types-of-input-keras%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Kera's functional API allows arbitrary models to be combined like you are describing.
One option is to define a model very similar to the documentation linked above: define a "main input" that is categorical and then define an "auxiliary input" that is numerical. Both of those sub-models can be merged into a single network with additional layers.
$endgroup$
add a comment |
$begingroup$
Kera's functional API allows arbitrary models to be combined like you are describing.
One option is to define a model very similar to the documentation linked above: define a "main input" that is categorical and then define an "auxiliary input" that is numerical. Both of those sub-models can be merged into a single network with additional layers.
$endgroup$
add a comment |
$begingroup$
Kera's functional API allows arbitrary models to be combined like you are describing.
One option is to define a model very similar to the documentation linked above: define a "main input" that is categorical and then define an "auxiliary input" that is numerical. Both of those sub-models can be merged into a single network with additional layers.
$endgroup$
Kera's functional API allows arbitrary models to be combined like you are describing.
One option is to define a model very similar to the documentation linked above: define a "main input" that is categorical and then define an "auxiliary input" that is numerical. Both of those sub-models can be merged into a single network with additional layers.
answered 1 hour ago
Brian SpieringBrian Spiering
4,1631029
4,1631029
add a comment |
add a comment |
Thanks for contributing an answer to Data Science Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f13198%2frecurrent-neural-network-multiple-types-of-input-keras%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
You may want to use the Keras functional API(keras.io/getting-started/functional-api-guide/…) to build such a network!
$endgroup$
– Victor Chen
Nov 21 '16 at 2:28