Element-Research / rnn

Recurrent Neural Network library for Torch7's nn
BSD 3-Clause "New" or "Revised" License
939 stars 313 forks source link

Cannot get expected results when applying to a text classification task #312

Closed zhzou2020 closed 8 years ago

zhzou2020 commented 8 years ago

The code of my model is as followed:

local lookup = nn.LookupTable(opt.vocab_size, opt.vec_size) if opt.model_type == 'static' or opt.model_type == 'nonstatic' then lookup.weight:copy(w2v) else -- rand lookup.weight:uniform(-0.25, 0.25) end -- padding should always be 0 lookup.weight[1]:zero()

-- build simple recurrent neural network local r if opt.lstm == 0 then r = nn.Recurrent( opt.hidden_size, nn.Identity(), nn.Linear(opt.vec_size, opt.hidden_size), nn.Sigmoid(),
max_seq_len ) else require 'nngraph' nn.FastLSTM.usenngraph = true -- faster nn.FastLSTM.bn = opt.bn -- batch normolization r = nn.FastLSTM(opt.vec_size, opt.hidden_size) end

rnn = nn.Sequential() :add(lookup) :add(nn.SplitTable(1, 2)) -- batch * seq * vec :add(nn.Sequencer(r)) -- seq * batch * vec :add(nn.SelectTable(-1)) -- this selects the last time-step of the rnn output sequence :add(nn.Linear(opt.hidden_size, opt.num_classes)) :add(cudnn.LogSoftMax()) -- opt.cudnn = 1

zhzou2020 commented 8 years ago

I've tried other models before, it turns out that other parts of my code are correct.