Ai paper reader

From samirpatil2000/skills · View interactive version

Ai paper reader is an AI agent skill from the GitHub repository samirpatil2000/skills. In-depth analysis of AI papers, generating publish-ready professional reading notes

How to use this skill

Skill file

AI Paper Reading Notes Generator

Core Goal

Generate reading notes ready to publish directly to technical communities (Zhihu, Juejin, WeChat Official Accounts, Medium, Substack, etc.).

Note requirements:


Writing Standards

Do

  1. Professional, precise phrasing
  1. Explain from simple to deep
  1. Clearly structured organization
  1. Valuable in-depth analysis

Must Avoid

  1. AI clichés and templated phrasing
  1. Hollow summaries and evaluations
  1. Excessive formatting decoration
  1. Unnecessary first person

Note Structure

0. Metadata (start of the note)

Every note should begin with the following information, so readers can quickly judge whether to continue reading:

> **Paper**: Actions Speak Louder than Words: Trillion-Parameter Sequential Transducers for Generative Recommendations
> **Authors**: Meta AI
> **Published**: ICML 2024
> **Reading time**: ~15 minutes
> **Difficulty**: ⭐⭐⭐⭐ (requires Transformer and recommender-systems background)
> **Prerequisites**: Attention mechanism, DLRM, Scaling Law concepts

Difficulty level guide:

1. TL;DR

Summarize the paper's core innovation in 2-3 sentences so readers without time to read in depth can quickly grasp the key points.

## TL;DR

Traditional recommendation models like DLRM rely on heavy manual feature engineering and cannot scale. This paper reframes recommendation as a sequence generation problem. The core innovation is the HSTU architecture: replacing Softmax with Pointwise Attention to preserve the absolute strength of user preferences, making recommendation systems exhibit an LLM-like Scaling Law for the first time.

Requirements:

2. Paper Overview

Concisely answer three questions:

## Paper Overview

**Problem**: Large-scale recommendation systems can't continuously improve quality by simply increasing compute the way LLMs can

**Approach**: Shift recommendation from "feature engineering + discriminative model" to "sequence modeling + generative model"

**Contributions**:
1. Proposes the Generative Recommenders (GRs) paradigm, achieving a Scaling Law for recommendation systems
2. Designs the HSTU architecture, replacing Softmax with Pointwise Attention to preserve strength information
3. Proposes the M-FALCON inference algorithm for efficient candidate scoring

3. Background and Motivation

Explain the problems with existing methods and why a new method is needed:

4. Core Method (the main focus)

This is the core section of the notes, and must be complete, in-depth, and without omissions.

Organization
  1. Overall architecture
  1. Detailed breakdown of core modules (for each key module)
  1. Key technical details
Example format
## Core Method

### Overall Architecture

[architecture diagram]

Data flow: user history sequence → Embedding → HSTU Layers × L → prediction head

### HSTU Layer in Detail

#### Input/Output
- Input: X ∈ R^{N×d}, where N is sequence length and d is embedding dimension
- Output: Y ∈ R^{N×d}

#### Core Formulas

**Pointwise Projection**:
$$U, V, Q, K = \text{Split}(\phi_1(f_1(X)))$$

Where:
- $\phi_1$: SiLU activation function
- $f_1$: a single linear transformation layer
- Split divides the output into four vectors

**Spatial Aggregation**:
$$A(X)V(X) = \phi_2(Q(X)K(X)^T + r_{ab}) V(X)$$

Key point: SiLU is used instead of Softmax to preserve the absolute strength of attention.

#### Code Implementation

class HSTULayer(nn.Module):

def forward(self, x):

# Pointwise Projection

projected = F.silu(self.proj_in(x))

u, v, q, k = projected.split([...], dim=-1)

# Spatial Aggregation (not Softmax!)

attn = F.silu(q @ k.T + self.rel_bias)

out = self.norm(attn @ v) * u

return x + self.proj_out(out)


#### Design Analysis

**Why SiLU instead of Softmax?**

Softmax normalizes attention into a probability distribution, which loses important information in the recommendation setting...

5. Experimental Analysis

Don't just list numbers — extract the key conclusions:

6. Deep-Dive Q&A

Use carefully designed questions to help readers deeply understand the key points of the paper.

Answers are shown directly, without collapsing/folding.

## Deep-Dive Q&A

### Q1: Why isn't Softmax Attention suited to the recommendation setting?

The recommendation setting needs to predict the **absolute strength** of user preference (e.g., watch time), not just **relative ranking**.

Consider two users:
- User A: 10 historical interactions
- User B: 100 historical interactions

With Softmax, both users' attention weights get normalized to [0,1], causing the information that "User B is more active" to be lost.

Pointwise Attention preserves the accumulated raw magnitude, so the model can learn the difference in activity level.

### Q2: How does HSTU replace the Transformer's 6 linear layers with just 2?

A standard Transformer layer needs:
- Q, K, V projections: 3 linear layers
- Output projection: 1 linear layer
- FFN: 2 linear layers (expand + compress)

