Amiro:

I see your point, but then why if i only pass to the optimizer the tensor (data_words) self.optimizer.add_param_group({“params”: data_words}), I find that the gradients are calculated successfully (and not None)?


Most likely because you also remove other code like the wrapping in the nn.Parameter() for data_phrases that disconnects data_phrases from data_words.

Actually I have calculated the (data_phrases) from (data_words) but this was outside the training loop.

If data_phrases is computed from data_words, why should it be in the optimizer? Shouldn’t you just update data_words and recompute data_phrases every time data_words is updated?