Sequence Models (RNN / Transformer) for Recommendation Service widely used at OTT and e-Commerce

CK CK 3788 
Created at  
240 0 0

Sequence models treat a user’s history as an ordered sequence of interactions and predict the next item the user will engage with. Unlike matrix factorization or NCF — which treat history as an unordered bag — sequence models exploit order, recency, and short-term intent. The shift from “shopping for a tent last month” to “currently researching laptops” is exactly the kind of signal they capture.

Two architectural lineages dominate: recurrent neural network (RNN) models (GRU4Rec) and self-attention / Transformer models (SASRec, BERT4Rec). Transformers have largely become the default for their parallelism and ability to model long-range dependencies.



 

How It Works (The Math)

Let a user’s interaction sequence be S = (i₁, i₂, …, i_t). The model learns P(i_{t+1} | i₁ … i_t).

Recurrent (GRU4Rec)

Each item embedding is fed step by step into a GRU (Gated Recurrent Unit), which maintains a hidden state summarizing history:

h_t = GRU(h_{t-1}, emb(i_t)), then ŷ_{t+1} = softmax(W · h_t)

Trained session-by-session, originally with a pairwise ranking loss (BPR — Bayesian Personalized Ranking — / TOP1).

Self-Attention (SASRec)

Items are embedded and given positional encodings, then passed through stacked self-attention blocks. Attention weights how much each past item matters for the current prediction:

Attention(Q, K, V) = softmax( Q Kᵀ / √d ) V

SASRec is causal (left-to-right masking): position t may attend only to positions ≤ t, predicting the next item autoregressively.

Bidirectional (BERT4Rec)

Uses a masked-item objective like BERT: random items in the sequence are masked and predicted from both left and right context, giving richer representations at the cost of a different (non-autoregressive) training scheme.

Typical loss

Next-item prediction as classification over the catalog (often with sampled softmax for large catalogs) or a pairwise ranking loss.



 

Requirements

  • Timestamped, ordered interaction logs per user or per session.
  • Sequence preprocessing: sessionization, truncation/padding to a max length, recency windows.
  • Embedding tables for items (and optionally actions, categories, time gaps).
  • A GPU training stack and, for large catalogs, sampled softmax / negative sampling to make the output layer tractable.
  • Low-latency sequence serving: the user’s recent history must be assembled and encoded in real time at request.



 

Simplified Architecture

Sequence Models (RNN / Transformer) for Recommendation Service widely used at OTT and e-Commerce



 

Reference Architecture

Sequence Models (RNN / Transformer) for Recommendation Service widely used at OTT and e-Commerce


 

Reference Architecture (with Technology Stack)

The same flow on concrete tooling — Flink for sessionization, Redis for recent-history state, a Transformer (SASRec) trained on GPU, FAISS for retrieval, and near-real-time retraining off the Kafka stream.

Sequence Models (RNN / Transformer) for Recommendation Service widely used at OTT and e-Commerce


 

Signals & Features

The essential input is the ordered item sequence. Models are routinely enriched with per-step features: action type (click vs. purchase vs. skip), dwell time, time gaps between events (to encode recency and session boundaries), item category, and contextual features (device, time of day). Encoding the time delta explicitly helps the model distinguish a rapid in-session burst from interactions weeks apart.



 

Training & Serving Considerations

Causal models (SASRec) train efficiently because every position contributes a next-item prediction in parallel. The output layer over a huge catalog is the cost center, mitigated by sampled softmax. At serving time the user’s latest events must be incorporated — this is why sequence recommenders pair naturally with near-real-time feature pipelines and online/continuous training (the design philosophy behind systems like TikTok’s Monolith). The sequence is encoded into a query vector that hits an ANN (Approximate Nearest Neighbor) index over item embeddings.



 

Evaluation

Next-item prediction is evaluated with HR@k (Hit Ratio at k), NDCG@k (Normalized Discounted Cumulative Gain at k), and MRR (Mean Reciprocal Rank) under a leave-one-out (predict the last item) or temporal-split protocol. Because user intent shifts, temporal evaluation is mandatory — random splits leak future information and badly overstate performance. Online, watch session depth and immediate next-action engagement.



 

Strengths & Weaknesses

Strengths: captures order, recency, and short-term intent that static models ignore; excels at session-based and “next-item” recommendation; Transformers model long-range dependencies and parallelize well; naturally suited to fast-moving feeds.

Weaknesses: compute- and data-hungry; sensitive to sequence length and noise; cold-start for brand-new items/users persists; bidirectional variants add training complexity; real-time serving of fresh sequences raises infrastructure demands.



 

When to Use It

Sequence models shine wherever order and immediacy matter: short-video and music feeds, e-commerce sessions, news, and any context with strong intra-session intent. They are the backbone of modern “next item” and feed-ranking systems and are typically combined with two-tower retrieval and feature-rich ranking layers in a full production stack.

