There’s multiple solutions. The simplest is to literally use the matrix multiply operation as you did here, applying it to a Variable and the transpose of the same Variable. If you set requires_grad=True on the Variable you’ll also be able to get back gradients to use in training.