· Xiaojing Yang · NLP and LLMs · 3 min read
ENPrompting and Instruction Following
Prompting 既是任务说明,也是接口设计和评估风险。
核心观点
Prompt 不只是输入文本,而是语言模型的临时任务接口。
1. Prompting 做了什么
Prompting 在不改变模型权重的情况下说明任务、上下文、约束、风格和输出格式。Instruction following 取决于预训练、instruction tuning、alignment 和 decoding。
要做什么
证据或示例
格式和规则
生成输出
检查有用性和失败
2. Prompt 类型
| 类型 | 用途 |
|---|---|
| zero-shot | 直接指令 |
| few-shot | 在上下文中给例子 |
| chain-of-thought style | 在合适时引出推理痕迹 |
| structured output | JSON、表格、标签 |
| retrieval-augmented prompt | 用外部证据 grounded answer |
3. Hugging Face 实践
from transformers import pipeline
generator = pipeline("text-generation", model="Qwen/Qwen2.5-0.5B-Instruct")
out = generator("Explain cross-validation in one paragraph.", max_new_tokens=80)4. 我的研究连接
Prompting 对 LLM evaluation 很重要,因为很小的措辞变化都可能改变表现。对多语任务来说,英文 prompt 不一定公平迁移到其他语言或领域。
有用习惯
把 prompts 当成实验变量。
评估风险
不要在最终测试集上调 prompt。
总结
Prompting 强大,因为它轻量;也正因为轻量,它很容易悄悄过拟合。
面试回答模板
如果面试问到这个概念,我通常会这样回答:
- 用一句话定义;
- 解释数据如何流动;
- 指出主要失败模式;
- 连接到 evaluation、multilinguality 或 fine-tuning。
参考资料
- Hugging Face Course
- Hugging Face Transformers documentation
- Hugging Face tokenizer summary
- Hugging Face fine-tuning guide
- Hugging Face PEFT
- The Illustrated Transformer
- Speech and Language Processing, Jurafsky & Martin
- Stanford CS224N readings
- Attention Is All You Need
- COMET: A Neural Framework for MT Evaluation