Tags Deep Learning Recs E-commerce Recommendations Machine Learning Next Item Prediction Personalized AI RNN Models Recommendation Systems Recommendations Architecture Sequence Models Session-Based Recs Transformer Models Facebook X
Comments 0
Similar posts
  1. Neural Collaborative Filtering (NCF) for Recommendation Service
    235
  2. Two-Tower Model for Recommendation Service having a Very Large Catalog
    258
  3. Hybrid Methods for Recommendation Service
    213
  4. Model-Based CF: Matrix Factorization for Recommendation Service
    177
  5. Memory-Based Collaborative Filtering for Recommendation Service
    186
  6. Wide & Deep / DeepFM for Recommendation Service (aka Ranking Service)
    247
  7. Content-Based Filtering for Recommendation Service (aka User-based Model)
    187
  8. Harnessing the Power of Random Forest Algorithm in Python
    657
  9. Mastering Model Persistence: Saving and Loading Trained Machine Learning Models in Python
    1,154
  10. YouTube's Recommendation System
    258
  11. Reinforcement Learning–Based Methods for CTR Improvement based on Recommendation System
    262
  12. Understanding and Implementing K-Nearest Neighbors (KNN) Algorithm in Python
    630
  13. Forecasting the Weather with PyTorch: A Beginner's Guide to Temperature Prediction
    1,430
  14. Getting Started with PyTorch: A Beginner's Guide to Building Your First Neural Network
    799
  15. Mastering AI: A Beginner's Guide to Python Programming and Beyond
    1,031
  16. Forecasting with Linear Regression and KNN Regression in Python
    920
  17. Vector Databases: From Embeddings to Application
    310
  18. Machine Learning Models for Ad Detection from a Video Stream
    185
  19. FAISS Already Does ANN... So Why Do Top Teams Still Pay for SageMaker?
    307
  20. Milvus & FAISS: Decoding Their ML Synergy
    276
  21. PyTorch example to Forcast Stock Price based on 10 days Dataset
    651
  22. Predicting Buyer Preferences with PyTorch: A Deep Learning Approach
    1,230
  23. Mastering Ad Budget Throttling: Static, PID, and ML Strategies
    316
  24. Ad Impression Forecasting (aka Ad Inventory Forecasting): Architecting for Scale, Speed, and Accuracy
    327
  25. AI-Powered Ad Fraud Detection: Architectural Strategies
    331
  26. Brand Safety: AI-Driven Content Moderation on AWS
    710
  27. Building a MCP server in PHP
    626
  28. How Netflix Runs Recommendations for Hundreds of Millions of Users Using Amazon SageMaker & Metaflow
    171
  29. Python ML Technologies used for the target Segmentation
    376
  30. Coding Revolution with Claude Code & MoAI ADK(Agent Development Kit)
    726
  1. A Complete Guide to LLM Dataset Formats: From Pre-Training to DPO in JSONL
    198
  2. Comparison of ChatGPT, Gemini, and Grok
    554
  3. MLOps Explained: Spark, Flink, and Reference Architecture Deep Dive
    237
  4. AI-based Image Creation based on Bing Image Creator
    981
  5. ChatGPT App (flowGPT) to create images with text
    1,030
  6. TikTok's Recommendation System - Monolith
    286
  7. Things to Know for AI-driven, Multimodal Content Personalization.
    196
  8. Deep Dive into Vector Databases: Understanding Collections (Not Tables) and Embeddings
    230
  9. Image Embeddings for Vector Databases
    241
  10. Vector Databases: From Embeddings to Application
    310
  11. Scaling Vector Search: How to Architect FAISS on AWS EKS and ECS
    158
  12. Reinforcement Learning–Based Methods for CTR Improvement based on Recommendation System
    262
  13. YouTube's Recommendation System
    258
  14. Wide & Deep / DeepFM for Recommendation Service (aka Ranking Service)
    247
  15. Two-Tower Model for Recommendation Service having a Very Large Catalog
    258
  16. Neural Collaborative Filtering (NCF) for Recommendation Service
    235
  17. Common Recommendation Service Architecture
    525
Recently updated
  1. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    27
  2. Why SPF and DKIM Are Essential for Linux Email Servers?
    24
  3. How do I create animated background for Google Meet?
    19,708
  4. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    217
  5. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    85
  6. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    153
  7. Array of arguments passed to script in PHP
    85
  8. Invalid Auction Storms in Ad Tech
    93
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    197
  10. The Two Clocks of Ad Server Architecture
    63
  11. Frequency Cap Architecture Overview
    509
  12. Collecting Proof-of-Play from 100,000 Screens
    141
  13. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    280
  14. What is RedisVL?
    105
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    224
  16. TPU & GPU Cluster Management Tools
    232
  17. The Concept of Scaffolding in AI Agents
    221
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    575
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    252
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    326
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    197
  22. Machine Learning: Training vs. Ranking
    213
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    217
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    189
  25. Designing a Data Curation System Around a Vector Database
    215
  26. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    229
  27. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    649
  28. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    185
  29. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    207
  30. Understanding Data Lineage
    252