Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Recommenders team Recommenders SLI REC Model

From Leeroopedia
Revision as of 16:29, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Recommenders_team_Recommenders_SLI_REC_Model.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Recommendation Systems, Deep Learning, Sequential Recommendation
Last Updated 2026-02-10 00:00 GMT

Overview

Implements the SLI_REC (Short and Long-term Interest Recommendation) model, which adaptively combines long-term and short-term user preferences using time-aware modeling for personalized sequential recommendation.

Description

The SLI_RECModel class extends SequentialBaseModel and implements _build_seq_graph with three major components:

Long-term interest (ASVD): Concatenated item and category history embeddings are processed through an attention layer (_attention) to produce att_fea1, a weighted sum representing the user's stable long-term preferences.

Short-term interest (Time4LSTM + Attention FCN): Item history embeddings are augmented with temporal features (time_from_first_action and time_to_now) and processed through a Time4LSTMCell via dynamic_rnn. The LSTM outputs are then attended by the _attention_fcn method, which computes target-item-aware attention weights. This attention FCN uses a learned attention_mat to transform user states, tiles the target item query to match, and computes attention scores from the concatenation of four interaction features: [att_inputs, queries, att_inputs - queries, att_inputs * queries]. The scores are passed through an FCN and masked with the sequence mask before softmax normalization, producing att_fea2.

Adaptive fusion: A sigmoid-activated FCN computes alpha from the concatenation of target item embedding, long-term features, short-term features, and the most recent time-to-now value. The final user embedding is computed as user_embed = att_fea1 * alpha + att_fea2 * (1 - alpha), adaptively blending long-term and short-term interests based on temporal context.

Usage

Use this model when temporal dynamics matter in user behavior, such as when users show different interests over short-term and long-term horizons. It is particularly effective when the time between interactions carries meaningful signal for recommendation.

Code Reference

Source Location

Signature

class SLI_RECModel(SequentialBaseModel):
    def _build_seq_graph(self)

    def _attention_fcn(self, query, user_embedding)

Import

from recommenders.models.deeprec.models.sequential.sli_rec import SLI_RECModel

I/O Contract

Inputs

Name Type Required Description
self.item_history_embedding tf.Tensor Yes Embedding tensor of the user's item interaction history
self.cate_history_embedding tf.Tensor Yes Embedding tensor of the corresponding category history
self.target_item_embedding tf.Tensor Yes Embedding tensor of the target item being scored
self.iterator.mask tf.Tensor Yes Binary mask tensor indicating valid sequence positions
self.iterator.time_from_first_action tf.Tensor Yes Temporal feature: time elapsed from the user's first action
self.iterator.time_to_now tf.Tensor Yes Temporal feature: time elapsed from each action to the current time
hparams.attention_size int Yes Dimensionality of the attention layer for long-term modeling
hparams.hidden_size int Yes Hidden size for the Time4LSTMCell
hparams.att_fcn_layer_sizes list Yes Layer sizes for the attention FCN and alpha fusion FCN
query (_attention_fcn) tf.Tensor Yes Target item embedding used as the attention query
user_embedding (_attention_fcn) tf.Tensor Yes RNN output states used as user modeling

Outputs

Name Type Description
return (_build_seq_graph) tf.Tensor Concatenation of the adaptively fused user representation and target item embedding
return (_attention_fcn) tf.Tensor Attention-weighted user modeling output

Usage Examples

Basic Usage

from recommenders.models.deeprec.models.sequential.sli_rec import SLI_RECModel
from recommenders.models.deeprec.deeprec_utils import prepare_hparams

# Prepare hyperparameters from YAML config
hparams = prepare_hparams(
    "recommenders/models/deeprec/config/sli_rec.yaml",
    attention_size=40,
    hidden_size=40,
    att_fcn_layer_sizes=[64, 16, 1],
)

# Create and train the SLI_REC model
model = SLI_RECModel(hparams, iterator_creator)
model.fit(train_file, valid_file)

# Evaluate the model
eval_results = model.run_eval(test_file)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment