How LLMs and BERT Personalize Session Recommendations

Peter Bubenik · Sony AI · · Source

Step-by-Step Teaching

Step 1: Foundation — What is a Recommendation System?

Think of Netflix suggesting movies or Amazon suggesting products. These are recommendation systems.

Their core goal:

Suggest the right content to the right user at the right time

Why they matter:

  • Increase user engagement
  • Boost satisfaction
  • Improve retention (users keep coming back)

Step 2: What is Session-Based Recommendation (SR)?

The Problem with Traditional Recommenders

Traditional systems look at your entire history — everything you've ever clicked or bought.

Problem: Your interests change! What you wanted 2 years ago may not reflect what you want today.

The Session-Based Solution

A session = a group of interactions within a short time window

Example Session:
[Searched "running shoes"] → [Clicked Nike Air] → [Viewed socks] → ???
                                                                    ↑
                                              Recommend: Running shorts?

SR focuses on SHORT-TERM preferences — what does the user want right now?


Step 3: What is Session-Based Social Recommendation (SSR)?

Adding the Social Layer

SSR extends SR by asking:

"What are your friends interested in?"

Why social networks help:

  • Friends often share similar tastes
  • Social influence shapes purchasing/viewing decisions
  • More data = better personalization
SR:   [Your current session] → Recommendation

SSR:  [Your current session]
    + [Your historical sessions]        → Better Recommendation
    + [Your friends' preferences]

Step 4: The Two Big Problems with Current SSR Models

Problem 1: Limited Personalization

Current SSR models only look at the current session.

They ignore:

  • Who you are as a person
  • Your long-term personality/preferences
  • Your unique user profile

Analogy: Imagine a salesperson who helps you every day but never remembers anything about you — they only react to what you say right now.

Problem 2: Computational Inefficiency

Current SSR models use Graph-based algorithms to represent sessions.

Graph-based approach:
Items → Nodes
Interactions → Edges
Session → Complex Graph Structure

Why this is a problem:

  • Graphs are computationally heavy
  • Slow during training (learning phase)
  • Even slower during inference (real-time recommendation)
  • Not scalable for large platforms

Step 5: Introducing LLM-BRec — The Solution

LLM-BRec is a fusion framework combining two powerful AI technologies:

┌─────────────────────────────────────────┐
│              LLM-BRec                   │
│                                         │
│   ┌──────────┐      ┌───────────────┐   │
│   │   BERT   │  +   │     LLM       │   │
│   │(Sessions)│      │(User Profiles)│   │
│   └──────────┘      └───────────────┘   │
│                                         │
│         ↓ Fusion ↓                      │
│   Personalized Recommendation           │
└─────────────────────────────────────────┘

Step 6: Component 1 — BERT for Session Modeling

What is BERT?

BERT = Bidirectional Encoder Representations from Transformers

Key features:

FeatureWhat it means
BidirectionalReads text/sequence from BOTH directions
Transformer ArchitectureEfficient parallel processing
Self-Attention MechanismFocuses on what's most relevant

How BERT Solves Problem 2 (Efficiency)

Instead of building complex graphs, BERT treats a session like a sequence:

Graph Approach (Old):
Session → Build Graph → Run Graph Algorithm → Slow ❌

BERT Approach (New):
Session → [Item1, Item2, Item3, Item4] → Self-Attention → Fast ✅

Self-Attention — The Key Mechanism

Self-attention lets the model ask:

"Which items in this session are most relevant to each other?"

Session: [Running Shoes] [Socks] [Water Bottle] [Yoga Mat]
                ↑                      ↑
         High attention            Lower attention
         (related items)           (less related)

The model weighs relationships between items — relevant items get more attention, irrelevant ones get less.


Step 7: Component 2 — LLM for User Profile Generation

What is an LLM?

LLM = Large Language Model (e.g., GPT-4, LLaMA)

LLMs are trained on massive text data and can:

  • Understand context deeply
  • Generate human-like descriptions
  • Summarize complex information

How LLM Solves Problem 1 (Personalization)

LLM generates a rich user profile by analyzing:

  • Historical sessions
  • Social connections
  • Behavioral patterns
Input to LLM:
"User has viewed: hiking boots, trail maps, camping gear,
 protein bars over past 3 months. Friends like: outdoor sports"

LLM Output (User Profile):
"Outdoor enthusiast interested in hiking and camping,
 health-conscious, adventure-seeking"

This profile is then used at inference time to make recommendations more personal.


Step 8: The Fusion — How LLM + BERT Work Together

┌─────────────────────────────────────────────────────┐
│                   LLM-BRec Pipeline                 │
│                                                     │
│  TRAINING PHASE:                                    │
│  Sessions → BERT → Session Representations         │
│                                                     │
│  INFERENCE PHASE:                                   │
│  Session Representation (BERT)                      │
│           +                                         │
│  User Profile (LLM)          → Final Recommendation│
│           +                                         │
│  Social Network Data                                │
└─────────────────────────────────────────────────────┘

Key insight: LLM enhances the representation at inference stage — meaning real-time recommendations become smarter without slowing down training.


Step 9: Results and Validation

LLM-BRec was tested on 4 datasets:

  • 2 Social datasets
  • 2 Non-social datasets

Outcomes:

MetricResult
AccuracyOutperformed State-of-the-Art (SOTA) methods
Training TimeSignificantly reduced
Inference TimeSignificantly reduced
GeneralizationWorks on both social AND non-social data

Step 10: Summary — The Big Picture

PROBLEM                    SOLUTION              COMPONENT
─────────────────────────────────────────────────────────
Poor personalization   →   User Profile Gen  →   LLM
(ignores user identity)

Computational slowness →   Sequence Modeling →   BERT
(heavy graph methods)      with Self-Attention

Key Takeaways:

  1. SR captures short-term preferences; SSR adds social context
  2. Current SSR fails at personalization and efficiency
  3. BERT replaces slow graph methods with fast transformer-based session modeling
  4. LLM generates rich user profiles for deeper personalization
  5. Fusion of both creates a system that is faster AND more accurate

Quick Knowledge Check

Q1: Why is session-based recommendation better than traditional recommendation for capturing current intent?

Q2: What are the two main problems LLM-BRec tries to solve?

Q3: How does self-attention help BERT understand a session?

Q4: At which stage does LLM contribute in LLM-BRec — training or inference?

Q5: Why is replacing graph-based methods with BERT beneficial?

💡 Pro Tip: The core innovation of LLM-BRec is not just using LLM or BERT alone — it's the strategic fusion of both, where each component addresses a different weakness of existing systems.

More to study