# Retrain\_variables in the loss function

**URL:** <https://discuss.pytorch.org/t/retrain-variables-in-the-loss-function/1677>\
**Category:** Uncategorized\
**Created:** [April 5, 2017, 10:15pm UTC](https://discuss.pytorch.org/t/retrain-variables-in-the-loss-function/1677 "2017-04-05T22:15:30Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![miguelvr](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/miguelvr/32/366_2.png) [@miguelvr](https://discuss.pytorch.org/u/miguelvr)\
**Post date:** [April 6, 2017, 11:35am UTC](https://discuss.pytorch.org/t/retrain-variables-in-the-loss-function/1677/5 "2017-04-06T11:35:01Z")

</div>

Your linear layer is not doing the same as a TimeDistributedDense in Keras. You are only using the last time step, and ditching everything else.

Have a look at my TimeDistributed wrapper here:

> [@Any PyTorch function can work as Keras' Timedistributed?](https://discuss.pytorch.org/t/any-pytorch-function-can-work-as-keras-timedistributed/1346/4):
>
> Hey, I developed a PyTorch module that mimics the TimeDistributed wrapper of Keras a few days ago: import torch.nn as nn class TimeDistributed(nn.Module): def \_\_init\_\_(self, module, batch\_first=False): super(TimeDistributed, self).\_\_init\_\_() self.module = module self.batch\_first = batch\_first def forward(self, x): if len(x.size()) \<= 2: return self.module(x) # Squash samples and timesteps into a single axis x\_reshape = x.…

---

_[View the full topic](https://discuss.pytorch.org/t/retrain-variables-in-the-loss-function/1677)._