HSTU's simplification:
1. **Fuses the Q, K, V, U projections**: a single linear layer produces all four vectors at once
2. **Replaces the FFN with U-gating**: `output * U` achieves a similar nonlinear transformation

The cost is reduced per-layer expressive capacity, which is compensated for by stacking more layers.

### Q3: Why can Stochastic Length training drop 70% of tokens with almost no effect on performance?

The key lies in the statistical properties of user behavior:

1. **Temporal repetition**: users repeatedly interact with similar content, so there's high information redundancy
2. **Low-rank interests**: 10,000 interactions may only involve 20 major interest categories
3. **Recency priority**: sampling weights recent behavior more heavily, keeping the most relevant information

As long as the sample size exceeds a certain multiple of the number of interest categories, it can cover all interests with high probability.

7. Summary and Reflection

Objectively summarize the paper's contributions and limitations:

## Summary

### Core Contributions
- Demonstrates that recommendation systems can follow a Scaling Law
- Proposes an Attention variant suited to the recommendation setting

### Limitations
- Cold-start scenarios: the advantage is less clear when history sequences are too short
- Computational cost: requires substantial GPU resources
- Real-time performance: latency challenges for long-sequence inference

### Applicable Scenarios
- Scenarios with rich user history (>100 interactions)
- Ample compute resources available
- Real-time requirements are not extremely strict

Directory Structure Convention

Papers and reading notes should be organized under a unified subdirectory structure for easy management and retrieval:

paper-notes/
├── hstu/                           # one directory per paper, short name
│   ├── paper.pdf                   # original paper PDF
│   ├── README.md                   # reading notes (main file)
│   └── images/                     # extracted figures
│       ├── fig1_architecture.png
│       ├── fig2_method.png
│       └── fig3_scaling.png
│
├── attention-is-all-you-need/
│   ├── paper.pdf
│   ├── README.md
│   └── images/
│
└── din-deep-interest-network/
    ├── paper.pdf
    ├── README.md
    └── images/

Naming conventions:

Image naming convention:

fig{number}_{type}_{brief description}.png

Types:
- arch: architecture diagram
- method: method flowchart
- result: experimental results
- ablation: ablation study
- compare: comparison figure

Examples:
- fig1_arch_overall.png
- fig2_method_attention.png
- fig3_result_scaling.png

Q&A Section Design Guide

Question Types

  1. Principle-understanding type
  1. Detail-clarification type
  1. Boundary-condition type
  1. Extension-thinking type

Answer Requirements


Figure/Table Handling

Figures/tables that must be extracted

Figure caption convention

![Architecture Diagram](images/fig1_architecture.png)

**Content shown**: HSTU's overall architecture, with DLRM comparison on the left

**Key information**:
- Input is a unified interleaved item-action sequence
- HSTU Layers can be stacked indefinitely
- Output is a multi-task prediction head

**Corresponds to text**: described in detail in Section 3.2

Figure Extraction Tools

Figures in academic papers come in two types, requiring different extraction methods:

| Type | Characteristics | Extraction Method |

|------|------------------|--------------------|

| Embedded images | PNG/JPEG images inserted by the authors | get_images() |

| Vector graphics | Drawn figures like architecture/flow diagrams | cluster_drawings() |

Method 1: Extract Embedded Images

Suitable for bitmaps directly inserted into the paper (e.g., experimental result screenshots, photos):

import fitz  # PyMuPDF
import os

def extract_embedded_images(pdf_path, output_dir):
    """Extract bitmap images embedded in the PDF"""
    os.makedirs(output_dir, exist_ok=True)
    doc = fitz.open(pdf_path)

    for page_num in range(len(doc)):
        page = doc[page_num]
        images = page.get_images(full=True)

        for img_idx, img in enumerate(images):
            xref = img[0]
            base = doc.extract_image(xref)
            image_bytes = base["image"]
            image_ext = base["ext"]

            # Filter out images that are too small (likely icons/decoration)
            if base["width"] > 100 and base["height"] > 100:
                output_path = f"{output_dir}/page{page_num+1}_img{img_idx+1}.{image_ext}"
                with open(output_path, "wb") as f:
                    f.write(image_bytes)

    doc.close()

Method 2: Extract Vector Graphics (recommended)

Suitable for vector figures drawn in the paper, such as architecture diagrams, flowcharts, and charts:

import fitz
import os

