newsreclib.models.components.encoders.user package

Submodules

newsreclib.models.components.encoders.user.caum module

class newsreclib.models.components.encoders.user.caum.UserEncoder(news_embed_dim: int, num_filters: int, dense_att_hidden_dim1: int, dense_att_hidden_dim2: int, user_vector_dim: int, num_heads: int, dropout_probability: float)[source]

Bases: Module

Implements the user encoder of 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

news_embed_dim

The number of features in the news vector.

num_filters

The number of output features in the first linear layer.

dense_att_hidden_dim1

The number of output features in the first hidden state of the DenseAttention.

dense_att_hidden_dim2

The number of output features in the second hidden state of the DenseAttention.

user_vector_dim

The number of features in the user vector.

num_heads

The number of heads in the MultiheadAttention.

dropout_probability

Dropout probability.

forward(hist_news_vector: 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.encoders.user.cen_news_rec module

class newsreclib.models.components.encoders.user.cen_news_rec.UserEncoder(num_filters: int, num_heads: int, query_dim: int, gru_hidden_dim: int, num_recent_news: int, dropout_probability: float)[source]

Bases: Module

Implements the user encoder of CenNewsRec.

Reference: Qi, Tao, Fangzhao Wu, Chuhan Wu, Yongfeng Huang, and Xing Xie. “Privacy-Preserving News Recommendation Model Learning.” In Findings of the Association for Computational Linguistics: EMNLP 2020, pp. 1423-1432. 2020.

For further details, please refer to the paper

num_filters

The number of input features in the MultiheadAttention

num_heads

The number of heads in the MultiheadAttention.

query_dim

The number of features in the query vector.

gru_hidden_dim

The number of features in the hidden state of the GRU.

num_recent_news

Number of recent news to be encoded in the short-term user representation.

dropout_probability

Dropout probability.

forward(hist_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.encoders.user.dkn module

class newsreclib.models.components.encoders.user.dkn.UserEncoder(input_dim: int, hidden_dim: int)[source]

Bases: Module

Implements the user encoder 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

input_dim

The number of input features to the user encoder.

hidden_dim

The number of features in the hidden state of the user encoder.

forward(hist_news_vector: Tensor, cand_news_vector: Tensor, mask_hist: Tensor, mask_cand: 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.encoders.user.lstur module

class newsreclib.models.components.encoders.user.lstur.UserEncoder(num_users: int, input_dim: int, user_masking_probability: float, long_short_term_method: str)[source]

Bases: Module

Implements the user encoder of LSTUR.

Reference: An, Mingxiao, Fangzhao Wu, Chuhan Wu, Kun Zhang, Zheng Liu, and Xing Xie. “Neural news recommendation with long-and short-term user representations.” In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics, pp. 336-345. 2019.

For further details, please refer to the paper

num_users

The number of users.

input_dim

The number of input features in the embeddng layer for the long-term user representation.

user_masking_probability

The probability for randomly masking users in the long-term user representation.

long_short_term_method

The method for combining long and short-term user representations. If ini is chosen, the GRU will be initialized with the long-term user representation. If con is chosen, the long and short-term user representations will be concatenated.

forward(user: Tensor, hist_news_vector: Tensor, hist_size: 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.encoders.user.mins module

class newsreclib.models.components.encoders.user.mins.UserEncoder(news_embed_dim: int, query_dim: int, num_filters: int, num_gru_channels: int)[source]

Bases: Module

Implements the user encoder of MINS.

Reference: Wang, Rongyao, Shoujin Wang, Wenpeng Lu, and Xueping Peng. “News recommendation via multi-interest news sequence modelling.” In ICASSP 2022-2022 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP), pp. 7942-7946. IEEE, 2022.

For further details, please refer to the paper

news_embed_dim

The number of features in the news vector.

query_dim

The number of features in the query vector.

num_filters

The number of filters used in the GRU.

num_gru_channels

The number of channels used in the GRU.

forward(hist_news_vector: Tensor, hist_size: 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.encoders.user.naml module

class newsreclib.models.components.encoders.user.naml.UserEncoder(news_embed_dim: int, query_dim: int)[source]

Bases: Module

Implements the user encoder of NAML.

Reference: Wu, Chuhan, Fangzhao Wu, Mingxiao An, Jianqiang Huang, Yongfeng Huang, and Xing Xie. “Neural news recommendation with attentive multi-view learning.” arXiv preprint arXiv:1907.05576 (2019).

For further details, please refer to the paper

news_embed_dim

The number of features in the user vector.

query_dim

The number of features in the query vector.

forward(hist_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.encoders.user.npa module

class newsreclib.models.components.encoders.user.npa.UserEncoder(user_embed_dim: int, num_filters: int, preference_query_dim: int, dropout_probability: float)[source]

Bases: Module

Implements the user encoder of 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

user_embed_dim

The number of feature in the user vector.

num_filters

The number of filters in the PersonalizedAttention.

preference_query_dim

The number of features in the preference query vector.

dropout_probability

Dropout probability.

forward(hist_news_vector: Tensor, projected_users: 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.encoders.user.nrms module

class newsreclib.models.components.encoders.user.nrms.UserEncoder(news_embed_dim: int, num_heads: int, query_dim: int)[source]

Bases: Module

Implements the user encoder of NRMS.

Reference: Wu, Chuhan, Fangzhao Wu, Suyu Ge, Tao Qi, Yongfeng Huang, and Xing Xie. “Neural news recommendation with multi-head self-attention.” In Proceedings of the 2019 conference on empirical methods in natural language processing and the 9th international joint conference on natural language processing (EMNLP-IJCNLP), pp. 6389-6394. 2019.

For further details, please refer to the paper

news_embed_dim

The number of features in the news vector.

num_heads

The number of heads in the MultiheadAttention.

query_dim

The number of features in the query vector.

forward(hist_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

Module contents