[ PROMPT_NODE_22390 ]
custom-tasks
[ SKILL_DOCUMENTATION ]
# 自定义任务
在 lm-evaluation-harness 中创建特定领域评估任务的完整指南。
## 概述
自定义任务允许您在自己的数据集和指标上评估模型。任务通过 YAML 配置文件定义,并可选择使用 Python 工具处理复杂逻辑。
**为什么要创建自定义任务**:
- 在私有/特定领域数据上进行评估
- 测试现有基准未涵盖的特定能力
- 为内部模型创建评估工作流
- 复现研究实验
## 快速开始
### 最小化自定义任务
创建 `my_tasks/simple_qa.yaml`:
yaml
task: simple_qa
dataset_path: data/simple_qa.jsonl
output_type: generate_until
doc_to_text: "问题: {{question}}n答案:"
doc_to_target: "{{answer}}"
metric_list:
- metric: exact_match
aggregation: mean
higher_is_better: true
**运行它**:
bash
lm_eval --model hf
--model_args pretrained=meta-llama/Llama-2-7b-hf
--tasks simple_qa
--include_path my_tasks/
## 任务配置参考
### 核心字段
yaml
# 任务标识
task: my_custom_task # 唯一任务名称 (必填)
task_alias: "我的任务" # 显示名称
tag: # 用于分组的标签
- custom
- domain_specific
# 数据集配置
dataset_path: data/my_data.jsonl # HuggingFace 数据集或本地路径
dataset_name: default # 子集名称 (如果适用)
training_split: train
validation_split: validation
test_split: test
# 评估配置
output_type: generate_until # 或 loglikelihood, multiple_choice
num_fewshot: 5 # 少样本示例数量
batch_size: auto # 批处理大小
# 提示词模板 (Jinja2)
doc_to_text: "问题: {{question}}"
doc_to_target: "{{answer}}"
# 指标
metric_list:
- metric: exact_match
aggregation: mean
higher_is_better: true
# 元数据
metadata:
version: 1.0
### 输出类型
**`generate_until`**: 自由生成
yaml
output_type: generate_until
generation_kwargs:
max_gen_toks: 256
until:
- "n"
- "."
temperature: 0.0
**`loglikelihood`**: 计算目标的对数概率
yaml
output_type: loglikelihood
# 用于困惑度、分类任务
**`multiple_choice`**: 从选项中选择
yaml
output_type: multiple_choice
doc_to_choice: "{{choices}}" # 选项列表
## 数据格式
### 本地 JSONL 文件
`data/my_data.jsonl`:
{"question": "2+2 等于多少?", "answer": "4"}
{"