> For the complete documentation index, see [llms.txt](https://unsloth.ai/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://unsloth.ai/docs/zh/xin/studio/data-recipe.md).

# Unsloth 数据配方

了解如何使用 Unsloth Studio 的数据配方创建、构建和编辑数据集。

Unsloth Studio 的 Data Recipes 允许你上传 PDF 或 CSV 等文档，并将它们转换为可用的/合成的数据集。通过图节点工作流以可视化方式创建和编辑数据集。在深入了解 Unsloth Data Recipes 之前，本指南将带你了解基础知识。

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FQ6e19jESrJg0VjHnX58c%2Fdata%20recipes%20final.png?alt=media&amp;token=8d74e453-815d-4790-83d1-76d0bc80a3ce" alt=""><figcaption></figcaption></figure></div>

### Data Recipes 的工作原理

Data Recipes 遵循相同的基本流程。你打开 recipes 页面，创建或选择一个 recipe，在编辑器中构建工作流，进行验证并运行预览，然后在输出看起来正确后运行完整数据集。添加种子数据和生成块，验证工作流，预览示例输出，然后运行完整的数据集构建。Unsloth Data Recipes 由以下技术驱动： **NVIDIA Nemo** [**Data Designer**](https://github.com/NVIDIA-NeMo/DataDesigner).

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fc5m3JX1kUA3UwmdcJcxH%2FArea.gif?alt=media&amp;token=33bbd908-7d6c-456a-bc58-ce495c0adca1" alt=""><figcaption><p>生成数据集并微调模型的示例</p></figcaption></figure></div>

一眼看去，常见的工作流应如下所示：

1. 打开 recipes 页面。
2. 创建一个新 recipe 或打开一个现有 recipe。
3. 添加 blocks 来定义你的数据集工作流。
4. 点击 **验证** 以便尽早发现配置问题。
5. 运行预览以快速检查示例行。
6. 当 recipe 准备就绪时，运行完整的数据集构建。
7. 在图中或在以下位置实时查看进度和输出： **执行** 视图，以查看更多详情。
8. 在中选择生成的数据集 **Unsloth** 并微调模型。

### 开始使用

recipes 页面是主要入口。Recipes 会本地存储在浏览器中，因此你之后可以回到已保存的工作。从这里，你可以创建一个空白 recipe，或者打开一个引导式学习 recipe。

{% hint style="info" %}
Recipes 可以导出和导入，因此很容易与其他 Unsloth 用户分享工作流 :tada:。如果你正在尝试构建某种特定的数据集模式，可以在 Unsloth Discord 中提问。也许已经有人有可以分享的 recipe。
{% endhint %}

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FAwKh7speKv3eXERFhPg2%2FScreenshot%202026-03-13%20at%2008.26.11.png?alt=media&amp;token=809ac83f-75c8-4ef2-9721-65971b3faaa5" alt="" width="563"><figcaption><p>Recipes 首页</p></figcaption></figure></div>

如果你刚接触工作流的概念，学习型 recipes 是最快了解种子数据、提示、表达式和校验器如何在一个可运行示例中组合在一起的方式。如果你已经知道自己想要的数据集形状，从空白开始通常更快。

#### 选择起始路径

<table><thead><tr><th>如果你想要：</th><th>起始方式：</th><th data-hidden></th></tr></thead><tbody><tr><td><sub><strong>快速构建自定义工作流</strong></sub></td><td><sub><strong>从空白开始</strong></sub></td><td></td></tr><tr><td><sub><strong>通过示例了解产品</strong></sub></td><td><sub><strong>从学习型 recipe 开始</strong></sub></td><td></td></tr><tr><td><sub><strong>继续之前的工作</strong></sub></td><td><sub><strong>打开已保存的 recipe</strong></sub></td><td></td></tr></tbody></table>

### 你在编辑器中构建的内容

编辑器是 recipe 成形的地方。你从 block sheet 中添加 blocks，在对话框中配置它们，在画布上将它们连接起来，然后验证或运行工作流。

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F6A2uN85dkYAdP7v0eUyX%2Fworkflow.gif?alt=media&amp;token=b44d9682-1825-4ddb-88f6-485a2aea3359" alt="" width="563"><figcaption><p>构建产品描述工作流的示例</p></figcaption></figure></div>

{% columns %}
{% column %}
编辑器有几个核心部分：

* recipe 标头，你可以在这里重命名 recipe，并在以下选项之间切换 **编辑器** 和 **执行**
* 画布，recipe 图会显示在这里
* block sheet，你可以在这里添加新 blocks
* 配置对话框，你可以在这里定义 prompts、references、模型别名、校验器和种子设置。
* 浮动的 **运行** 和 **验证** 控件
* 这里还需要添加更多内容

{% endcolumn %}

{% column %}
recipes 中最常见的 blocks 是：

* **种子** 用于来自 Hugging Face 的输入数据、本地结构化文件（或会被分块成行的非结构化文档）。
* **LLM + 模型** 用于提供方、模型配置、LLM 生成 blocks，以及共享工具配置文件。
* **表达式** 用于不需要 LLM 调用的基于 Jinja2 的转换。
* **校验器** 用于通过内置的 Python、SQL 和 JavaScript/TypeScript 代码检查器过滤不良生成代码。
* **采样器** 用于类别和子类别等确定性列。
  {% endcolumn %}
  {% endcolumns %}

### 引用如何工作

大多数会产生数据的 blocks（有少数例外）都会成为后续 blocks 的引用。这是 Data Recipes 背后的核心理念之一。你只需创建一次值，然后在 prompts、表达式、结构化输出和验证步骤中重复使用它。

{% hint style="info" %}
Jinja 表达式可帮助你处理 recipe 中已经存在的值。你可以引用嵌套字段，例如 `{{customer.first_name}}` ，连接值例如 `{{customer.first_name}} {{customer.last_name}}` ，并使用如下模式添加条件逻辑： `{% if condition %}...{% endif %}`&#x20;
{% endhint %}

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FNJYWKeIDC6aqgT2dShsB%2FScreenshot%202026-03-13%20at%2010.06.14.png?alt=media&amp;token=9d20bb8c-8a25-4395-9616-6429021d76f0" alt="" width="563"><figcaption><p>编辑器中显示引用的示例</p></figcaption></figure></div>

例如：

* 一个名为 `domain` 的类别块可以被引用为 `{{ domain }}`
* 种子列可以直接用于 LLM 提示词，你的种子数据中的列（例如 HF 数据集列、csv）
* 结构化的 LLM 输出可以为后续提示暴露字段
* 表达式块可以在不进行另一个模型调用的情况下组合早期值

### 接下来会发生什么？

预览运行用于快速迭代。它们会在编辑器中返回示例行和分析结果，以便你在提交完整运行之前检查生成的数据。

完整运行会创建一个持久化的本地数据集制品。该输出随后会出现在 Unsloth 的本地数据集选择器中，你可以再次检查它并用于微调。你也可以选择将数据集发布到你的 Hugging Face 仓库。

### 核心构建块

{% columns %}
{% column %}

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FuphMi76re2aUX7JvFNce%2FScreenshot%202026-03-13%20at%2011-35-45%20Unsloth%20Studio.png?alt=media&amp;token=674eb5ef-5acb-4b32-ab85-11a2af2e210f" alt="" width="188"><figcaption><p>核心构建块</p></figcaption></figure></div>
{% endcolumn %}

{% column %}

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FsdoYKdurtGeu4YgVqu0q%2FScreenshot%202026-03-13%20at%2011-38-59%20Unsloth%20Studio.png?alt=media&amp;token=328c7ea6-591e-43fa-9e87-c71277a54736" alt="" width="188"><figcaption><p>模型和 LLM blocks</p></figcaption></figure></div>
{% endcolumn %}
{% endcolumns %}

#### 模型设置分为两个可用层：

* **模型提供方** 定义端点和身份验证
* **模型配置** 定义模型名称和推理设置

这种设置适用于托管提供方、自托管端点， `vLLM` , `llama.cpp` 或任何你在 Unsloth 外部运行的 OpenAI 兼容 API。

{% hint style="info" %}
Recipes 不限于一个模型。你可以添加多个 **模型提供方** 和 **模型配置** blocks，然后在不同步骤中使用不同模型，例如一个用于编码，另一个用于通用文本任务。
{% endhint %}

完成模型设置后，你可以使用四种 LLM block 类型：

| 块       | 输出     | 最适合                             |
| ------- | ------ | ------------------------------- |
| LLM 文本  | 自由形式文本 | 指令、解释、对话和描述                     |
| LLM 结构化 | JSON   | 需要固定字段和可预测结构的输出                 |
| LLM 代码  | 代码     | Python、SQL、TypeScript 和其他代码生成任务 |
| LLM 裁判  | 评分评估   | 使用一个或多个用户定义评分对输出进行评分            |

#### 工具配置文件

{% columns %}
{% column %}
工具配置文件 blocks 为一个或多个 LLM blocks 定义基于 MCP 的共享工具访问。当生成步骤需要工具时使用它们，例如通过以下方式查找代码文档： `Context7`.

左图显示了在工具配置文件 block 对话框中添加并配置了 Context7 MCP：
{% endcolumn %}

{% column %}

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fu4GbfrjuQyiU7cN15fDY%2FScreenshot%202026-03-13%20at%2010.50.01.png?alt=media&amp;token=889a9425-bb40-4e41-9dab-5408b03bd3ca" alt="" width="375"><figcaption></figcaption></figure></div>
{% endcolumn %}
{% endcolumns %}

#### 校验器

{% columns %}
{% column %}
校验器 block 主要通过运行生成的代码输出并进行 Linter 和语法验证来针对 LLM 代码 block，这有助于你通过过滤掉不良或无效代码行，将它们排除在最终数据集之外。内置选项涵盖 Python、SQL 和 JavaScript/TypeScript 验证。
{% endcolumn %}

{% column %}

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FobyvYzcfyJkloHfHMyVC%2FScreenshot%202026-03-13%20at%2011-39-08%20Unsloth%20Studio.png?alt=media&amp;token=19c8dbfa-c876-4f6e-9e62-5b8df515dc7b" alt=""><figcaption></figcaption></figure></div>
{% endcolumn %}
{% endcolumns %}

### 验证、预览和运行

一旦 recipe 工作流就位，下一步就是执行。推荐的模式是：先验证以发现配置问题，再预览以快速获得反馈并在执行视图中检查生成的数据，然后在你觉得输出符合计划时运行完整数据集。

按以下顺序使用执行控件：

{% stepper %}
{% step %}

#### 验证

点击 **验证** 以发现配置问题。
{% endstep %}

{% step %}

#### 预览

运行预览以检查示例行和分析结果
{% endstep %}

{% step %}

#### 优化

优化 prompts、引用、种子设置或校验器。

不断迭代，直到你对生成的数据感到满意
{% endstep %}

{% step %}

#### 运行完整的数据集构建

{% endstep %}
{% endstepper %}

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FFCcEaVt8xsaNsMFi2MoZ%2Funsloth%20chef.png?alt=media&amp;token=0266aa36-4ba7-4364-be59-5fe57936ef7f" alt="" width="188"><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://unsloth.ai/docs/zh/xin/studio/data-recipe.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
