Skip to content

下面这份笔记严格以你上传的《Chap10 — LLMs in Data Mining》71 页课件为基础整理,重点不是简单复述,而是按照“为什么需要下一步方法”的逻辑重新组织。对于课件中属于历史性模型列表、产品示例等内容,我按课件原样保留其教学含义,不用今天的外部资料替换。

重要程度统一标记为:

  • ★★★:核心概念 / 很可能直接考 / 必须能解释
  • ★★☆:重要方法、案例或比较,需要理解
  • ★☆☆:背景、实例、模型名称,知道即可

Chapter 10 — LLMs in Data Mining

0. 全章到底在解决什么问题? ★★★

这章真正的主线不是“介绍 ChatGPT”,而是:

如何把原本只做语言建模的 Large Language Model,逐步变成一个可以理解任务、处理非结构化数据、调用知识、参与传统 Data Mining 任务、甚至操作表格的通用数据挖掘接口。

因此可以把整章理解成下面这棵“进化树”:

text
Language Modeling
预测下一个 token / 计算文本概率


Large Language Models
大数据 + 大模型 + Transformer + 大算力

        ├── 问题:模型有能力,但如何把人的任务表达给模型?

Prompt Engineering
clear instruction / few-shot / structured output / reasoning

        ├── 问题:现实数据不是干净的一段文本

Unstructured Data Preprocessing
Normalization → Elements → Metadata → Chunking

        ├── 问题:处理后的数据如何真正用于 Data Mining?

LLM-Enhanced Data Mining
Pattern Mining
Classification
Clustering
Outlier Detection

        ├── 更进一步:表格本来不是自然语言

LLM for Tabular Data
   ├── LIFT:把结构化任务语言化
   ├── CAAFE:让 LLM 提供领域知识并生成特征
   └── TableLLM:
       小表 → textual reasoning
       大表 → code execution

这一演进有一个非常重要的思想:

LLM 在 Data Mining 中不一定直接取代传统算法。
它越来越多地成为一种 semantic interface / reasoning engine / knowledge source / tool controller。

这是整章最值得理解的抽象。


1. Basic Concepts of Large Language Models

1.1 Language Modeling Problem ★★★

课件首先没有从“ChatGPT 是什么”开始,而是从最基本的问题开始:

一段文本到底有多 plausible?

例如:

  • Jane went to the store.
  • store to Jane went the.
  • Jane went store.
  • Jane goed to the store.

语言模型应该给自然、语法正确、语义合理的句子更高概率。

课件 Page 4 给出的核心思想就是:

即:

对一整段文本赋予概率。

例如课件示意:

而更自然连贯的上下文可能有:

由于

模型认为第二种语言序列更 plausible。


2. Language Model 的核心数学公式 ★★★

Page 5 给出的最关键公式:

课件图中主要写成乘积形式:

2.1 每一个符号

符号含义
sequence 中 token 的数量
当前预测位置
个 token
已经出现的 context
给定前文后,第 个 token 的条件概率

也经常简记:

于是:


2.2 为什么联合概率能够写成这样? ★★★

来自 probability chain rule。

从两个变量开始:

三个变量:

推广:

所以语言建模这个看起来极其复杂的问题:

“这整个句子的概率是多少?”

可以被拆成:

“根据已经看到的 token,下一个 token 是什么?”

这正是 autoregressive language model 的底层逻辑。


2.3 直觉 ★★★

Page 5 的例子是:

the students opened their ___

模型对 vocabulary 中所有可能 token 分配概率,比如:

  • books
  • laptops
  • exams
  • minds
  • ...

实际上模型输出的是:

对 vocabulary 中每一个候选 token 都有一个概率。

满足:

最终可以选择概率最大的 token,也可以按照这个概率分布采样。


3. Language Model 到底学到了什么? ★★★

Page 6 把语言模型描述成四种“judge”。

3.1 Judge of grammaticality

判断语法合理性:

The boy runs.

通常应该比:

The boy run.

概率更高。


3.2 Judge of semantic plausibility

不仅看 grammar,还看 semantic meaning。

例如:

The woman spoke.

通常比:

The sandwich spoke.

更合理。

也就是说:


3.3 Enforcer of stylistic consistency

语言模型还会根据 context 学习 discourse style。

比如:

Hello, how are you this evening?
Fine, thanks, how about you?

比突然出现:

Has your house ever been burgled?

在一般对话上下文中更加一致。


3.4 Repository of knowledge (?) ★★★

模型可能学到:

Barack Obama was the 44th President of the United States.

因此模型看起来像某种 knowledge repository。

但课件这里特意标了问号:

repository of knowledge (?)

并提醒:

this is very difficult to guarantee.

这直接为后面的 hallucination 埋下伏笔。

逻辑非常重要:

text
LLM 能生成高概率文本

高概率 ≠ 事实正确

因此模型表现得“像有知识”

但不能保证知识真实

Hallucination

Retrieval + grounded answering

4. Why Language Modeling? ★★☆

Page 7 给出经典应用。

4.1 Machine Translation

比较不同目标句子的概率。

例如:

模型更偏向自然语言中的搭配。


4.2 Spelling Correction

如果候选表达有:

about fifteen minutes from

与错误表达,则选择语言概率更高的一个。

本质依然是:

课件没有显式给这个公式,但这就是 Page 7 所表达的决策逻辑。


4.3 Speech Recognition

声学模型可能产生多个 candidate sequence:

Language Model 可以帮助选择 linguistic plausibility 较高的结果。


4.4 其他应用

课件列出:

  • summarization
  • question answering
  • handwriting recognition
  • OCR
  • etc.

这里应该理解的不是死记任务名,而是:

只要任务能够被表述成“生成某个合理的 token sequence”,language modeling 就可能参与其中。


5. Unified Language Modeling ★★★

Pages 8–9 是很重要的思想转折。

传统 NLP:

text
Translation       → 一个模型
Summarization     → 一个模型
Sentiment         → 一个模型
Question Answering→ 一个模型
Classification    → 一个模型

Unified Language Modeling:

text
Task + Input

Prompt / textual format

One language model

Textual output

Page 8 用 T0 作为例子,把大量 NLP tasks 统一进 text-to-text 框架。

