Paper → implementation
See this paper in code.
Community-written snippets that make the paper’s ideas concrete. These are not official implementations from the paper’s authors.
Summarize within categories before combining them
A single history may mix sportswear and kitchen products. First summarize relevant items within each known category; then decide which category summaries matter for the candidate. items [B, N, D] and target [B, D] contain feature vectors. category_ids [B, N] assigns one category 0…G−1 to each item; −1 marks padding. Output interest [B, D] is a feature vector, not a click probability. B is the batch size, N the padded history length, D the vector width, and G the number of categories. Category labels are supplied by the data; the network learns relevance, not the category assignments.
3 4class Relevance(nn.Module):5 def __init__(self, dim):6 super().__init__()7 self.net = nn.Sequential(nn.Linear(4 * dim, 16), nn.ReLU(), nn.Linear(16, 1))8 9 def forward(self, items, target):Train one model from IDs to click logits
Predict a click from item IDs and known categories. B is the number of examples, N the padded history length, D the learned embedding width, and G the category count. Supply history IDs [B, N], one target ID per example [B], and category IDs [B, N]. The model looks up D-feature vectors, averages relevant items within categories, then weights and sums those summaries for the candidate. A head returns logits [B]: unrestricted click scores. Observed binary labels [B] train the whole model with one loss.
34 35class HierarchicalRecommender(nn.Module):36 def __init__(self, num_items, dim, categories):37 super().__init__()38 self.embedding = nn.Embedding(num_items, dim, padding_idx=0)39 self.pool = HierarchicalInterest(dim, categories)40 self.head = nn.Linear(2 * dim, 1)Your place is saved automatically. Reaching the end marks this paper as read.
Page 1