Skip to content

Commit

Permalink
CHANGE: change calculation to .einsum(...)
Browse files Browse the repository at this point in the history
This should be much more better to show the calculation logic inside the model.
  • Loading branch information
p768lwy3 committed Oct 29, 2019
1 parent 6be6057 commit 0787dd5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion torecsys/layers/ctr/compose_excitation_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def forward(self, field_emb_inputs: torch.Tensor) -> torch.Tensor:
# inputs: field_emb_inputs, shape = (B, N * N, E)
# output: outputs, shape = (B, N * N, E)
attn_w = attn_w.unflatten("N", (("N", attn_w.size("N")), ("E", 1)))
outputs = field_emb_inputs * attn_w

# Multiply attentional weights on field embedding tensors
## outputs = field_emb_inputs * attn_w
outputs = torch.einsum("ijk,ijh->ijk", [field_emb_inputs.rename(None), attn_w.rename(None)])
outputs.names = ("B", "N", "E")

return outputs

0 comments on commit 0787dd5

Please sign in to comment.