Minimind/preprocessing/README_trex_processor.md

97 lines
3.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# TREx 数据集处理工具使用说明
这个工具支持两步骤处理 TREx 数据集:
1. **句子提取**:从 TREx 数据集提取三元组并转换为自然语言句子
2. **LLM 处理**:使用 ollama qwen3:4b 模型进行句子修正和重要性评分
## 安装依赖
```bash
pip install agno asyncio pydantic
```
确保已安装并启动 ollama并下载 qwen3:4b 模型:
```bash
ollama pull qwen3:4b
```
## 使用方法
### 1. 完整流程(两步骤连续执行)
```bash
python trex_to_sentences_simple.py --step all --input_dir dataset/TREx --max_files 2
```
### 2. 分步骤执行
#### 步骤1仅提取句子
```bash
python trex_to_sentences_simple.py --step extract --input_dir dataset/TREx --sentences_json my_sentences.json --max_files 2
```
#### 步骤2仅LLM处理
```bash
python trex_to_sentences_simple.py --step llm --sentences_json my_sentences.json --output_file final_output.txt
```
## 主要参数说明
- `--step`: 运行步骤
- `extract`: 仅提取句子
- `llm`: 仅LLM处理
- `all`: 完整流程(默认)
- `--input_dir`: TREx数据集目录默认`dataset/TREx`
- `--sentences_json`: 提取的句子JSON文件默认`extracted_sentences.json`
- `--output_file`: 最终输出文件(默认:`trex_sentences_enhanced.txt`
- `--max_files`: 最大处理文件数(用于测试)
- `--no_llm`: 禁用LLM处理
## 输出文件
**注意:所有输出文件都会自动保存在 `./output/` 目录中**
### 步骤1输出
- `output/extracted_sentences.json`: 提取的原始句子,包含元数据
### 步骤2输出
- `output/{output_file}.txt`: 修正后的句子文本文件
- `output/{output_file}.json`: 完整的处理结果(包含原句、修正句、评分)
- `output/{output_file}_sorted_by_importance.txt`: 按重要性评分排序的句子
### 检查点文件
- `output/{output_file}_checkpoint_{数量}.json`: 每2000条句子自动保存的检查点
## 检查点恢复机制
- 步骤2会自动检测已有的检查点文件`output/` 目录中)
- 只处理尚未处理的句子,避免重复工作
- 如果所有句子都已处理,会直接生成最终输出文件
## 示例工作流
```bash
# 1. 先提取句子(可以快速完成)
python trex_to_sentences_simple.py --step extract --max_files 5
# 2. 后续进行LLM处理耗时较长支持断点续传
python trex_to_sentences_simple.py --step llm
# 如果中途中断再次运行步骤2会自动从检查点恢复
python trex_to_sentences_simple.py --step llm
```
## 性能特点
- **并发处理**: 最大54个并发LLM请求
- **检查点保存**: 每2000条句子自动保存支持断点续传
- **进度显示**: 详细的处理进度和时间预估
- **错误处理**: LLM请求失败时使用原句子和默认评分
## 注意事项
1. 首次运行步骤2前必须先完成步骤1
2. 检查点文件会占用额外磁盘空间(每个都包含所有已处理数据)
3. LLM处理速度取决于模型性能和网络状况
4. 建议先用`--max_files`参数测试小批量数据