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 NextItNet Model

From Leeroopedia


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

Overview

The NextItNetModel class implements a dilated convolutional generative network for next-item recommendation, using causal residual blocks to capture long-range sequential dependencies without recurrence.

Description

NextItNetModel extends SequentialBaseModel and implements the _build_seq_graph method to construct a stack of dilated causal CNN residual blocks for sequential recommendation. The architecture is based on the paper "A Simple Convolutional Generative Network for Next Item Recommendation" (Yuan et al., WSDM 2019).

The model operates differently during training and inference. During training, it subsamples history embeddings (taking every train_num_ngs + 1-th entry) and processes the full sequence through the dilated residual blocks, producing predictions at every sequence position (generative training). During inference, only the last position output is used for prediction.

Each residual block (_nextitnet_residual_block_one) applies a sequence of operations: layer normalization, ReLU activation, 1x1 convolution (dimensionality reduction to half channels), layer normalization, ReLU, dilated causal convolution (with configurable dilation rates and kernel sizes), layer normalization, ReLU, and a final 1x1 convolution back to full channel size. A residual connection adds the block input to the output. The dilated causal convolutions use front-padding to ensure that predictions at each position only depend on past positions.

The _conv1d method implements 1D convolution via TensorFlow's atrous_conv2d for dilated convolutions with causal padding, or standard conv2d for non-causal cases. The _layer_norm method provides custom layer normalization with learnable gamma and beta parameters.

Usage

Use NextItNetModel when building a sequential recommendation system that benefits from a non-recurrent architecture with logarithmic receptive field growth. It is particularly well-suited for datasets with strong sequential patterns where capturing long-range dependencies efficiently is important. The model requires a dataset with strong sequence signals and uses generative training (predicting all positions), which can be more sample-efficient than discriminative training.

Code Reference

Source Location

Signature

class NextItNetModel(SequentialBaseModel):
    """NextItNet Model"""

    def _build_seq_graph(self):
        """The main function to create nextitnet model.
        Returns:
            object: The output of nextitnet section.
        """

    def _training_output(self):
        """Produces output during training by repeating dilated input for all negative samples."""

    def _normal_output(self):
        """Produces output during inference using only the last sequence position."""

    def _nextitnet_residual_block_one(
        self, input_, dilation, layer_id, residual_channels, kernel_size,
        causal=True, train=True
    ):
        """Dilated CNN residual block with layer normalization."""

    def _conv1d(
        self, input_, output_channels, dilation=1, kernel_size=1,
        causal=False, name="dilated_conv"
    ):
        """1D dilated convolution using atrous_conv2d or standard conv2d."""

    def _layer_norm(self, x, name, epsilon=1e-8, trainable=True):
        """Layer normalization with learnable gamma and beta."""

Import

from recommenders.models.deeprec.models.sequential.nextitnet import NextItNetModel

I/O Contract

Inputs

Name Type Required Description
hparams HParams Yes Hyperparameters object containing model configuration including dilations, kernel_size, train_num_ngs, max_seq_length, and layer_sizes
iterator_creator object Yes An iterator to load sequential training and evaluation data
graph tf.Graph No An optional TensorFlow graph; a new one is created if not provided
seed int No Random seed for reproducibility

Outputs

Name Type Description
model_output tf.Tensor During training: tensor of shape (batch * (train_num_ngs + 1) * max_seq_length, concat_dim) with predictions at all positions for all negative samples. During inference: tensor of shape (batch, concat_dim) with the prediction at the last sequence position concatenated with the target item embedding.

Usage Examples

Basic Usage

import tensorflow as tf
from recommenders.models.deeprec.models.sequential.nextitnet import NextItNetModel
from recommenders.models.deeprec.deeprec_utils import prepare_hparams

# Prepare hyperparameters with NextItNet-specific settings
hparams = prepare_hparams(
    yaml_file="recommenders/models/deeprec/config/nextitnet.yaml",
    dilations=[1, 2, 4, 1, 2, 4],
    kernel_size=3,
    train_num_ngs=4,
    max_seq_length=50,
    epochs=10,
    learning_rate=0.001,
)

# Create model
model = NextItNetModel(hparams, iterator_creator)

# Train the model
model.fit(train_file, valid_file, valid_num_ngs=4)

# Run evaluation
eval_results = model.run_eval(test_file, num_ngs=4)

# Make predictions
model.predict(infile_name, outfile_name)

Related Pages

Page Connections

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