包括:

  • summarization
  • sentiment analysis
  • question answering
  • multiple-choice
  • natural language inference
  • classification
  • commonsense reasoning 等。

核心转变:

这其实也直接预示了后面的 LIFT:

如果自然语言任务能够统一为 text-to-text,那么 tabular / image features / molecule 是否也能先 serialization 成文本,再统一处理?

答案就是 LIFT。


6. 从 Language Model 到 Large Language Model ★★★

6.1 ChatGPT 的直觉解释

Page 10:

A large function doing a game of word solitaire.

也就是说,可以粗略认为:

不是:

而是:

其中 是 vocabulary size。

因此同一个问题可以有不同输出。


6.2 多轮对话为什么成立? ★★★

假设对话:

下一轮不是只使用当前问题:

而是把历史 conversation 放入 context:

所以 Page 10 的核心结论:

Use all previous dialogues and current round's questions as input.

多轮对话从建模上并没有一个神秘的“conversation mechanism”。

它仍然是:

只不过 context 里包含 conversation history。


7. 为什么 Language Model 会变成 Large Language Model? ★★★

Page 11 给出三个关键 scaling 条件:

  1. Transformer allows fast parallel computation on many GPUs.
  2. 可以训练大量数据。
  3. 可以构造 many layers / large model。

于是课件定义:

A large language model is a language model with a large number of parameters, trained on large amounts of data, for a long period of time.

可以概括为:

为什么 Transformer 很重要?

课件这里没有展开 Transformer 数学公式,因此期末本章不必从这里推 Attention。

这里的教学重点只是:


8. Scaling 的代价 ★★☆

Page 12 的 training price 图显示了从:

  • GPT-1
  • BERT
  • GPT-2
  • GPT-3
  • PaLM
  • GPT-4

训练成本显著增长。

本页的考试意义不是背具体价格,而是:

这也是“Large”的另一面。


9. Diverse LLMs ★☆☆

Page 13 给出的简单经验定义:

Language Models That Have Many Parameters (Over 1B)

课件随后展示不同 model families。

Page 14 按课件列出的典型模型包括:

ModelDeveloperAccessParameters(课件)
GPT-4oOpenAIAPIUnknown
SoraOpenAIAPIUnknown
Claude 3.5AnthropicAPIUnknown
Grok-1xAIOpen-Source314B
Mistral 7BMistral AIOpen-Source7.3B
Mixtral 8x22BMistral AIOpen-Source141B
PaLM 2Google课件误列为 Open-Source(实际未公开权重)340B
Stable LM 2Stability AIOpen-Source1.6B / 12B
Gemini 1.5Google DeepMindAPIUnknown
GemmaGoogle DeepMindOpen-Source2B / 7B
Llama 3.1Meta AIOpen-Source405B
Phi-3MicrosoftBoth3.8B

这里按课件记忆即可;但 PaLM 2 的 Access 标注是课件错误,不应当作事实记忆。

Page 15 进一步强调:

GPT / Llama / PaLM 等不是孤立模型,而是 model family。

例如:

text
GPT family
 ├─ GPT-1
 ├─ GPT-2
 ├─ GPT-3
 ├─ InstructGPT
 ├─ ChatGPT
 └─ GPT-4 ...

LLaMA family
 ├─ LLaMA
 ├─ Alpaca
 ├─ Vicuna
 └─ ...

PaLM family
 └─ ...

重要程度较低,不建议花大量期末复习时间背家谱。


10. What Can LLM Do? ★★☆

Pages 17–21 给出五种应用:

  1. Code generation
  2. Math reasoning
  3. Conversational agent
  4. Long-context summarization
  5. Advanced search engine

这里其实是在说明 LLM 能力从:

扩展到:


11. Page 18 数学推理示例 ★☆☆

课件使用 Llemma 展示 mathematical reasoning。

给定:

求:

交换求和顺序:

因为是有限 范围,可以写:

内层是 geometric series:

整理:

又因为:

因此:

形成 telescoping series:

中间项全部消去:

注意:

这个数学题本身不是 Data Mining 的核心考试知识点。课件用它证明“LLM 可以执行多步数学 reasoning”。


12. Prompt Engineering

这一部分是本章第一个非常可能直接考定义、简答题的模块。

整体框架:

text
Principle 1
Clear and specific instructions

        ├─ delimiters
        ├─ structured output
        ├─ condition checking
        └─ few-shot examples

Principle 2
Give the model time to think

        ├─ specify reasoning steps
        └─ solve before judging

Model limitation
Hallucination


Retrieval first
Grounded answer second

13. Principle 1 — Clear and Specific Instructions ★★★

课件特意强调:

prompt 越短并不意味着越好。

真正目标是减少:


13.1 Tactic 1: Use Delimiters ★★★

