> ## Content Index
> Fetch the complete content index at: https://www.hubwiz.com/blog/llms.txt
> Use this file to discover other available public pages before exploring further.

# FragenAntwortLLMCPU
- URL: https://www.hubwiz.com/blog/fragenantwortllmcpu/
- Published: 2024-12-05T14:28:30.000Z
- Updated: 2024-12-05T14:28:30.000Z
- Description: FragenAntwortLLMCPU是一个低成本的库，它不需要 GPU 来通过生成 JSON 格式的问答 (QA) 集来促进微调 LLM 过程的初始步骤。 FragenAntwortLLMCPU仅使用 CPU。
- Author: admin
- Tags: TOOL, DATASET, FRAGENANTWORTLLMCPU, #Import 2026-10-14 14:41

微调大型语言模型 (LLM) 涉及通过提供额外的训练数据来调整预训练模型，使其更有效地执行特定任务。 

FragenAntwortLLMCPU是一个低成本的库，它不需要 GPU 来通过生成 JSON 格式的问答 (QA) 集来促进微调 LLM 过程的初始步骤。 FragenAntwortLLMCPU仅使用 CPU。

本教程将指导你完成库的安装、设置和使用，以生成微调 LLM 所需的 JSONL 文件。

在开始之前，请确保你具备以下条件：

- 对 Python 编程和 LLM 有基本的了解。

## 1、了解 LLM 和 QA 集

> LLM

LLM（如 Mistral）可以通过对大量数据进行训练来理解和生成类似人类的文本。微调这些模型涉及为它们提供额外的特定数据，以提高它们在特定任务上的表现，例如回答文档中的问题、总结文本或参与对话。

> 问答 (QA) 集

QA 集是从文本中得出的问题和答案的对。它们对于训练和微调 LLM 以理解和响应基于文档内容的查询至关重要。生成高质量的 QA 集对于创建有效的微调模型至关重要。

## 2、安装

要安装 FragenAntwortLLMCPU 库，请使用以下 pip 命令：

```
pip install FragenAntwortLLMCPU
```

此命令还将安装必要的依赖项，例如 `PyMuPDF`、 `tokenizers`、 `semantic-text-splitter`、 `langchain` 等。

## 3、基本用法

步骤 1：导入库。

首先，从库中导入必要的组件：

```
from FragenAntwortLLMCPU import DocumentProcessor
```

步骤 2：初始化文档处理器

使用所需参数创建 `DocumentProcessor` 类的实例：

```
pythdeprocessor = DocumentProcessor(
    book_path="path/to/your/document/",  # Directory path without ".pdf" term
    temp_folder="path/to/temp/folder",
    output_file="path/to/output/QA.jsonl",
    book_name="YourDocument.pdf",
    start_page=2,
    end_page=4,
    number_Q_A="one",  # This should be a written number like "one", "two", etc.
    target_information="specific information you need",
    max_new_tokens=1000,
    temperature=0.1,
    context_length=2100,
    max_tokens_chunk=400,
    arbitrary_prompt=""
)
```

参数说明：

- book\_path：不带“.pdf”扩展名的文档的目录路径。
- temp\_folder：用于中间处理的临时文件夹的路径。
- output\_file：将保存输出 JSONL 文件的路径。
- book\_name：文档文件的名称。
- start\_page：处理的起始页码。
- end\_page：处理的结束页码。
- number\_Q\_A：要生成的问答对的数量（以书面数字表示）。
- target\_information：要从文档中提取 QA 对的特定信息。
- max\_new\_tokens：要生成的新标记的最大数量。
- temperature：语言模型的温度率（创造力）。
- context\_length：模型的最大上下文长度。
- max\_tokens\_chunk：每个块的最大标记数。（尝试几个不同的数字以找到最佳性能的数字）
- arbitrary\_prompt：您要使用的任何其他提示。

步骤 3：加载和处理文档

加载文档并处理它以提取文本：

```
processor.process_book()
```

步骤 4：生成提示

从处理后的文本生成提示：

```
prompts = processor.generate_prompts()
print(prompts)
```

步骤 5：将提示保存到文件

将生成的提示保存到 JSONL 文件：

```
processor.save_to_jsonl()
```

## 4、完整示例

以下是将所有步骤放在一起的完整示例：

```
from FragenAntwortLLMCPU import DocumentProcessor
# Initialize the processor
processor = DocumentProcessor(
    book_path="path/to/your/document/",
    temp_folder="path/to/temp/folder",
    output_file="path/to/output/QA.jsonl",
    book_name="YourDocument.pdf",
    start_page=2,
    end_page=4,
    number_Q_A="one",
    target_information="locations and foods",
    max_new_tokens=1000,
    temperature=0.1,
    context_length=2100,
    max_tokens_chunk=400,
    arbitrary_prompt=""
)
# Process the document
processor.process_book()
# Generate prompts
prompts = processor.generate_prompts()
print(prompts)
# Save prompts to a JSONL file
processor.save_to_jsonl()
```

## 5、高级用法

- 自定义处理器

你可以通过在初始化或方法调用期间提供其他参数来自定义 `DocumentProcessor` 的行为。有关详细选项和配置，请参阅库的文档。

- 与其他工具集成

FragenAntwortLLMCPU 库旨在与其他 NLP 和 ML 工具无缝协作。你可以将其集成到现有的工作流程中，以增强文本处理和问答功能。

## 6、结束语

FragenAntwortLLMCPU 库提供了一种强大而灵活的方式来生成 JSONL 文件，用于微调大型语言模型。

---

原文链接：[Fine-Tuning LLMs: Generating JSONL Files with FragenAntwortLLMCPU](https://medium.com/@mehrdad.al.2023/fine-tuning-llms-generating-jsonl-files-with-fragenantwortllmcpu-78678e38b34a?ref=hubwiz.com)

汇智网翻译整理，转载请标明出处