{"action":"created","issue":{"url":"https://api.github.com/repos/fchollet/keras/issues/1459","repository_url":"https://api.github.com/repos/fchollet/keras","labels_url":"https://api.github.com/repos/fchollet/keras/issues/1459/labels{/name}","comments_url":"https://api.github.com/repos/fchollet/keras/issues/1459/comments","events_url":"https://api.github.com/repos/fchollet/keras/issues/1459/events","html_url":"https://github.com/fchollet/keras/issues/1459","id":126486135,"number":1459,"title":"Sequence classification with LSTM + max pooling","user":{"login":"rfeinman","id":9561213,"avatar_url":"https://avatars.githubusercontent.com/u/9561213?v=3","gravatar_id":"","url":"https://api.github.com/users/rfeinman","html_url":"https://github.com/rfeinman","followers_url":"https://api.github.com/users/rfeinman/followers","following_url":"https://api.github.com/users/rfeinman/following{/other_user}","gists_url":"https://api.github.com/users/rfeinman/gists{/gist_id}","starred_url":"https://api.github.com/users/rfeinman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rfeinman/subscriptions","organizations_url":"https://api.github.com/users/rfeinman/orgs","repos_url":"https://api.github.com/users/rfeinman/repos","events_url":"https://api.github.com/users/rfeinman/events{/privacy}","received_events_url":"https://api.github.com/users/rfeinman/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-01-13T18:46:32Z","updated_at":"2016-04-12T03:37:40Z","closed_at":"2016-03-31T18:50:21Z","body":"Hello,\r\n\r\nI am trying to build an LSTM for sequence classification. I would like the network to be able to accept variable length inputs. Here is an example of what the inputs would look like:\r\n\r\ninputs after applying pad_sequences:\r\nX = [[0, 0, 0, 1, 2], [0, 1, 4, 3, 5], [0, 0, 1, 1, 5]]\r\nbinary class labels:\r\ny = [1, 0, 1]\r\n\r\nI am looking for something as defined below. This model uses a 10-word vocabulary, an embedding that converts words into 5-element vectors, and a single 5-node hidden LSTM layer that returns sequences. A pooling layer accepts the temporal sequence output by the LSTM layer and performs temporal max-pooling, looking at only the non-masked portion of the sequence. The pooling layer converts the entire variable-length hidden vector sequence into a single hidden vector, and then feeds its output to the Dense layer.\r\n\r\nmodel = Sequential()\r\nmodel.add(Embedding(input_dim=10, output_dim=5, mask_zero=True))\r\nmodel.add(LSTM(output_dim=5, activation='sigmoid', return_sequences=True))\r\nmodel.add(MaxPool()) ## <----  This is what I need\r\nmodel.add(Dense(output_dim=1, activation='sigmoid'))\r\nmodel.compile(loss='binary_crossentropy', optimizer='rmsprop', class_mode='binary')\r\n\r\nmodel.fit(X, y)\r\n\r\nAny thoughts on how to best facilitate this?\r\n\r\nThanks,\r\nReuben\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/fchollet/keras/issues/comments/208689103","html_url":"https://github.com/fchollet/keras/issues/1459#issuecomment-208689103","issue_url":"https://api.github.com/repos/fchollet/keras/issues/1459","id":208689103,"user":{"login":"chenchenbox","id":4936707,"avatar_url":"https://avatars.githubusercontent.com/u/4936707?v=3","gravatar_id":"","url":"https://api.github.com/users/chenchenbox","html_url":"https://github.com/chenchenbox","followers_url":"https://api.github.com/users/chenchenbox/followers","following_url":"https://api.github.com/users/chenchenbox/following{/other_user}","gists_url":"https://api.github.com/users/chenchenbox/gists{/gist_id}","starred_url":"https://api.github.com/users/chenchenbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chenchenbox/subscriptions","organizations_url":"https://api.github.com/users/chenchenbox/orgs","repos_url":"https://api.github.com/users/chenchenbox/repos","events_url":"https://api.github.com/users/chenchenbox/events{/privacy}","received_events_url":"https://api.github.com/users/chenchenbox/received_events","type":"User","site_admin":false},"created_at":"2016-04-12T03:37:40Z","updated_at":"2016-04-12T03:37:40Z","body":"It performs well. Thanks."}}