AndreaRossi:

What I am trying to do is to compute the Hessian matrix of the likelihood of the trigrams that contain a certain word, with respect to the embedding of that word.


NLP tasks are a little out of my skill set, but what I’d suggest you try is figure out how exactly the embedding of given word is link to the likelihood of the trigrams, and build a function which takes the embeddings and returns the likelihood. Then you can just use the torch.autograd.functional.hessian to calculate it!