UserWarning: nn.functional.tanh is deprecated. Use torch.tanh instead. warnings.warn("nn.functional.tanh is deprecated. Use torch.tanh instead.")

Ask Questions Forum: ask Machine Learning Questions to our readersCategory: PyTorchUserWarning: nn.functional.tanh is deprecated. Use torch.tanh instead. warnings.warn("nn.functional.tanh is deprecated. Use torch.tanh instead.")
Chris Staff asked 1 month ago

What does this warning mean?

1 Answers
Best Answer
Chris Staff answered 1 month ago

It means that nn.functional.tanh is deprecated – in other words, that it is no longer officially supported (although still existing in the code) and that it may be removed in the future.
 
It was deprecated because “tensors and variables are now merged” – according to one of the PyTorch developers.
 
It’s best to replace it with a call to nn.Tanh instead:
 
    def __init__(self):
      super().__init__()
      self.layers = nn.Sequential(
        nn.Linear(28 * 28, 256),
        nn.Sigmoid(),
        nn.Linear(256, 128),
        nn.Tanh(),
        nn.Linear(128, 56),
        nn.ReLU(),
        nn.Linear(56, 10)
      )

Your Answer

4 + 5 =