Skip to content

Instantly share code, notes, and snippets.

@khuangaf
Last active July 10, 2019 02:06
Show Gist options
  • Save khuangaf/bf09c802d7bfe6b3092a2967d8bba70d to your computer and use it in GitHub Desktop.
Save khuangaf/bf09c802d7bfe6b3092a2967d8bba70d to your computer and use it in GitHub Desktop.
# efficiently compute the aggregation of feature interactions
emb_list = [emb_item, pooled_interaction, emb_price_rank, emb_city, emb_last_item, emb_impression_index, emb_star]
emb_concat = torch.cat(emb_list, dim=1)
sum_squared = torch.pow( torch.sum( emb_concat, dim=1) , 2).unsqueeze(1)
squared_sum = torch.sum( torch.pow( emb_concat, 2) , dim=1).unsqueeze(1)
second_order = 0.5 * (squared_sum - sum_squared)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment