{"action":"created","issue":{"url":"https://api.github.com/repos/Element-Research/rnn/issues/75","labels_url":"https://api.github.com/repos/Element-Research/rnn/issues/75/labels{/name}","comments_url":"https://api.github.com/repos/Element-Research/rnn/issues/75/comments","events_url":"https://api.github.com/repos/Element-Research/rnn/issues/75/events","html_url":"https://github.com/Element-Research/rnn/issues/75","id":121526185,"number":75,"title":"How to use MaskZero with LSTM and nn.ClassNLLCriterion for variable length squences ","user":{"login":"jundeng86","id":8589835,"avatar_url":"https://avatars.githubusercontent.com/u/8589835?v=3","gravatar_id":"","url":"https://api.github.com/users/jundeng86","html_url":"https://github.com/jundeng86","followers_url":"https://api.github.com/users/jundeng86/followers","following_url":"https://api.github.com/users/jundeng86/following{/other_user}","gists_url":"https://api.github.com/users/jundeng86/gists{/gist_id}","starred_url":"https://api.github.com/users/jundeng86/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jundeng86/subscriptions","organizations_url":"https://api.github.com/users/jundeng86/orgs","repos_url":"https://api.github.com/users/jundeng86/repos","events_url":"https://api.github.com/users/jundeng86/events{/privacy}","received_events_url":"https://api.github.com/users/jundeng86/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-12-10T16:33:07Z","updated_at":"2015-12-14T18:02:16Z","closed_at":null,"body":"Hi Guys,\r\nI tried to make use LSTM to deal with variable length sequences. But I failed to do that by using the MaskZero function. Could you please help me out? Thanks a lot!!\r\n\r\nHere a minimal code example of what I mean:\r\n```lua\r\nrequire 'rnn'\r\nrequire 'optim'\r\n\r\ninSize = 20\r\nbatchSize = 2\r\nhiddenSize = 10\r\nseqLengthMax = 11\r\nnumTargetClasses=5\r\nnumSeq = 30\r\n\r\nx, y1 = {}, {}\r\n\r\nfor i = 1, numSeq do\r\n   local seqLength = torch.random(1,seqLengthMax)\r\n   local temp = torch.zeros(seqLengthMax, inSize)\r\n   local targets ={}\r\n   if seqLength == seqLengthMax then\r\n         targets = (torch.rand(seqLength)*numTargetClasses):ceil()\r\n   else\r\n      targets = torch.cat(torch.zeros(seqLengthMax-seqLength),(torch.rand(seqLength)*numTargetClasses):ceil())\r\n   end\r\n      temp[{{seqLengthMax-seqLength+1,seqLengthMax}}] = torch.randn(seqLength,inSize)\r\n   table.insert(x, temp)\r\n   table.insert(y1, targets)\r\nend\r\n\r\nmodel = nn.Sequencer(\r\n   nn.Sequential()\r\n      :add(nn.MaskZero(nn.FastLSTM(inSize,hiddenSize),1))\r\n      :add(nn.MaskZero(nn.Linear(hiddenSize, numTargetClasses),1))\r\n      :add(nn.MaskZero(nn.LogSoftMax(),1))\r\n)\r\n\r\ncriterion = nn.SequencerCriterion(nn.MaskZero(nn.ClassNLLCriterion(),1))\r\n\r\noutput = model:forward(x)\r\nprint(output[1])\r\n\r\nerr = criterion:forward(output, y1)\r\nprint(err)\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Element-Research/rnn/issues/comments/164511704","html_url":"https://github.com/Element-Research/rnn/issues/75#issuecomment-164511704","issue_url":"https://api.github.com/repos/Element-Research/rnn/issues/75","id":164511704,"user":{"login":"nicholas-leonard","id":3520613,"avatar_url":"https://avatars.githubusercontent.com/u/3520613?v=3","gravatar_id":"","url":"https://api.github.com/users/nicholas-leonard","html_url":"https://github.com/nicholas-leonard","followers_url":"https://api.github.com/users/nicholas-leonard/followers","following_url":"https://api.github.com/users/nicholas-leonard/following{/other_user}","gists_url":"https://api.github.com/users/nicholas-leonard/gists{/gist_id}","starred_url":"https://api.github.com/users/nicholas-leonard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicholas-leonard/subscriptions","organizations_url":"https://api.github.com/users/nicholas-leonard/orgs","repos_url":"https://api.github.com/users/nicholas-leonard/repos","events_url":"https://api.github.com/users/nicholas-leonard/events{/privacy}","received_events_url":"https://api.github.com/users/nicholas-leonard/received_events","type":"User","site_admin":false},"created_at":"2015-12-14T18:02:16Z","updated_at":"2015-12-14T18:02:16Z","body":"@jundeng86 The model seems ok. It masks the zeros correctly AFAIK.\r\n\r\nAs for the criterion, the MaskZero cannot be used to decorate a criterion. We would need a MaskZeroCriterion for that. Working on it."}}