def extract_vector_figures(pdf_path, output_dir, dpi=200, min_size=100):
    """
    Use cluster_drawings() to identify vector-graphic regions and screenshot them

    Args:
        pdf_path: path to the PDF file
        output_dir: output directory
        dpi: output resolution (default 200; increase to 300 for sharper images)
        min_size: minimum size threshold to filter out decorative lines (default 100pt)
    """
    os.makedirs(output_dir, exist_ok=True)
    doc = fitz.open(pdf_path)

    figures = []
    for page_num in range(len(doc)):
        page = doc[page_num]

        # Identify clustered regions of vector graphics
        # x_tolerance/y_tolerance control the merge distance for adjacent elements
        try:
            drawing_rects = page.cluster_drawings(
                x_tolerance=3,
                y_tolerance=3
            )
        except Exception:
            # Some PDFs may not support this — skip
            continue

        for idx, rect in enumerate(drawing_rects):
            # Filter out regions that are too small (likely lines/decoration)
            if rect.width < min_size or rect.height < min_size:
                continue

            # Expand the boundary to avoid cropping too tightly
            rect = rect + (-10, -10, 10, 10)
            # Make sure it doesn't exceed the page boundary
            rect = rect & page.rect

            # High-resolution screenshot
            zoom = dpi / 72
            mat = fitz.Matrix(zoom, zoom)
            pix = page.get_pixmap(matrix=mat, clip=rect)

            output_path = f"{output_dir}/page{page_num+1}_fig{idx+1}.png"
            pix.save(output_path)
            figures.append({
                "page": page_num + 1,
                "path": output_path,
                "rect": rect
            })

    doc.close()
    return figures

Method 3: Manually Specify a Region to Crop

When automatic detection doesn't work well, you can manually specify coordinates:

import fitz

def crop_figure(pdf_path, page_num, rect, output_path, dpi=200):
    """
    Crop a specific region from a given page of a PDF

    Args:
        pdf_path: path to the PDF
        page_num: page number (starting from 1)
        rect: (x0, y0, x1, y1) coordinates, in points (pt), 72pt = 1 inch
        output_path: output image path
        dpi: resolution
    """
    doc = fitz.open(pdf_path)
    page = doc[page_num - 1]

    clip = fitz.Rect(rect)
    zoom = dpi / 72
    mat = fitz.Matrix(zoom, zoom)

    pix = page.get_pixmap(matrix=mat, clip=clip)
    pix.save(output_path)
    doc.close()

# Example usage: crop a region on page 2
# Coordinates can be checked with a PDF viewer, or fine-tuned after identifying with Method 2
crop_figure(
    "paper.pdf",
    page_num=2,
    rect=(50, 100, 550, 400),  # top-left (50,100) to bottom-right (550,400)
    output_path="./images/fig1_architecture.png"
)

Smart Extraction (combined approach)

Automatically tries multiple methods to extract all figures:

import fitz
import os

def smart_extract_figures(pdf_path, output_dir, dpi=200):
    """
    Intelligently extract all figures from a paper
    1. First use cluster_drawings to identify vector graphics
    2. Then extract embedded bitmaps
    3. Automatically filter and deduplicate
    """
    os.makedirs(output_dir, exist_ok=True)
    doc = fitz.open(pdf_path)
    results = {"vector": [], "embedded": []}

    for page_num in range(len(doc)):
        page = doc[page_num]

        # 1. Extract vector graphics
        try:
            rects = page.cluster_drawings(x_tolerance=3, y_tolerance=3)
            for idx, rect in enumerate(rects):
                if rect.width > 100 and rect.height > 100:
                    rect = (rect + (-10, -10, 10, 10)) & page.rect
                    zoom = dpi / 72
                    pix = page.get_pixmap(matrix=fitz.Matrix(zoom, zoom), clip=rect)
                    path = f"{output_dir}/p{page_num+1}_vec{idx+1}.png"
                    pix.save(path)
                    results["vector"].append(path)
        except:
            pass

        # 2. Extract embedded images
        for img_idx, img in enumerate(page.get_images(full=True)):
            xref = img[0]
            base = doc.extract_image(xref)
            if base["width"] > 100 and base["height"] > 100:
                path = f"{output_dir}/p{page_num+1}_img{img_idx+1}.{base['ext']}"
                with open(path, "wb") as f:
                    f.write(base["image"])
                results["embedded"].append(path)

    doc.close()
    print(f"Extraction complete: {len(results['vector'])} vector figures, {len(results['embedded'])} bitmaps")
    return results

# Example usage
results = smart_extract_figures("paper.pdf", "./images/")

FAQ

Q: The extracted image contains multiple figures merged together?

Reduce the x_tolerance and y_tolerance parameters (e.g., to 1-2) to make clustering stricter.

Q: A single figure gets split into multiple pieces?

Increase the tolerance parameters (e.g., to 10-20) to merge adjacent elements.

Q: Some figures aren't being detected?

  1. It may be an embedded image — try the get_images() method
  2. Use the manual region-specification method

Q: The image is blurry?

Increase the dpi parameter to 300 or higher.


Usage

Basic usage

Please read this paper and generate a professional reading note suitable for publishing to a technical community.

Specifying focus areas

Please read this paper, with a focus on analyzing:
1. The differences between HSTU and the standard Transformer
2. The setup and conclusions of the Scaling Law experiments
3. Feasibility of deployment in industrial settings

Comparative analysis

Please compare and analyze how these two papers solve problem XXX differently.

Technical Requirements

Content Completeness

Depth Requirements

Readability


Dependencies

# Image extraction
pip install pymupdf

# PDF to image (optional)
pip install pdf2image
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.