Page 24 给出的 delimiter:

  • triple quotes """
  • triple backticks
  • triple dashes ---
  • angle brackets < >
  • XML tags <tag></tag>

作用是明确:

text
instruction

delimiter

data/content

例如:

text
Summarize the text delimited by triple backticks.

```text to summarize```

Why?

没有 delimiter 时:

之间的 boundary 不清晰。

有 delimiter:

因此可减少:

  • parsing ambiguity
  • instruction 与 document content 混淆

但 delimiter 只是边界提示,不能单独防止 prompt injection,也不是安全控制。

Page 24 图中尤其展示:

文档内部可能出现“forget the previous instructions...”

delimiter 帮助模型理解:

这是被处理的文本,而不是新的 system instruction。


14. Tactic 2 — Ask for Structured Output ★★★

Page 25:

要求输出:

  • HTML
  • JSON
  • etc.

例如:

Why?

非结构化回答:

text
The first book is ..., second ...

机器难以稳定解析。

结构化:

json
[
  {"title": "...", "author": "...", "genre": "..."}
]

更适合 downstream pipeline。

核心思想:

尤其在 Data Mining pipeline 中很重要。


15. Tactic 3 — Check Whether Conditions Are Satisfied ★★★

Page 26:

先检查:

执行任务所需 assumptions 是否成立。

逻辑:

text
Input

Condition satisfied?
 ├─ Yes → perform task
 └─ No  → report that task is not applicable

举例:

如果要求:

从文本中提取操作步骤。

应该先判断文本是否真的包含 sequence of instructions。

否则不应该凭空制造 Step 1, Step 2。

这也是减少 hallucination 的基础机制之一。


16. Tactic 4 — Few-shot Prompting ★★★

定义:

Give successful examples of completing task, then ask model to perform the task.

形式:

作为 demonstrations,然后输入:

要求模型生成:

关键点:

Few-shot prompting ≠ model parameter training。

模型参数没有因此发生 gradient update。

它是通过 context examples 告诉模型:

  • task format
  • desired style
  • input-output mapping
  • constraints

17. 从 Zero-shot 到 Few-shot 的逻辑演进 ★★★

方法给模型的信息优点问题
Zero-shot只有 instruction简洁ambiguous
Better instruction更详细任务定义ambiguity ↓难表达隐式 pattern
Few-shotinstruction + examplesstyle/task mapping 更明确context 更长

因此:

解决的是:

“我用语言很难完全说清楚我要什么。”


18. Principle 2 — Give the Model Time to Think ★★★

Page 28。

这里的“time”不是单纯 wall-clock time。

本质是:

让模型经过更明确的 intermediate reasoning structure,而不是直接生成 final answer。


18.1 Tactic 1 — Specify Steps ★★★

例如:

text
Step 1: summarize
Step 2: extract names
Step 3: determine ...
Step N: produce result

抽象表示:

直接:

分步:

其中 是 intermediate computation / reasoning stage。

优势:

  • 减少漏步骤
  • 将复杂任务 decomposition
  • 约束执行顺序

19. Tactic 2 — Solve Before Judging ★★★

Page 29 的例子:

Determine whether student's solution is correct.

直接把学生答案给模型:

可能造成 anchoring:

模型沿着学生的错误 reasoning 继续走。

更好的设计:

课件表述:

instruct the model to work out its own solution before rushing to a conclusion.

解决的问题:


20. Model Limitation — Hallucination ★★★

定义必须会:

Hallucination:LLM makes statements that sound plausible but are not true.

最关键的区别:

这实际上回到了 Page 4。

语言模型训练的目标首先是:

而不是一个显式:

判定函数。

因此一个错误事实如果语言上非常自然:

依然可能很高。


21. 减少 Hallucination:Retrieval → Answer ★★★

Page 30 提出的核心策略:

  1. First find relevant information — retrieval
  2. Then answer based on relevant information.

流程:

text
Question

Retrieve relevant evidence

Context

LLM

Grounded answer

即:

其中:

  • :query
  • :retrieved evidence
  • :answer

相比:

现在:

这就是后面 Page 49 LLM-assisted preprocessor 图的核心基础,也是现代 RAG 思想的教学雏形。


22. Iterative Prompt Development ★★★

Page 31 不鼓励“一次写出完美 prompt”。

而是:

text
Idea

Implementation / Prompt

Experimental Result

Error Analysis

Refine
 └──────────→ repeat

具体步骤:

  1. Be clear and specific.
  2. Try something.
  3. Analyze why result is undesirable.
  4. Clarify instructions / give more reasoning structure.
  5. Refine with a batch of examples.

这和机器学习开发非常像:

最重要的是:

不要只根据一个成功样例优化 prompt。

课件强调:

refine prompts with a batch of examples.

否则容易:


23. Four Basic Prompting Capabilities ★★★

Pages 32–35:

这是非常适合出 matching / short-answer 的地方。


23.1 Summarizing ★★★

可以:

  • impose word limit
  • focus on specific aspects
  • extract information relevant to audience

核心:


23.2 Inferring ★★★

课件包括:

  • knowledge extraction
  • semantic understanding
  • topic classification
  • sentiment classification
  • etc.

形式:

其中 是没有直接显式写出的 semantic property。

例如:


23.3 Transforming ★★★

输入信息基本保留,但 representation 改变。

例:

或者:

所以:


23.4 Expanding ★★★

例如:

  • email
  • essay
  • customer-service response

与 summarization 相反:


24. 四种能力最容易混淆的地方

Capability核心操作信息长度示例
Summarizing压缩report → summary
Inferring推断隐变量不固定review → sentiment
Transforming改表示形式接近Chinese → English
Expanding补充生成outline → essay

25. Temperature ★★★

Pages 36–37 是本章另一个重要公式。

模型首先产生 logits:

temperature-scaled softmax:


25.1 每个符号

符号含义
token 的 logit
temperature
token 被选择的 probability
遍历所有 vocabulary candidates

课件示例初始概率:

  • pizza:53%
  • sushi:30%
  • tacos:5%
  • others:12%

26. Temperature 为什么能控制随机性? ★★★

考虑两个 token:

它们经过 softmax 后概率比:

这个公式非常有解释力。


所以:

高 logit token 会变得更加 dominant。

因此 distribution 更尖锐。

极端情况下:

趋近于选择 argmax。

于是:

  • more reliable
  • predictable
  • less variable

不同 token 的概率差距被压缩。

distribution 更平。

因此:

  • more exploration
  • more randomness
  • more diverse output

总结:

这是期末极其适合考“解释为什么”的公式。


27. Preprocessing Unstructured Data for LLM Applications

这一部分的核心问题发生了变化:

模型会处理 text 了,但现实世界里的 documents 并不是一整段干净 text。

现实包括:

  • PDF
  • HTML
  • PPT
  • JSON
  • CSV
  • tables
  • images
  • sections
  • titles
  • headers/footers

所以需要:


28. Preprocessing Outputs ★★★

Page 40 定义三类结果。

28.1 Document Content

文本内容。

主要用于:

  • keyword search
  • similarity search

28.2 Document Elements

document 的基本 semantic building blocks:

  • Title
  • Narrative Text
  • List Item
  • Table
  • Image

非常重要:

不能只把文档理解成一个 long string。

更好的 representation:

其中:


28.3 Element Metadata

附加信息:

  • filename
  • filetype
  • page number
  • section

即:

其中:

  • :content
  • :metadata

metadata 后面会帮助:

  • retrieval
  • filtering
  • provenance
  • chunking

29. Why Is Data Preprocessing Hard? ★★★

Page 41 给四个原因。

29.1 Content Cues

不同 document format 通过不同 signal 表达 structure。

例如:

HTML:

html
<h1>Title</h1>

Markdown:

markdown
# Title

PDF 可能依靠:

  • font size
  • position
  • visual hierarchy

因此:


29.2 Standardization Need

如果不标准化:

text
HTML pipeline
PDF pipeline
PPT pipeline
DOCX pipeline
...

downstream 每个模块都必须理解所有 format。

复杂度迅速增加。

标准化后:

text
HTML ─┐
PDF  ─┤
PPT  ─┼→ Common Elements → downstream
JSON ─┤
CSV  ─┘

29.3 Extraction Variability

不同 document type 需要不同 extraction approach:

  • forms
  • journal articles
  • websites
  • slides

不能只靠一种 parser。


29.4 Metadata Insight

有些 metadata 并不是显式字符串,而要理解 structure 才能得到。

例如:

这一段属于 Method section。

需要知道:

  • section hierarchy
  • title relation
  • layout

30. Normalizing the Content ★★★

Page 42:

第一步:

要求 common format 能够识别:

  • titles
  • narrative text
  • other elements

目标:

让来源不同的文档变得 structurally comparable。


31. 为什么 Normalize 很重要? ★★★

Page 43 给出多个 benefit。

31.1 Format-independent Processing

无论:

  • HTML
  • PDF
  • PPT

转换后可以走同一个 pipeline。


31.2 Filtering

可过滤:

  • headers
  • footers
  • unwanted elements

31.3 Chunking

可以按照 document elements / sections chunk。


31.4 Reduce Processing Cost ★★★

课件特别强调:

initial document preprocessing is the most expensive part.

于是:

如果每实验一种 chunking strategy 都重新 parse PDF:

如果先 normalized + serialized:

由于:

后者便宜很多。

这是非常典型的 engineering logic。


32. Serialization ★★★

Page 44:

Normalization 后还应该 serialization。

目的:

preprocessing results 可以重复使用。

课件推荐 JSON,理由:

  1. structure common and well understood
  2. standard HTTP response
  3. multi-language support
  4. can convert to JSONL for streaming

所以完整 pipeline:


33. HTML Example ★★☆

Page 45:

Medium Blog HTML:

典型 element 可能包括:

text
type: Title
text: ...
metadata:
    page_number
    filename
    filetype

重点不是 Medium,而是:


34. Metadata ★★★

Page 46。

定义:

Metadata provides additional information about content extracted from source documents.

可分成两类。

34.1 Source Identification Metadata

描述 source 本身:

  • URL
  • filename
  • filetype

34.2 Structural Metadata

来自 document structure:

  • element type
  • hierarchy
  • section
  • page

因此:

metadata 不只是“文件名”。


35. Chunking ★★★

Page 47 是 preprocessing 部分最重要页面之一。

为什么需要?

Vector databases need documents split into chunks for retrieval and prompt generation.

即:

随后:


36. Naive Chunking:Even-size Chunks ★★★

最简单:

例如:

text
tokens 1–500
tokens 501–1000
tokens 1001–1500

优点:

  • simple
  • predictable size

问题:

semantically related content may be split across chunks.

例如:

text
Chunk 1:
Definition of clustering...

Chunk 2:
...the remaining part of the same definition.

所以:


37. Better Chunking:Atomic Elements ★★★

先识别:

  • title
  • paragraph
  • list
  • table
  • section

再组合 element。

例如:

作为一个 chunk。

优点:

Page 47 示例:

combine content under the same section header into the same chunk.


38. Chunking 演进逻辑 ★★★

text
Raw character/token splitting

        │ Problem:
        │ semantic units 被切断

Atomic-element chunking

        │ 利用 document structure

More coherent chunks


Better retrieval context

这一段跟 RAG 高度相关。


39. PowerPoint Example ★★☆

Page 48:

PPT 被 partition 成:

  • Title
  • ListItem
  • ListItem
  • ...

并统一表示。

所以同样:

这说明 normalization 并不只针对 HTML/PDF。


40. Build LLM-Assisted Data Preprocessors ★★★

Page 49 给出重要 architecture:

text
HTML ─┐
PPT  ─┼→ normalized contents
PDF  ─┘

       Vector Database

           Query


       retrieve Context


Prompt = Context + Query


            LLM


       LLM Response

更数学化:

给 query

构造:

LLM:

这里解决了什么问题?

单独 LLM:

不知道你的 private documents。

加入 vector database:

因此外部 data source 被纳入生成。


41. LLM-Enhanced Data Mining Tasks

课件接下来正式回答:

LLM 怎么参与经典 Data Mining?

四个传统任务:

  1. Pattern Mining
  2. Classification
  3. Clustering
  4. Outlier Detection

注意这四个刚好对应本课程前面的传统 Data Mining 内容。

非常容易出综合题:

Compare traditional algorithm and LLM-enhanced approach.


42. Pattern Mining with LLM ★★★

参考:

Weiss, 2024, An Exploration of Pattern Mining with ChatGPT

目标:

从已知 examples 中提炼 reusable patterns。

课件给出了 eight-step collaborative process。


43. Eight-Step Pattern Mining Process ★★★

顺序建议直接背下来。

Step 1 — Identify Initial Examples

建立 concrete basis。

例如在线学习:

  • weekly quizzes → students stay active
  • short videos → more watching
  • discussion questions → more interaction
  • badges → harder work

Why?

LLM 不应该一开始纯空想 pattern,而是从 known cases 开始。


Step 2 — Extract Common Solutions

识别重复 solution:

  • break long content
  • add interaction
  • rewards / feedback
  • social discussion

即:


Step 3 — Define Problems

把 solution 和其解决的问题关联:

例如:


Step 4 — Distill Problem-Solution Pairs into Patterns

从 instance 变成 general pattern。

例如:

Short Content Units

Problem:

Long videos make students lose focus.

Solution:

Use short focused videos.

形成:


Step 5 — Identify Affordances

Affordance:

当前系统具有什么 capability,使 pattern 可以被实现?

例如:

  • video hosting
  • quiz tools
  • progress bar
  • forum/chat

注意 pattern 不能脱离 system capability。


Step 6 — Relate Patterns to Affordances

例如:

这一步把 conceptual solution 与 executable capability 连接。


Step 7 — Refine Iteratively

加入:

  • constraints
  • limits
  • practical tips
  • remove overlap
  • relationship/dependencies

例如:

quizzes 太多会造成 fatigue。

因此 pattern 不是无条件有效。


Step 8 — Consolidate Patterns

形成 pattern language / guidebook。

每个 pattern 包括:

  • name
  • problem
  • solution
  • why it works
  • when it works
  • examples

44. Pattern Mining 的演进本质 ★★★

传统 mining 更偏:

而这里 LLM 被用于:

LLM 的优势来自:

  • semantic understanding
  • summarization
  • analogy
  • abstraction

但它依然依赖 human + data source collaborative process。


45. LLM Classification ★★★

参考:

Sun et al., Text Classification via Large Language Models

核心方法:

Progressive Reasoning Strategy。


46. Vanilla Zero-shot 的问题

最简单 prompt:

text
Classify sentiment as Positive or Negative.
INPUT: ...

直接:

可能出错,因为模型直接从完整文本跳到 class label。


47. CoT Zero-shot

让模型先 reasoning:

有所改善。

但 reasoning 本身可能:

  • 没有 focus
  • 捕捉错误 evidence
  • 过度解释

48. Progressive Reasoning / CARP ★★★

课件 Page 55:

先让 LLM 找 superficial clues:

  • keywords
  • tone
  • semantic clues
  • etc.

然后再分类。

抽象:

其中:

  • :input text
  • :clues
  • :reasoning
  • :class

而不是直接:

这是一种 task-specific reasoning structure。

Page 56 结论:

proposed method outperforms vanilla zero-shot and CoT zero-shot.


49. 为什么 Progressive Reasoning 会有效? ★★★

它不是单纯让模型“想更多”,而是明确:

解决 vanilla method:

evidence extraction 不明确。

也解决 generic CoT:

reasoning 没有 task-specific structure。

可以记:

text
Vanilla Zero-shot
    ↓ insufficient reasoning
CoT
    ↓ reasoning exists but may be unfocused
Progressive Reasoning
    ↓ explicit clues + reasoning
Better classification

50. LLM for Clustering ★★★

参考:

Viswanathan et al., 2024, Large Language Models Enable Few-shot Clustering

这里非常重要,因为:

LLM 并没有直接替代 K-Means。

流程:


51. Pairwise Constraints ★★★

对于两个 samples:

LLM 判断两类 relationship:

表示:

应该属于同一 cluster。

表示:

不应该属于同一 cluster。

课件虽然没有展开 Must-Link / Cannot-Link 名称,但“pairwise constraints”应这样理解。


52. 为什么要这样做? ★★★

传统 K-Means 只依赖 geometric structure:

它不知道:

从 semantic/domain knowledge 来看,哪些 points 应该在一起。

LLM 可以产生 pseudo-oracle constraints。

于是:

text
Traditional K-Means
distance only

      │ Problem:
      │ semantics unavailable

LLM generates semantic constraints


Pairwise-constrained K-Means

核心价值:


53. 为什么叫 Pseudo-oracle? ★★★

真正 oracle:

但人工昂贵。

LLM:

它近似 oracle,因此叫:

pseudo-oracle.

这也是一个很典型的“LLM 不替代算法,而替代 expensive supervision signal”的案例。


54. LLM-Assisted Outlier Detection ★★★

Page 58。

两条路线。

54.1 Zero-shot Detection

利用:

LLM's pretrained knowledge

直接:

不进行:


54.2 Data Augmentation ★★★

LLM 不一定亲自检测 anomaly,而是生成:

  1. synthetic data
  2. category descriptions

然后提高 anomaly detection model。

流程:

或:


55. Outlier Detection 的方法演进

text
Traditional AD
only limited observed data

       │ Problem:
       │ rare anomalies → little training evidence

LLM pretrained knowledge
       ├─ directly zero-shot detect
       └─ generate extra information
              ├─ synthetic examples
              └─ category descriptions

这里最关键的问题就是:

anomaly 本来就稀有,所以 data scarcity 尤其严重。

LLM 提供 extra prior information。


56. 四种 Data Mining Task 中 LLM 的角色对比 ★★★

TaskLLM 扮演什么角色是否替代传统算法
Pattern Miningsemantic pattern abstraction较直接参与
Classificationreasoning / evidence extraction可直接分类
Clusteringgenerate pairwise constraints否,仍用 K-Means
Outlier Detectionzero-shot detector / data augmenter两者都有

这是很值得背的一张表。


57. LLM for Tabular Data Analysis ★★★

Page 59 分三类:

  1. LLM for Direct Tabular Data Prediction
  2. LLM uses tools/knowledge for Tabular Data Prediction
  3. LLM for Table Operations

课件分别主要通过:

  • LIFT
  • CAAFE
  • TableLLM

讲解。

这三种方法非常容易被混为一谈。


58. LIFT — Language-Interfaced Fine-Tuning ★★★

参考:

Dinh et al., NeurIPS 2022。

核心命题:

Transform any supervised learning task into a text-to-text format and directly fine-tune LLMs.

这是 Unified Language Modeling 思想向 non-language task 的进一步推广。


59. LIFT Step 1 — Serialized Input ★★★

原始输入可能是:

  • tabular data
  • image features
  • molecular structures

传统输入:

LIFT:

例如 tabular row:

AgeSalaryJob
3560000Engineer

serialization:

The person is 35 years old, earns 60000, and works as an engineer.

于是:


60. LIFT Step 2 — Unified Training Objective ★★★

将 supervised task:

变成:

模型直接优化文本 answer。

一般语言模型训练形式:

等价地最小化 negative log-likelihood:

课件没有展开这个显式公式,但“maximize consistency between LLM-generated text and ground-truth answers”就是这个标准 text-generation objective 的含义。


61. 为什么 LIFT 是一个重要的 conceptual leap? ★★★

过去:

text
Tabular classification → tabular model
Image classification   → vision model
Molecule prediction    → graph model

LIFT:

text
Tabular ─┐
Image    ─┼→ serialize to text → LLM → textual answer
Molecule ─┘

即:

Problem it solves

LLM 本身接受 language interface:

但 table 不是 language。

Fix

serialization:


62. LIFT 的潜在瓶颈 ★★☆

课件主要讲方法,没有专门批判,但从结构上应该理解:

serialization 必然意味着:

所以 scalability 和结构保持成为潜在问题。

这也直接解释后面为什么 TableLLM 不简单把成千上万行 spreadsheet 全部塞进 prompt。


63. CAAFE — LLM for Automated Feature Engineering ★★★

参考:

Hollmann, Müller & Hutter, NeurIPS 2023。

CAAFE:

Context-Aware Automated Feature Engineering.

关键区别:

而是:


64. CAAFE Workflow ★★★

Step 1 — Prompt Construction

提供:

  • dataset contextual description
  • feature names
  • data types
  • small set of samples

即:

为什么需要这些?

因为 feature engineering 依赖 domain semantics。

例如:

仅知道数值 distribution 未必容易发现;

知道 feature name 后,LLM 可能利用 pretrained knowledge:


65. Step 2 — LLM-Generated Code ★★★

LLM 输出:

  • Python code
  • natural-language explanation

即:

其中 是 candidate feature transformation。


66. Step 3 — Code Execution and Evaluation ★★★

不能因为 LLM 说:

这个 feature 很有帮助。

就相信它。

必须:

并在 validation set 上运行 predictive model:

比较:


67. Step 4 — Iterative Optimization ★★★

如果:

保留 feature。

否则丢弃。

然后继续:

形成:

text
LLM proposes

Code executes

Validation evaluates

Improved?
 ├─ Yes → keep
 └─ No  → reject

repeat

这其实和 Page 31 iterative prompting 非常像。


68. CAAFE 为什么比传统 AutoFE 更强? ★★★

传统自动 feature engineering:

context-agnostic。

通常通过:

  • arithmetic combinations
  • predefined transformations
  • search

寻找 feature。

CAAFE:

产生 context-aware feature。

因此:


69. CAAFE Results ★★☆

Page 62:

课件结论:

Across downstream classifiers, CAAFE-generated features consistently improve performance.

并超过 traditional context-agnostic methods:

  • DFS
  • AutoFeat

实验包含:

  • Logistic Regression
  • Random Forest
  • AutoSklearn2
  • AutoGluon
  • TabPFN

非常重要的结论:

LLM 提供的价值可以通过传统 predictor 的 downstream performance 来验证。

这比“LLM 自己说自己设计的 feature 很好”可靠得多。


70. LIFT vs CAAFE ★★★

LIFTCAAFE
核心问题如何让 LLM 做 non-language prediction如何用 LLM domain knowledge 提升传统 ML
LLM 输入serialized datadataset context/schema/sample
LLM 输出prediction textfeature-engineering Python code
是否 fine-tune LLM主要作为生成器
是否保留传统 predictor不一定
核心思想language interfaceknowledge-guided FE

一句话:


71. TableLLM ★★★

参考:

Zhang et al., ACL Findings 2024。

这是本章最后一个很重要的架构。

核心洞察:

并不是所有 tables 都应该用同一种 reasoning mode。

课件分成两个 scenario。


72. Scenario 1 — Document-embedded Tables ★★★

特点:

  • 表格嵌在 document
  • relatively few rows
  • usually tens or fewer

例如:

text
paper
report
webpage
PDF table

任务偏:

  • QA
  • understanding
  • reasoning

TableLLM 采取:

输入:

输出:

也就是:


73. Scenario 2 — Spreadsheet Tables ★★★

特点:

  • hundreds to thousands of rows
  • spreadsheet environment
  • operations

任务:

  • insertion
  • deletion
  • merge
  • update
  • query
  • chart generation

如果直接让 LLM:

在脑子里读 10,000 行然后修改。

非常低效也不可靠。

所以 TableLLM 采用:

即:


74. 为什么两种 Scenario 要分开? ★★★

这是 TableLLM 最值得考的 Why。

小表:

足够小,可以装进 context。

因此:

可行。

大表:

直接 text reasoning:

  • token cost ↑
  • arithmetic error ↑
  • manipulation reliability ↓

所以:

程序负责 deterministic operation。

最核心思想:


75. TableLLM Data Construction — Text Reasoning ★★★

Page 64。

数据源:

  • WikiTQ
  • FeTaQA
  • TAT-QA

原始数据:

很多 answer 太短。

因此用 GLM-4-Plus 把:

扩展成:

目的:

transform concise answers into detailed reasoning processes.

即为模型提供 reasoning supervision。


76. TableLLM Data Construction — Operations ★★★

Page 65:

来源:

  • WikiTQ:5,177 samples
  • TAT-QA:5,000
  • FeTaQA:4,019
  • GitTables:1,300 long-table samples

然后扩展成 10 types of questions。

覆盖:

  • Query
  • Update
  • Merge
  • Chart

这里数量建议记住至少 dataset names 与四大 operation categories。


77. TableLLM Response Construction ★★★

Page 66 分成两条路径。

Text-based Path

模型生成:

个 textual answers。

然后选取:

most consistent with reference answer

的结果作为 final response。


Code-based Path

Pandas 生成:

个 code solutions。

对结果进行 majority vote,并选择与 reference answer consistent 的 output。


为什么这样做?

因为 single generation 有 stochasticity。

如果:

可以利用 self-consistency:

或者通过 reference consistency 进行筛选。

核心目标:


78. TableLLM Training ★★★

Page 67。

78.1 Text-driven Training

Input:

Output:

课件称:

inner-parameter-driven.

即依赖模型内部参数完成 reasoning。


78.2 Code-driven Training

Input:

Output:

不是要求:

而是:

然后:


79. 为什么只给 Table Header + First Few Rows? ★★★

这是非常好的推理题。

因为真正需要 LLM 理解的是:

  • schema
  • column semantics
  • operation intent

而不是把所有 rows 都“记住”。

设表:

如果 很大:

直接 serialization:

tokens/representation cost。

而代码生成只需要:

示例 rows,其中:

然后 Pandas 在外部对全部:

行执行。

这是:


80. TableLLM Results ★★☆

Page 68 给出了完整结果表。

几个重点:

TableLLM (8B)

  • WikiTQ: 89.10
  • TAT-QA: 89.50
  • FeTaQA: 93.36
  • WikiSQL: 89.6
  • Spider: 81.05
  • Our created: 77.83
  • Average accuracy: 86.74
  • Inference times: 1

GPT-4o:

  • Average: 84.79

因此课件中的主要结果:

TableLLM 8B 的 average accuracy 高于表中 GPT-4o。

另外某些 multi-call reasoning 方法:

  • StructGPT: 3 inference times
  • Binder: 50
  • DATER: 100

而:

所以它同时强调:

  • accuracy
  • inference efficiency

81. TableLLM 与普通 LLM 的方法演进 ★★★

text
Generic LLM
serialize table → text reasoning

       │ Works for small tables

       │ Fails/scales poorly for large spreadsheet

Task separation

       ├── Small embedded table
       │     → reading comprehension

       └── Large spreadsheet
             → code generation
             → external execution

这其实是整章最后最成熟的一种 LLM-system 思想:

不让 LLM 做它不擅长的 deterministic bulk computation,而让它负责 semantic reasoning 和 code generation。


82. 三种 Tabular 方法总对比 ★★★

方法核心策略LLM 的角色输出传统工具
LIFTtable → languagepredictoranswer较少
CAAFEdomain context → feature codefeature engineerPython featuresclassifier
TableLLM Textsmall table → reasoningQA/reasonertextual answer无/少
TableLLM Codelarge table → programplanner/code generatorPandas codePandas

方法演进可以理解成:

text
LIFT
让所有数据适应 LLM
table → text

      │ Problem: structured / large data scaling

CAAFE
不必让 LLM 做全部计算
LLM 提供 domain knowledge
traditional ML 做 prediction


TableLLM
进一步区分任务性质
semantic reasoning → LLM
large deterministic execution → code/tool

83. 全章最核心的“Why it fails → How it fixes”

这是我建议你期末重点背的一张逻辑表。

前一阶段Why it fails / limitation下一步怎么修复
Raw LMtask-specific interface 碎片化Unified text-to-text
Small LMcapability / scaling 有限large data + model + compute
LLM direct promptinginstruction ambiguousclear/specific prompt
Instruction only隐式 pattern 难表达few-shot examples
Direct answercomplex reasoning 容易跳步structured reasoning
Internal knowledgehallucinationretrieval + grounded answer
One-shot prompt designresult unstableiterative development
Raw documentsformats heterogeneousnormalization
Plain textdocument structure 丢失atomic elements + metadata
Fixed-size chunkingsemantic content 被切开element/section chunking
LLM pattern mining缺乏 grounded exampleseight-step collaborative mining
Zero-shot classificationevidence 未显式提取progressive reasoning
K-Meansonly geometry, no semanticsLLM pairwise constraints
AD with scarce anomaliesinsufficient rare sampleszero-shot knowledge / augmentation
LLM only accepts texttable is structuredLIFT serialization
Generic AutoFEcontext-agnosticCAAFE domain-aware FE
LLM direct large-table reasoningscale + calculation reliabilityTableLLM code execution

84. 一张图记完整章 ★★★

text
             ┌───────────────────────┐
             │ Language Modeling     │
             │ p(x1,...,xN)          │
             └──────────┬────────────┘

              chain-rule next-token

             ┌───────────────────────┐
             │ Large Language Model  │
             │ data/model/compute ↑  │
             └──────────┬────────────┘

              How do humans control it?

             ┌───────────────────────┐
             │ Prompt Engineering    │
             ├───────────────────────┤
             │ clear instructions    │
             │ delimiters            │
             │ structured output     │
             │ few-shot              │
             │ reasoning structure   │
             │ retrieval grounding   │
             └──────────┬────────────┘

              Data isn't clean text

             ┌───────────────────────┐
             │ Data Preprocessing    │
             ├───────────────────────┤
             │ normalize             │
             │ serialize             │
             │ metadata              │
             │ chunk                 │
             │ vector DB             │
             └──────────┬────────────┘

              Apply to Data Mining

        ┌───────────────┴───────────────┐
        │                               │
 Pattern / Class / Cluster / AD       Tables
        │                               │
        │                    ┌──────────┼──────────┐
        │                    ▼          ▼          ▼
        │                  LIFT       CAAFE    TableLLM
        │                    │          │          │
        │               text iface   features   text/code
        └────────────────────┴──────────┴──────────┘

85. 考前必须会写的三个公式 ★★★

Formula 1 — Autoregressive Language Modeling

必须解释:

joint sequence probability 被 chain rule 分解成逐 token conditional probability。


Formula 2 — Temperature-scaled Softmax

必须解释:

最好进一步会:


Formula 3 — LIFT 的统一语言训练思想

课件没有单独写 loss,但其描述对应:

其中:

  • :serialized non-language input
  • :text-form target
  • :LLM parameters

核心:


86. 名词定义速查表 ★★★

Term一句话定义
Language Model为 token sequence / next token 建模概率的模型
LLM在大量数据上长时间训练、具有大量参数的 language model
Prompt Engineering设计输入 instructions/context 以稳定引导 LLM 完成任务
Few-shot Prompting在 context 中给若干 successful examples 后要求完成新样例
Hallucination生成听起来 plausible 但事实错误的信息
Retrieval从外部 data source 寻找 query-related evidence
Normalization将不同 raw formats 转成统一 document representation
Elementtitle/list/table/image 等 document atomic unit
Metadata描述 source 或 document structure 的附加信息
Chunking将 document 切分成 retrieval units
Vector Database存储/检索 vectorized chunks 的数据库
Pairwise Constraint对两个 samples 是否应该同 cluster 的约束
Pseudo-oracle用 LLM 近似 human oracle 提供 constraints
LIFT把 non-language supervised task 转成 text-to-text fine-tuning
CAAFELLM 根据 dataset context 自动生成 feature-engineering code
TableLLM针对 document tables 和 spreadsheets 分别采用 text reasoning / code execution

87. 最容易出的对比题 ★★★

Zero-shot vs Few-shot

Vanilla Zero-shot vs CoT vs Progressive Reasoning

vs.

vs.

Even-size vs Element-based Chunking

Traditional K-Means vs LLM-enhanced Clustering

LIFT vs CAAFE vs TableLLM


88. 按期末优先级复习

如果时间非常紧,我建议按照以下顺序。

第一优先级 ★★★

  1. Language modeling chain-rule formula
  2. next-token prediction
  3. LLM definition
  4. two prompting principles
  5. four tactics under Principle 1
  6. hallucination + retrieval
  7. four prompting capabilities
  8. temperature formula与 的作用
  9. preprocessing output:content / element / metadata
  10. normalization
  11. metadata
  12. even-size vs atomic-element chunking
  13. vector DB + LLM workflow
  14. 8-step pattern mining
  15. progressive reasoning classification
  16. pairwise constraints clustering
  17. two LLM anomaly-detection approaches
  18. LIFT
  19. CAAFE
  20. TableLLM 两种 scenario
  21. TableLLM text-driven vs code-driven

第二优先级 ★★☆

  • unified language modeling / T0
  • LLM capabilities
  • serialization / JSON
  • iterative prompt development
  • pseudo-oracle
  • CAAFE evaluation loop
  • TableLLM data construction
  • TableLLM results

第三优先级 ★☆☆

  • 各模型发布时间/参数规模
  • ChatGPT / Poe / Kimi / DeepSeek 等产品例子
  • Llemma 数学题的具体数值
  • individual benchmark 的全部小数点结果

89. 最后的整体理解

如果老师出一道:

“How are LLMs changing data mining?”

一个高质量答案不应该只是说:

LLMs can do classification, clustering and anomaly detection.

而应该抓住这章真正展示的三层演进:

第一层,LLM 把许多原来不同的任务统一成了 language interface:

第二层,面对传统 Data Mining,LLM 不一定替代算法,而是注入 semantic knowledge:

例如 clustering 中:

第三层,当任务包含大规模 deterministic computation 时,最合理的系统开始把:

分开。

TableLLM 的 spreadsheet 方法正是:

所以整章最深的一条进化路线其实是:

这比单独记“LLM 可以做哪些任务”重要得多。


高密度复习:LLMs in Data Mining

一条主线

核心不是 LLM 必然替代传统算法,而是让非语言数据、领域知识和工具接入统一的语言接口。

1. LM、LLM 与 temperature

自回归语言模型把整段文本的联合概率拆成 next-token 条件概率:

每一步产生 vocabulary 上的分布;高概率不等于事实正确,因此 hallucination 仍然可能发生。

温度分布典型效果
更尖锐更稳定、少变化;仅在趋近 时趋近 argmax
更平坦更多探索、更多样;不等于更正确

LLM 可粗略理解为:大参数 + 大数据 + 大算力上训练的 LM;这不是把四项做数学相加的严格等式。

2. Prompting:让任务可执行

高频组合:

目标手段
减少歧义clear/specific instruction、delimiter、规定输出格式
告诉模型任务模式few-shot demonstrations
处理复杂任务specify steps、先独立求解再判断
减少无依据回答先 retrieval,再基于 evidence 回答
提高鲁棒性批量例子评估、error analysis、迭代 refinement

安全边界:delimiter 只是提示 instruction/data 的边界,不是独立的 prompt-injection 防护;文档内容应视为不可信输入。还应校验 JSON/schema、限制工具权限,并对检索证据和最终事实做验证。JSON 可以是 object,也可以是 array;具体 schema 必须写清楚。

3. 非结构化数据预处理与 chunking

元素至少保留 ;metadata 包括来源、文件类型、页码、section/hierarchy,可用于过滤、溯源和重建上下文。固定 token 长度简单但可能切断语义;优先按 title/paragraph/list/table/section 等 atomic elements 组合,并把同一 section header 下的内容放在相关 chunk 中。先解析并序列化,之后反复尝试 chunking,可避免每次重新解析原始文件。

4. LLM-assisted 四类 Data Mining

任务LLM 做什么传统算法是否保留
Pattern mining从 examples 抽象可复用的 problem–solution patterns;流程:examples → common solutions → problems → patterns → affordances → relate → refine → consolidate需要人和数据源协作验证
Classificationvanilla zero-shot 直接给标签;CoT 增加 reasoning;Progressive/CARP 先抽 clues,再 reasoning,最后分类可直接输出类别,但结果非普遍保证
Clustering生成 pairwise Must-Link/Cannot-Link 约束(pseudo-oracle)仍由 constrained K-Means 聚类
Outlier detectionzero-shot 使用预训练知识,或生成 synthetic samples/category descriptions 扩充信息检测器可继续训练,合成数据需验证

5. LIFT、CAAFE、TableLLM 一眼区分

方法主要问题LLM 角色关键机制/输出
LIFT直接做非语言/表格监督预测predictor把 tabular/image features/molecule 等序列化成文本,统一成 QA 或 fill-in-the-blank,并 fine-tune LLM
CAAFE用领域知识做自动特征工程feature generator输入 schema/context/sample → 生成特征代码 → 执行、评估、迭代保留;传统 classifier 仍负责预测
TableLLM读表、问答和表格操作reasoner + code generator小型 document-embedded table 用 textual reasoning;大型 spreadsheet 生成 Pandas 代码,由外部工具执行

记忆:LIFT 语言化任务,CAAFE 生成特征,TableLLM 分离推理与执行。

6. 课件勘误与结果解读

  • PDF 第 14 页把 PaLM 2 的 Access 写成 Open-Source,这是课件疑似错误;PaLM 2 未公开模型权重,不应把该项当事实背诵。
  • PDF 第 14 页把 Llama 3.1 日期写成 June 23, 2024,日期很可能错误(常见发布日为 July 23, 2024);本笔记未抄录该日期。
  • PDF 第 24 页的 “Avoiding Prompt Injections” 不应理解为 delimiter 能提供安全保证。
  • PDF 第 68 页 TableLLM 的 与 GPT-4o 的 是该表六列、该实验设置下的平均值(),不是对所有数据集和模型都成立的普遍定理。

Static academic notes built with VitePress and KaTeX.