Essential for Large Model Interviews & Analysis: From Principles to Interview Questions
7/13/2026, 6:58:35 PM · updated 7/13/2026, 7:06:21 PM
This article systematically outlines the core architecture of large models, the three major training stages, RAG and Agent application paradigms, and high-quality data construction methods, and provides analyses of classic real interview questions and analytical thinking frameworks tailored for non-algorithm positions.
Essential for LLM Interviews/Analysis: From Principles to Interview Questions, This One Article Is Enough
Original by Classmate Zhao Daluo Zhao Xiaoluoluo
April 26, 2026 20:35 2,693 people
Hello everyone, I'm Xiaoluo. Recently, the concept of large language models (such as Doubao and DeepSeek) has been extremely hot. Do you often use AI LLMs for Q&A but feel completely in the dark about the underlying principles? Do you also frequently hear terms like "Transformer", "fine-tuning", "RAG", and "Agent"?
During my learning process, I systematically organized the core principles of LLMs, their training workflows, RAG/Agent applications, data construction methods, and common interview questions.
This article is primarily targeted at non-algorithmic roles such as LLM analysts, product managers, and operations, helping everyone build a complete understanding from theory to practice. Whether you are expanding your knowledge in emerging industries or preparing for job interviews, I believe you will find it rewarding. It is recommended to bookmark this for quick reference.
Part 1: Core Theoretical Concepts
1. Basic Architecture and Working Principles of LLMs
Large Language Models (LLMs) are usually based on the Transformer architecture, the core of which is the Self-Attention mechanism. In simple terms: when you read the sentence "He walked his dog in the park yesterday," you subconsciously connect "He" with the person mentioned earlier. This is exactly what self-attention does—**when understanding a word, the model **parallelly "pays attention" to all other words in the sentence and calculates the relevance of each word to the current word. This mechanism enables the model to efficiently process long texts and capture global dependencies.
Simplified Workflow:
-
Input and Embedding: Convert each word (token) into a vector (word embedding) while incorporating positional information (positional encoding).
-
Self-Attention Calculation: Generate three vectors for each word: Q (Query), K (Key), and V (Value). Use the similarity between Q and all Ks to determine "whom to look at," and then use these weights to compute a weighted sum of Vs, obtaining a new vector that integrates the context.
-
Feed-Forward Network + Residual Connections: Undergo non-linear transformation, and use "residual connections + layer normalization" to prevent gradient vanishing, allowing ultra-deep networks to train stably.
-
Training Objective: Conduct unsupervised pre-training on massive texts, where the core task is "predicting the next word". Through repeated guessing, the model learns grammar, semantics, factual knowledge, and even reasoning capabilities.
- The Three Core Stages of Training and Alignment
This is the process of nurturing a "knowledgeable student" into a "professional and reliable assistant".
-
Pre-training
-
Objective: Enable the model to learn statistical patterns of language and world knowledge, building a broad knowledge foundation.
-
Method: Train the model on massive unannotated texts to complete the "next token prediction" task.
-
Data Impact: This is the cornerstone of model capability. The scale, quality, diversity, and freshness of the data directly determine the breadth and depth of the model's knowledge base, language modeling capability, and inherent reasoning ability. As the saying goes, "Garbage in, Garbage out"—data deficiencies at this stage are fundamental.
-
Example: If the pre-training corpus lacks high-quality financial texts, the model is highly likely to make factual errors or fail to understand professional terminology when answering questions about "option pricing".
-
Supervised Fine-Tuning (SFT)
-
Objective: Teach the pre-trained model how to follow human instructions and interact in specific formats (such as dialogue). This is the first step of "alignment".
-
Method: Use high-quality paired
(instruction, expected output)data to conduct supervised training on the pre-trained model. -
Data Impact: Determines the model's instruction-following capability, response style and format, and expertise in specific domains. The quality of SFT data represents the ceiling of the model's conversation capability.
-
Example: By feeding the model a large amount of high-quality data such as
(Instruction: "Please summarize the following article...", Expected Output: "This article mainly describes..."), the model finally learns the "summarization" skill and outputs in the required format. -
Reinforcement Learning from Human Feedback (RLHF)
-
Objective: Make the model's responses, on top of being "correct," align better with human values and preferences—meaning safer, more helpful, and more human-like.
-
Collecting Human Feedback: Given an instruction, annotators rank the quality of multiple responses generated by the model (e.g., A > D > B > C).
-
Training a Reward Model (RM): Use thousands of such ranking data to train a reward model capable of judging the quality of responses. This RM learns to award high scores to responses that align with human preferences.
-
Reinforcement Learning Optimization: Use RL algorithms such as PPO, with the SFT model as the initial policy and the RM as the reward signal, to optimize model parameters, encouraging it to generate responses that gain high RM scores. Meanwhile, a KL-divergence penalty prevents the model from changing beyond recognition and drifting too far from the good foundation learned during the SFT stage.
-
Data Impact: Finely carves the model's values, safety boundaries, and aesthetic preferences. It can correct potential biases present in the SFT stage, or enable the model to make a better trade-off between "staying faithful to knowledge" and "satisfying user needs".
-
Example: Before RLHF, a model might directly generate a complex legal document template. After RLHF, the model will first explain relevant legal key points, then strongly advise the user to consult a professional lawyer, and attach a disclaimer. This more "responsible" behavior is precisely taught to the model through preference data.
Key Takeaway: Pre-training determines the upper limit of the model's "IQ", SFT teaches the model "dialogue formats" and "basic skills", and RLHF shapes the model's "values" and "EQ".
3. Two Major Application Paradigms: RAG vs. Agent
RAG (Retrieval-Augmented Generation)
-
Core Idea: Before the model generates an answer, it first retrieves relevant information from an external knowledge base, using it as context to enrich the user's query before handing it to the model to generate the final answer.
-
Core Value: Decouples "knowledge memorization" from "generative reasoning". The model does not need to memorize all knowledge by heart; the knowledge base can be updated independently at any time, effectively mitigating knowledge obsolescence and model hallucination.
-
Key Data Points: The knowledge base must be authoritative and clean; retrieval quality depends on the embedding model and document chunking strategies; both answer correctness and retrieval relevance need to be evaluated simultaneously.
AI Agent
-
Core Idea: The LLM acts as the "brain," capable of understanding complex tasks, planning execution steps, calling external tools (calculators, APIs, search engines, etc.), and executing actions.
-
Example (Legal Consulting Agent): Understand user's labor dispute → Plan required information → Call legal knowledge base RAG to retrieve clauses of the "Labor Contract Law" → Call case API to search for similar judgments → Call compensation calculator → Synthesize information to generate "Legal Consultation Summary".
One-sentence Distinction:
-
RAG: Equipping the model with a "database that can be consulted at any time."
-
Agent: Making the model a "brain capable of getting work done."
4. High-Quality Data Construction (Advanced)
What is "High-Quality Data"?
Universal Core Definition: High information density, low noise, and strong target alignment.
Specifically, it varies by stage:
Image
Together, these methods constitute an intelligent engineering system of "AI-enhanced, human-machine collaboration":
Image
Synthetic Data: Value and Risk Control
Value: Fills data gaps in privacy-sensitive areas (such as healthcare and finance) and long-tail scenarios, precisely customizes specific capabilities (such as multi-step reasoning), and significantly reduces annotation costs.
Risks and Controls:
-
Model Collapse: Over-reliance on synthetic data leads to output degradation.
→ Control: Proportion of synthetic data ≤30%; mix with real-world data; dynamically filter low-quality samples. -
Distribution Shift: Discrepancies between synthetic data and real business distributions.
→ Control: Set rule constraints based on real data characteristics; perform regular distribution validation (such as KL divergence). -
Compliance Risk: Latent sensitive information. Control desensitization before synthesis, and double-check with entity recognition after synthesis.
Balancing Data Quality and Efficiency (Economic Perspective + ML Perspective)
-
Economic Perspective: Optimal when Marginal Revenue (MR) = Marginal Cost (MC). The cost of increasing data accuracy from 85% to 90% might double, and from 95% to 98% it might increase fivefold.
-
Balancing Strategy: Phased investment (rapid validation with low-cost data in early stages, investing in high-quality data during productization); allocate more resources to critical categories (such as rare disease diagnosis).
-
Machine Learning Perspective: Under a fixed budget, allocate resources between data volume (N) and data quality (Q) to minimize generalization error.
-
Frontier Practices: Curriculum learning (from simple, clean data to complex, noisy data), active learning (prioritizing annotation of data the model is "most uncertain" about), noise-aware training, etc.
-
Integrated Dynamic Framework: Exploration Phase (Economics First) → Expansion Phase (Engineering Efficiency First) → Maturity Phase (ML First). Ultimately, balance is not a static compromise, but a dynamic optimization based on clear objectives and real-time metrics.
5. PETagging (Prompt Engineering for Annotation)
The exact meaning of PE Tagging (Prompt Engineering for Annotation) is: a systematic engineering workflow whose core is to leverage and optimize prompt engineering to complete data annotation tasks efficiently and with high quality. It involves two dimensions:
-
Dimension 1: Tagging conducted to "optimize prompts" (the target of tagging is the "prompts")
-
Purpose: Not to directly produce business data, but to find the optimal prompt for a certain task. This is a research activity of "prompt engineering" itself.
-
Process: Design multiple different prompt variants for the same task → Let the model generate different results → Human or AI judges grade the quality of these results (this is "tagging") → Analyze which prompt gets the highest score, thereby solidifying the best prompt template.
-
Dimension 2: Using the "optimized prompt" to tag massive tasks (the target of tagging is the "business data")
-
Purpose: Applying PE capabilities to actual production to generate training or evaluation data in batches.
-
Process: For a certain annotation task (e.g., "judging whether a response contains ads"), we have already found a reliable prompt through the first dimension of research → Use this designed prompt to instruct the LLM to automatically classify or grade tens of thousands of data points.
To summarize the relationship between the two:
-
The First Dimension (Research-oriented) is the cause, with the goal of finding a highly effective "instruction" (Prompt).
-
The Second Dimension (Production-oriented) is the effect, leveraging this effective "instruction" to complete annotation work at scale.
Example: Optimizing Q&A Prompts for an Internal Customer Service Assistant
-
Objective: Improve the accuracy and completeness of the model in extracting answers from the knowledge base.
-
Tagging Workflow:
-
Design Variants: For the "query product return policy" task, design 20 prompt variants. Variables include: whether to require quoting the original text, whether to first understand the user scenario, response format, etc.
-
Batch Testing: Use 100 historical real user queries to ask questions with each of the 20 prompt variants, obtaining 2,000 responses.
-
AI Tagging: Use GPT-4 as a judge to grade each response on "accuracy" (whether it aligns with official policy) and "completeness" (whether it covers key clauses).
-
Analysis Finding: Prompts with the structure "Please first judge user intent, then strictly quote relevant paragraphs from the original knowledge base, and finally summarize" scored significantly higher on average than other variants.
-
Outcome: Solidified this prompt template into the customer service system, raising answer accuracy from 75% to 92%.
Part 2: Interview Questions and Reference Answers (Selected)
The following questions are suitable for interview preparation for roles like LLM analysts, product, and operations.
1. Basic Concepts
Q1: What are the three stages of LLM training? What are the key points for capacity building in each stage?
Reference Answer:
The training of LLMs is divided into three core stages, with significant differences in objectives, data characteristics, and key points for capability improvement:
- Pre-training Stage
-
Core Characteristics: The goal is for the model to learn general language rules and massive knowledge. The data consists of unannotated general/broad-domain texts (such as web pages, books, papers), with a data scale reaching the trillion-token level.
-
Key Points for Improvement: First, ensure the domain breadth and balanced distribution of data to avoid knowledge blind spots; second, optimize the tokenization efficiency and semantic coverage of the tokenizer; third, enhance the model's fitting capability for general knowledge through large-batch training and mixed-precision optimization, with core evaluation metrics being perplexity (PPL) and downstream task zero-shot/few-shot accuracy.
- Instruction Fine-Tuning Stage
-
Core Characteristics: The goal is to make the model understand human instruction intent and generate responses matching the format. The data consists of labeled instruction-response pairs/multi-turn dialogues, with a data scale of millions to tens of millions.
-
Key Points for Improvement: First, data must closely match the format of real user instructions (e.g., containing multi-turn follow-ups, tool calling needs); second, unify the instruction format (e.g.,
{"instruction":"xxx", "input":"xxx", "output":"xxx"}), reducing the learning cost of formats for the model; third, train hierarchically by capability dimensions (reasoning, creation, summarization), with core evaluation metrics being instruction-following rate and response relevance.
- RLHF (Reinforcement Learning from Human Feedback) Stage
-
Core Characteristics: The goal is to make the model output high-quality responses that align with human preferences. The data consists of human-annotated response quality rankings/reward scores, divided into two sub-stages: reward model training and reinforcement learning.
-
Key Points for Improvement: First, annotated data must cover diverse preference dimensions (such as safety, helpfulness, fluency); second, the reward model must avoid overfitting the annotated data to prevent the model from "pandering" to annotation criteria and drifting away from real user needs; third, balance model capability and preference alignment through algorithms like PPO, with core evaluation metrics being human preference scores and safety risk trigger rates.
Q2: Does RLHF make it easier to "boost scores" for models?
Reference Answer:
Not necessarily. It is necessary to distinguish between capability-based evaluations (such as MMLU, GSM8K, etc.) and alignment-based evaluations (such as MT-Bench, safety, etc.). For capability-based evaluations: RLHF typically does not boost scores significantly, and sometimes even slightly lowers them (since the optimization goal is "human preference", which may conflict with standard answers). For alignment-based evaluations: RLHF almost always brings a huge improvement.
Conclusion: The primary goal of RLHF is alignment, not objective capability enhancement. One cannot simply say it is "easier to boost scores."
2. Data Analysis and Attribution
Q3: The model frequently makes factual errors when answering questions about new energy vehicles. How do we analyze and optimize this from a data perspective?
Reference Answer:
Follow the four-step methodology of "Locate-Trace-Hypothesize-Verify".
-
Quantify the error rate and classify error types (policy timeliness, regional applicability, monetary errors, etc.).
-
Trace back to pre-training data (whether it contains the latest authoritative policy documents) and SFT data (whether there are enough high-quality policy Q&A pairs).
-
Formulate hypotheses: Outdated knowledge → Update pre-training corpora or introduce RAG; insufficient instruction-following capability → Construct high-quality SFT Q&A pairs.
-
Design a dedicated evaluation set and compare the accuracy before and after optimization.
Q4: Why does the model score high on Benchmarks but offer a poor user experience?
Reference Answer:
Adopt the three-step methodology of "Metric Deconstruction → Data Traceability → Scenario Matching".
-
Metric Deconstruction: Benchmarks often focus on general reasoning, whereas the application side might be a vertical domain (such as healthcare), leading to a mismatch.
-
Data Traceability: If performance in a vertical domain is poor, check the proportion of domain-specific data in the pre-training stage and the number of professional samples in the SFT stage. If the tone/style doesn't match, check the wording templates of the SFT data.
-
Targeted Optimization: Supplement high-quality annotated data in the vertical domain, build business-specific evaluation sets, and perform joint evaluations combining Benchmarks and business assessments.
Q5: How to handle the contradictory phenomenon of "increasing session length but stagnant or declining user satisfaction"?
Reference Answer:
Dimensional Drill-down + Deep Case Analysis.
-
Segment by users (new users vs. old users), session types (task-oriented vs. chitchat), and topics.
-
Sample and perform manual analysis to attribute causes: Does model hallucination require continuous correction? Did comprehension bias lead to repetitions? Is the generated content too verbose and not concise enough?
-
If most cases fall under verbosity or comprehension bias, the problem may lie in the conciseness and instruction-following capability of the SFT data; optimizing the corresponding data is recommended.
Q6: Currently, Doubao's COT (Chain of Thought) is relatively long. If we want to keep reasoning performance unchanged but reduce COT length, from what angles can we approach this?
Reference Answer:
Not necessarily. It is necessary to distinguish between capability-based evaluations (MMLU, GSM8K, etc.) and alignment-based evaluations (MT-Bench, safety, etc.). Capability-based evaluations: RLHF typically does not boost scores significantly, and sometimes even slightly lowers them (because optimizing COT (Chain of Thought) is a technique that guides large language models to perform complex reasoning. Its core is to provide a small number of step-by-step reasoning examples in the input (or trigger them through instructions), thereby inspiring the model to mimic this "question - step-by-step reasoning - final answer" output mode. It decomposes a complex problem requiring multi-step calculation into a series of intermediate steps, effectively improving the model's performance on tasks like mathematics, logic, and common-sense reasoning. How to reduce COT length while maintaining performance? This is a classic "reasoning efficiency" optimization problem. You can start from the following angles:
-
Data and Training Level:
-
Extract high-quality, concise COT demonstrations: Analyze existing long COT data and identify which steps are redundant, repetitive, or overly explanatory. Ask experts or use self-distillation techniques to generate more refined COT data with more reasonable logical steps but correct conclusions, and use this data to fine-tune the model.
-
Conduct "conciseness" preference training: In the RLHF stage, in addition to the "correctness" preference, add an extra "conciseness" preference. That is, in the reward model, give a higher reward to the shorter of two equally correct responses. This can directly guide the model to produce more compact reasoning chains.
-
Prompt Engineering and Decoding Strategy Level:
-
Optimize COT prompts: In Few-Shot examples, use reasoning examples that are inherently very concise. Explicitly request in the instructions to "reason using the minimum necessary steps" or "avoid repetition and wordiness."
-
Post-processing and compression: Allow the model to first generate a complete (potentially long) COT, and then design a lightweight "reflection and compression" module to let the model summarize or trim its own reasoning steps, retaining the core logical chain.
-
Model Architecture and Inference Optimization:
-
Explore more efficient reasoning structures: For example, guide the model to reason using symbolic or more abstract language to reduce redundancy in natural language descriptions.
-
Potential Directions: Investigate whether conditional generation can control the granularity of COT, such as specifying "reasoning depth" or "number of steps" hyperparameters during generation.
Core Idea: The essence is to compress linguistic expression without losing information (key logical transitions). This requires combining high-quality data reconstruction with preference-based behavior tuning.
Q7: How do you locate model defects from a data perspective and propose and drive effective optimization strategies?
Reference Answer: Follow a closed-loop process of "Observe - Locate - Attribute - Act - Verify" to locate and optimize model defects. First, multi-dimensional localization. I would not look at a single metric; instead, I would combine horizontal comparisons of evaluation sets, vertical comparisons across versions, and conduct cluster analysis on Bad Cases (just like how I used to perform clustering attribution on user feedback) to group problems into several root-cause categories such as knowledge, reasoning, and safety.
Then, data attribution. I would trace back training data to analyze whether the defect corresponds to data gaps, low quality, or distribution bias. For instance, if I find that legal reasoning is poor, I would check the proportion and quality of legal-related data.
Next, propose precise strategies. Based on attribution, I would propose concrete plans such as "supplementing high-quality legal COT data" or "optimizing safety-aligned RLHF data". Here, I would use an approach similar to building ROI models in the past to evaluate the expected returns and costs of different data strategies.
Image
Finally, and most importantly, experiment-driven implementation. Design a small-scale data experiment, such as adding the new data to the training mix at a 5% ratio, and then use a rigorous evaluation framework to measure its actual effect. Only strategies validated by data will be pushed for full release and continuously monitored.
The core of this methodology lies in transforming model optimization from a "black-box parameter tuning" process into an analyzable, explainable, and verifiable data science engineering closed-loop."
3. Data Schemes and Benchmark Construction
Q8: How to construct an SFT dataset from scratch (using "legal consultation" as an example)?
Reference Answer:
Adopt the workflow of "expert-led, human-machine collaboration, and multiple quality checks".
-
Data Design: Define scenarios (labor disputes, contract review, etc.) and boundaries (when consultation with a lawyer must be advised) with legal experts.
-
Data Production: Experts draft seed answers → LLMs generate candidates → Annotators with legal backgrounds revise and optimize.
-
Quality Assurance: Expert spot checks → Cross-review → Model consistency checks.
-
Effectiveness Evaluation: Accuracy (factual error rate <1%), usefulness (95% of answers directly solve the problem), safety (100% free of over-promising).
-
Tool Support: Templated instruction generation, automated initial screening of answers, quality control dashboards.
Q9: If you were given a budget to improve the model's ability to "maintain role consistency in complex multi-turn dialogues," how would you allocate it?
Reference Answer:
Allocate according to a 7:2:1 ratio:
-
70% Data Engineering: Invest in building a high-quality role-playing dialogue dataset. The key is not simple annotation, but hiring screenwriters to write seed dialogues → AI expansion (characters, topic shifts) → design "consistency" preference annotations (for example, whether the personality in the tenth turn of dialogue contradicts the first turn).
-
20% Evaluation Benchmarks: Develop automated evaluation tools to assess effectiveness using quantitative metrics (such as personality trait vector consistency, accuracy of knowledge retrieval).
-
10% Algorithmic Experiments: Explore character memory modules or loss function optimization (high risk).
Core Idea: Use data to define problems, use evaluation to drive iterations, and use algorithms as assistance.
Q10: How do you view the value and risks of synthetic data? How would you design a synthesis scheme to address shortcomings in multi-step reasoning?
Reference Answer:
Value: Fills long-tail gaps, precise customization, cost reduction. Risks: Model collapse, distribution shift, compliance issues. Control: Mixed training (synthetic ≤30%), dynamic filtering, diversity incentives, lifecycle management.
To address multi-step reasoning shortcomings:
-
Scheme Design: Seed data (excellent reasoning samples) → change entities/conditions to generate new questions → use an executable validator (such as a code interpreter) to ensure logical correctness → add "red teaming" to synthesize negative examples (setting logical traps in intermediate steps).
-
Collapse Prevention: Keep synthetic data proportion ≤20%; introduce discriminators to filter low-quality data; run small-scale A/B tests to validate positive returns before rolling out fully.
Part 3: Summary and Extension
The world of LLMs is far larger than this, but by mastering the following core framework, you have already surpassed 90% of beginners:
-
Transformer + Self-Attention → Parallel processing, global dependency.
-
Pre-training → SFT → RLHF → Knowledge, skills, values.
-
RAG vs. Agent → Looking up information vs. Getting hands dirty.
-
High-Quality Data → The cornerstone; synthetic data is an amplifier but carries risks.
-
Balance of Data and Model → Phased approach, look at ROI, dynamic optimization.
If you are an LLM analyst or a product manager, it is recommended to further focus on:
-
Evaluation System Design (How to build a three-tier evaluation: basic capability layer, user experience layer, scenario depth layer)
-
Data Flywheel (How to build a data iteration closed-loop from user feedback)
-
Model Capability Balance (Trade-offs between creativity and factuality, fluency and knowledge)
Learning map
Large Language Model (LLM) Knowledge and Analyst Growth Roadmap
Stage 1: Core Theoretical Foundations (Solidifying Internal Skills)
- Transformer Architecture and Self-Attention Mechanism: Learn how models process text in parallel, capture associations between words, and understand the training essence of "predicting the next word".
- Three Stages of LLM Training (Pre-train, SFT, RLHF): Clarify the distinctions and connections between pre-training (determining the ceiling of intelligence), supervised fine-tuning (learning formats and instructions), and reinforcement learning from human feedback (aligning EQ and values).
Stage 2: Application Paradigms and Architectural Design (Technical Implementation)
- RAG (Retrieval-Augmented Generation): Master its principles for mitigating hallucinations and updating knowledge at low cost; understand the workflow of document chunking and embedding vector retrieval.
- AI Agent: Understand the complete closed loop of using LLM as the brain combined with "planning, memory, tool invocation, and execution"; master how to solve complex multi-step tasks.
Stage 3: High-Quality Data Engineering (Core Productivity)
- SFT Dataset Design and Construction: Learn how to design instruction pairs tailored to specific scenarios through "expert writing + AI expansion", and how to control data quality using multiple quality checks.
- Synthetic Data and PE Labeling: Learn how to perform batch automated labeling through Prompt Engineering (PE), and evaluate the balance between synthetic data risks and ROI.
Stage 4: Business Analysis and Interview Practice (Advanced Leap)
- Metric Drill-down and Bad Case Attribution: Master the four-step method of "locate-traceback-hypothesize-verify", and learn to troubleshoot model defects and propose targeted optimization strategies.
- Evaluation System Construction: Understand the gap between academic benchmarks and real user experience, and learn to build business-specific evaluation datasets.
Get hands-on — step by step
Hands-on Practice: Using AI to Help Build and Quality-Control an SFT Q&A Dataset
This experiment will take you through a zero-barrier process using the "human-in-the-loop (PE labeling)" method to build a small SFT training data sample for a "returns and exchanges consultation" scenario.
Preparation
- Set up your Python runtime environment (such as Jupyter Notebook or local VS Code).
- Obtain a large model API key (such as DeepSeek, OpenAI, or Zhipu AI).
Step 1: Configure the API Client
Install the SDK in your terminal (using the OpenAI-compatible library as an example):
pip install openai
Initialize the client in your Python file:
import os
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY", # 替换为你的真实API Key
base_url="https://api.deepseek.com" # 以实际提供商的Base URL为准
)
Step 2: Design Seed Instructions and Batch Generation (Synthetic Data)
Write a Prompt to let the model generate 5 multi-dimensional customer service Q&A pairs (SFT samples) based on your given business rules:
seed_rules = """
退货政策:商品签收后7天内支持无理由退货,商品需不影响二次销售。
换货政策:若因商品质量问题,15天内免费包退换,商家承担运费。
"""
prompt = f"""
基于以下业务规则,生成 5 个不同的客服对话样本。
每个样本格式为 JSON: {{"instruction": "用户问题", "output": "客服合规回答"}}。
业务规则:
{seed_rules}
请确保用户问题包含不同的语气 and 场景(如:催促、抱怨、询问运费)。
"""
response = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": prompt}]
)
raw_data = response.choices[0].message.content
print(raw_data)
Step 3: Write an AI Judge Prompt for Automated Quality Control (First-layer PE Labeling)
Design an "AI Judge" prompt to score the quality of and correct deviations in the SFT data generated in Step 2:
judge_prompt = f"""
你是一个专业的法律与服务质量检测员。请评估以下生成的客服回答是否完全符合业务规则:
业务规则:
{seed_rules}
待评估数据:
{raw_data}
请逐一检查,并输出结构化评估:
1. 是否存在“虚假承诺”或越界回答?
2. 如果存在错误,请给出修改后的完美版本。
"""
judge_response = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": judge_prompt}]
)
print(judge_response.choices[0].message.content)
Step 4: Export to Standard JSONL Training Format
Based on the AI-QCed and manually corrected data, organize and write it into sft_train.jsonl, which is the most common standard format for fine-tuning large models:
import json
sft_samples = [
{
"messages": [
{"role": "system", "content": "你是一个专业的电商客服助手。"},
{"role": "user", "content": "我买的衣服收到8天了,吊牌拆了能退吗?"},
{"role": "assistant", "content": "抱歉呢亲亲,我们的无理由退货政策是签收后7天内,且商品需不影响二次销售。由于您已签收8天且拆除吊牌,暂不支持无理由退货。"}
]
}
# 依次添加经质检合格的样本
]
with open("sft_train.jsonl", "w", encoding="utf-8") as f:
for sample in sft_samples:
f.write(json.dumps(sample, ensure_ascii=False) + "
")
print("数据集已成功构建并导出为 sft_train.jsonl!")
Top 3 sources
- 1Hugging Face NLP Course
官方免费的高质量NLP与Transformer教程,帮助初学者从零掌握模型架构、数据分词与微调实践。
https://huggingface.co/learn/nlp-course
- 2DeepLearning.AI: ChatGPT Prompt Engineering for Developers
由吴恩达与OpenAI联合推出的经典短课程,系统掌握提示词工程、数据批处理及自动化打标的核心技巧。
https://www.deeplearning.ai/short-courses/chatgpt-prompt-engineering-for-developers/
- 3LlamaIndex Documentation
最权威的RAG(检索增强生成)与数据管理框架文档,深度解析文档切分、嵌入与上下文检索的设计与评估。
https://docs.llamaindex.ai/
Links are AI-suggested — worth a quick sanity check before diving in.