Thank you for your reply! This is the final form that I want to get to. However, my question was if there is a way to go automatically from the sympy expression to this from (sorry if that was not clear). I have lots of sympy expressions, and I want to pass them automatically to a pytorch module for training, not write everything by hand. For example, for the line out = self.c0 * torch.cos(self.c1 * y) + self.c2 + self.c3 * x**2 I would like some function that would turn my sympy expression to that automatically, something like: out = sympy_to_pytorch(sympy_expression). And something similar for picking the parameters out of my sympy expression and doing the self.c0 = nn.Parameter(torch.randn(1, 1)) part on its own.