AnonymousMe
AnonymousMe

Reputation: 569

How to implement this equation in pytorch?

I'm trying to implement GNNs from a research paper and I have to code the following equations to get some sort of relatedness scores sj.

Since I am new to pytorch, I'm having some difficulties implementing equations.

Following are the set of equations that I want to code:

enter image description here

I have the following inputs h(t) = input_a = hidden[:,0:8,:]

hc(t) = input_b = hidden[:,8:13,:] The dimensions of 'hidden' is (1000, 13, 128) #(Batch size, inputs(context-0:8, and candidates 8:13), embedding dimension)

Also, the subscripts i in h(t) belong to 0:8, and j in hc(t) belong to 8:13. So, hi(t) would be hidden[:,i,:].

To provide some context,

enter image description here

enter image description here

Could someone please help me code the equations in the first picture ? I can even implement the function g() by myself, but I'm confused about the first two. Could someone help ?

Upvotes: 0

Views: 446

Answers (1)

SarthakJain
SarthakJain

Reputation: 1686

All the operations you could do to pytorch tensors are documented over here: https://pytorch.org/docs/stable/torch.html I suggest command + F to search for the operation you need.

For the 1st equations you gave:

For the second equation

There are many operations you can do to a torch.tensor object that are pretty useful for papers. As a rule of thumb, when implementing papers just use this pytorch doc as a way to find out many of those operations are.

Additionally if you are less comfortable with pytorch, another suggestion can be to do the equations in numpy then convert that value to a tensor.

Sarthak

Upvotes: 1

Related Questions