多语言合成数据生成工具,基于大语言模型(LLM)实现文本数据的增强与转换。
本项目是一个多语言数据合成工具,支持两种 Pipeline 模式:
- Simple Pipeline:直接使用 LLM 对输入数据集进行文本增强(默认模式)
- Nemotron-CC Pipeline:使用 nemo_curator 库进行复杂数据合成
支持 15 种语言:英语、中文、日语、法语、德语、西班牙语、葡萄牙语、俄语、阿拉伯语、韩语、希伯来语、印地语、意大利语、荷兰语、波兰语。
synthetic_data_project/
├── main.py # 主入口脚本,支持 CLI 参数
├── config.toml # 主配置文件(包含所有语言和 Prompt 模板)
├── run.sh # Bash 运行脚本(推荐使用)
├── requirements.txt # Python 依赖列表
├── postprocess_simple.py # 后处理脚本
├── constrains.txt # 约束条件文件
├── synthesizer/ # 核心模块目录
│ ├── __init__.py
│ ├── processor.py # 数据处理器
│ └── writer.py # 数据写入器
└── nemo_env/ # Python 虚拟环境(可选)
- Python 3.9+
- LLM API 服务(如 Ollama、OpenAI API、Claude API 等)
# 使用虚拟环境(推荐)
python -m venv nemo_env
source nemo_env/bin/activate # Linux/Mac
# 或 Windows: nemo_env\Scripts\activate
# 安装依赖
pip install -r requirements.txt本项目支持多种 LLM 服务:
Ollama(本地模型,推荐)
# 启动 Ollama 服务
ollama serve
# 下载模型
ollama pull qwen2.5:0.5bOpenAI API
export OPENAI_API_KEY="your-api-key"
export OPENAI_BASE_URL="https://api.openai.com/v1"核心配置项说明:
# ==================== 语言配置 ====================
[languages]
list = ["zh"] # 要处理的语言列表
# ==================== 输入输出 ====================
[io]
input_file = "/path/to/input.jsonl" # 输入文件(支持 ${LANG})
output_file = "/path/to/output.jsonl" # 输出文件
# ==================== API 配置 ====================
[api]
api_key = "any key" # API Key(本地模型用任意值)
base_url = "http://localhost:11434/v1" # Ollama 默认地址
model = "qwen2.5:0.5b" # 模型名称
max_concurrent = 1 # 最大并发数
# ==================== 生成配置 ====================
[generation]
temperature = 0.7 # 采样温度
top_p = 0.9 # Top-P 采样
max_tokens = 2048 # 最大输出 Token 数
prompts = "QA,Wikipedia-style_rephrasing" # 使用的 Prompt 类型| Prompt 类型 | 说明 |
|---|---|
QA |
问答对生成 |
Knowledge_list |
关键信息提取 |
Distill |
知识蒸馏 |
Extract_knowledge |
知识抽取 |
Wikipedia-style_rephrasing |
维基百科风格改写 |
# 基本用法(使用 config.toml 配置)
bash run.sh
# 指定单个 Prompt
bash run.sh --prompts l3_enhance
# 指定多个 Prompt(逗号分隔)
bash run.sh --prompts l3_enhance,l3_expand,l3_refine
# 指定输入输出文件
bash run.sh -i data.jsonl -o output.jsonl
# 使用不同的模型
bash run.sh --model qwen2.5:7b-instruct
# 指定语言
LANG=zh bash run.shpython main.py \
--pipeline simple \
--model qwen2.5:0.5b \
--base-url http://localhost:11434/v1 \
--input input.jsonl \
--output output.jsonl \
--prompts "QA,Wikipedia-style_rephrasing" \
--max-concurrent 5| 参数 | 说明 | 默认值 |
|---|---|---|
--pipeline |
Pipeline 类型 | simple |
--model |
模型名称 | config.toml 中的值 |
--base-url |
API 地址 | config.toml 中的值 |
--api-key |
API Key | config.toml 中的值 |
--input |
输入文件路径 | config.toml 中的值 |
--output |
输出文件路径 | config.toml 中的值 |
--prompts |
Prompt 类型(逗号分隔) | config.toml 中的值 |
--temperature |
采样温度 | 0.7 |
--top-p |
Top-P 采样 | 0.9 |
--max-tokens |
最大输出 Token | 2048 |
--max-concurrent |
最大并发数 | 1 |
--log-level |
日志级别 | INFO |
{"content": "原始文本内容", "language": "zh"}{"content": "原始文本", "language": "zh", "QA": "生成的问答对", "Wikipedia-style_rephrasing": "改写后的文本"}配置 config.toml 中的 [languages] 部分来指定要处理的语言:
[languages]
list = ["en", "zh", "ja", "fr", "de", "es", "pt", "ru", "ar", "ko", "he", "hi", "it", "nl", "pl"]系统会为每种语言加载对应的 Prompt 模板(定义在 config.toml 的 [prompt_templates.{lang}] 部分)。
- 确保 LLM 服务正常运行 - 使用 Ollama 时确保已启动服务
- 调整并发数 - 根据机器配置调整
max_concurrent参数避免过载 - 监控输出 - 建议先运行少量数据测试效果
- 输入文件格式 - 必须为 JSONL 格式,每行一个 JSON 对象
MIT License