Prompt Implementation - Details Question
Closed this issue · 1 comments
vthost commented
Thank you for providing all the code, it's a very interesting work!
I have three questions about the prompt implementation, just to make sure I understand it :)
- What is the purpose of
self.cls
in the prompt? - For each molecule you add one all-ones (kind of dummy) FG, and this is the one you then "extract" in
model.py
? :cls_hiddens = torch.gather(hidden_states, 0, fg_indexs)
- In the same file, why do you concatenate
fg_out = torch.zeros(1, self.hidden_size).cuda()
? I am actually even missing why this doesn't lead to a mismatch in dimensions because you have onlyatom_num
atoms... but I guess it's really me missing something.
ZJU-Fangyin commented
Hello, thank you very much for your interest in our project!
Here are some insights into the process:
fg_states
stores the representations of all functional groups for each molecule in the batch. We reserve a slot for the mediator tensor at the beginning of each molecule's functional group tensors by appending a tensor of ones. The mediator vector for each molecule is then initialized using the parameters inself.cls
.- Following two rounds of attention, we employ the
torch.gather
function to retrieve the resultant mediator tensor. Note that thefg_indexs
maintains a record of the indexes for each molecule's mediator tensor withinfg_states
. - In the next step, we map
cls_hiddens
to the same dimensionality as the model's hidden size by implementing a linear layer. To superimpose the mediator tensor of each molecule onto each of its constituent atoms, we replicate each molecule's mediator as many times as there are atoms within it, thereby derivingfg_hiddens
. We concatenatefg_out = torch.zeros(1, self.hidden_size).cuda()
withfg_hiddens
. This is primarily done because the initial row ofatom_hiddens
also comprises a tensor of all zeroes. By doing this, we maintain consistency which is crucial for facilitating further computations.
I hope these explanations clarify the functionality of this part of the code for you! If there are any more questions or aspects you'd like to discuss, please do not hesitate to reach out at your convenience.