newsreclib.models.components.layers package
Submodules
newsreclib.models.components.layers.attention module
- class newsreclib.models.components.layers.attention.AdditiveAttention(input_dim: int, query_dim: int)[source]
Bases:
Module
- forward(input_vector: Tensor) Tensor [source]
- Parameters:
input_vector – User tensor of shape (batch_size, hidden_dim, output_dim).
- Returns:
User tensor of shape (batch_size, news_emb_dim).
- training: bool
- class newsreclib.models.components.layers.attention.DenseAttention(input_dim: int, hidden_dim1: int, hidden_dim2: int)[source]
Bases:
Module
Dense attention used in CAUM.
Reference: Qi, Tao, Fangzhao Wu, Chuhan Wu, and Yongfeng Huang. “News recommendation with candidate-aware user modeling.” In Proceedings of the 45th International ACM SIGIR Conference on Research and Development in Information Retrieval, pp. 1917-1921. 2022.
For further details, please refer to the paper
- forward(input_vector: Tensor) Tensor [source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool
- class newsreclib.models.components.layers.attention.PersonalizedAttention(preference_query_dim: int, num_filters: int)[source]
Bases:
Module
Personalized attention used in NPA.
Reference: Wu, Chuhan, Fangzhao Wu, Mingxiao An, Jianqiang Huang, Yongfeng Huang, and Xing Xie. “NPA: neural news recommendation with personalized attention.” In Proceedings of the 25th ACM SIGKDD international conference on knowledge discovery & data mining, pp. 2576-2584. 2019.
For further details, please refer to the paper
- forward(query: Tensor, keys: Tensor) Tensor [source]
- Parameters:
query – (batch_size * preference_dim)
keys – (batch_size * num_filters * num_words_text)
- Returns:
(batch_size * num_filters)
- training: bool
- class newsreclib.models.components.layers.attention.PolyAttention(input_dim: int, num_context_codes: int, context_code_dim: int)[source]
Bases:
Module
Implementation of Poly attention scheme (used in MINER) that extracts K attention vectors through K additive attentions.
Adapted from https://github.com/duynguyen-0203/miner/blob/master/src/model/model.py.
Reference: Li, Jian, Jieming Zhu, Qiwei Bi, Guohao Cai, Lifeng Shang, Zhenhua Dong, Xin Jiang, and Qun Liu. “MINER: multi-interest matching network for news recommendation.” In Findings of the Association for Computational Linguistics: ACL 2022, pp. 343-352. 2022.
For further details, please refer to the paper
- forward(embeddings: Tensor, attn_mask: Tensor, bias: Optional[Tensor] = None)[source]
- Parameters:
embeddings – (batch_size, hist_length, embed_dim)
attn_mask – (batch_size, hist_length)
bias – (batch_size, hist_length, num_candidates)
- Returns:
(batch_size, num_context_codes, embed_dim)
- Return type:
torch.Tensor
- training: bool
- class newsreclib.models.components.layers.attention.TargetAwareAttention(input_dim: int)[source]
Bases:
Module
Implementation of the target-aware attention network used in MINER.
Adapted from https://github.com/duynguyen-0203/miner/blob/master/src/model/model.py
Reference: Li, Jian, Jieming Zhu, Qiwei Bi, Guohao Cai, Lifeng Shang, Zhenhua Dong, Xin Jiang, and Qun Liu. “MINER: multi-interest matching network for news recommendation.” In Findings of the Association for Computational Linguistics: ACL 2022, pp. 343-352. 2022.
For further details, please refer to the paper
- forward(query: Tensor, key: Tensor, value: Tensor) Tensor [source]
- Parameters:
query – (batch_size, num_context_codes, input_embed_dim)
key – (batch_size, num_candidates, input_embed_dim)
value – (batch_size, num_candidates, num_context_codes)
- training: bool
newsreclib.models.components.layers.click_predictor module
- class newsreclib.models.components.layers.click_predictor.DNNPredictor(input_dim: int, hidden_dim: int)[source]
Bases:
Module
Implementation of the click pedictor of DKN.
Reference: Wang, Hongwei, Fuzheng Zhang, Xing Xie, and Minyi Guo. “DKN: Deep knowledge-aware network for news recommendation.” In Proceedings of the 2018 world wide web conference, pp. 1835-1844. 2018.
For further details, please refer to the paper
- forward(user_vec: Tensor, cand_news: Tensor) Tensor [source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool
- class newsreclib.models.components.layers.click_predictor.DotProduct[source]
Bases:
Module
- forward(user_vec: Tensor, cand_news_vector: Tensor) Tensor [source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool
newsreclib.models.components.layers.projection module
- class newsreclib.models.components.layers.projection.UserPreferenceQueryProjection(user_embed_dim: int, preference_query_dim: int, dropout_probability: float)[source]
Bases:
Module
Projects dense user representations to preference query vector.
Reference: Wu, Chuhan, Fangzhao Wu, Mingxiao An, Jianqiang Huang, Yongfeng Huang, and Xing Xie. “NPA: neural news recommendation with personalized attention.” In Proceedings of the 25th ACM SIGKDD international conference on knowledge discovery & data mining, pp. 2576-2584. 2019.
For further details, please refer to the paper
- forward(projected_users: Tensor) Tensor [source]
- Parameters:
projected_user – Vector of project users of size (batch_size * embedding_dim)
- Returns:
Project query vector of size (batch_size * preference_dim)
- training: bool
- class newsreclib.models.components.layers.projection.UserProjection(num_users: int, user_embed_dim: int, dropout_probability: float)[source]
Bases:
Module
Embeds user ID to dense vector through a lookup table.
Reference: Wu, Chuhan, Fangzhao Wu, Mingxiao An, Jianqiang Huang, Yongfeng Huang, and Xing Xie. “NPA: neural news recommendation with personalized attention.” In Proceedings of the 25th ACM SIGKDD international conference on knowledge discovery & data mining, pp. 2576-2584. 2019.
For further details, please refer to the paper
- forward(users: Tensor) Tensor [source]
- Parameters:
users – Vector of users of size batch_size
- Returns:
Projected users vector of size ‘(batch_size * user_embedding_dim)`
- training: bool