# Loss dosn't decrase at all when using lstm

**URL:** <https://discuss.pytorch.org/t/loss-dosnt-decrase-at-all-when-using-lstm/69061>\
**Category:** Uncategorized\
**Created:** [February 8, 2020, 2:29pm UTC](https://discuss.pytorch.org/t/loss-dosnt-decrase-at-all-when-using-lstm/69061 "2020-02-08T14:29:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SimTorch](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@SimTorch](https://discuss.pytorch.org/u/SimTorch)\
**Post date:** [February 8, 2020, 2:29pm UTC](https://discuss.pytorch.org/t/loss-dosnt-decrase-at-all-when-using-lstm/69061/1 "2020-02-08T14:29:59Z")

</div>

Hi,  
I implemented a classification model to fix a Five-class problem, but I got a problem and the work stopped, the output of net, everything in batch is 1(class No2), while the real label is 0,1,2,3,4.  
why this happen? and how? Thank u, everyone!!  
Here is my code:

> def forward(self, input):

> ```
> if input is None or input.size()[-1] != self.input_size:
> return None
> out1,_= self.lstm(input,self.lstm_states)  
> lstmoutsize = self.hidden_size * 1 if self.bidirectional == 0 else 2
> lstmout = out1[:, -1, :]  
> lstmout = lstmout.view([-1,lstmoutsize]) # lstmout = batchsize * lstmoutsize
> outFcLstm = self.fcLstm(lstmout)             
> self.reset_hidden_states()
> 
> return outFcLstm 
> 
> ```

main:

> ```
> criterion = T.nn.CrossEntropyLoss()
> lr = opt.lr
> optimizer = T.optim.Adam(rnn.parameters(), lr=lr, weight_decay=opt.weight_decay)
> 
> while True:
> batch = self.queBatchSample.get()
> if batch is None:  
> break
> optimizer.zero_grad()
> output= rnn(batchData)
> if output is None:
> continue
> loss = criterion(output, batchLabel)
> loss.backward(retain_graph=True)
> optimizer.step()**
> 
> ```
