用户模拟器
使用可配置行为模拟多个标注者的自动化测试工具。
用户模拟器
用户模拟器通过模拟具有可配置行为和能力水平的多个用户,实现 Potato 标注任务的自动化测试。
概述
模拟器适用于:
- 质量控制测试:测试注意力检查、金标准和屏蔽行为
- 仪表板测试:为管理员仪表板生成真实的标注数据
- 可扩展性测试:使用大量并发用户对服务器进行压力测试
- AI 辅助评估:将 LLM 准确率与类人行为进行比较
- 主动学习测试:模拟迭代标注工作流
快速开始
bash
# Basic random simulation with 10 users
python -m potato.simulator --server http://localhost:8000 --users 10
# With configuration file
python -m potato.simulator --config simulator-config.yaml --server http://localhost:8000
# Fast scalability test (no waiting between annotations)
python -m potato.simulator --server http://localhost:8000 --users 50 --parallel 10 --fast-mode配置
YAML 配置文件
创建包含模拟器设置的 YAML 文件:
yaml
simulator:
# User configuration
users:
count: 20
competence_distribution:
good: 0.5 # 50% will be "good" annotators (80-90% accuracy)
average: 0.3 # 30% "average" (60-70% accuracy)
poor: 0.2 # 20% "poor" (40-50% accuracy)
# Annotation strategy
strategy: random # random, biased, llm, pattern
# Timing configuration
timing:
annotation_time:
min: 2.0
max: 45.0
mean: 12.0
std: 6.0
distribution: normal # uniform, normal, exponential
# Execution
execution:
parallel_users: 5
delay_between_users: 0.5
max_annotations_per_user: 50
server:
url: http://localhost:8000能力水平
| 水平 | 准确率 | 描述 |
|---|---|---|
perfect | 100% | 始终匹配金标准 |
good | 80-90% | 高质量标注者 |
average | 60-70% | 典型众包工人 |
poor | 40-50% | 低质量标注者 |
random | ~1/N | 从标签中随机选择 |
adversarial | 0% | 故意选错(用于测试质量控制) |
标注策略
随机策略(默认)
均匀随机选择标签:
yaml
strategy: random偏向策略
基于标签偏好的加权选择:
yaml
strategy: biased
biased_config:
label_weights:
positive: 0.6
negative: 0.3
neutral: 0.1LLM 策略
使用 LLM 根据文本内容生成标注:
yaml
strategy: llm
llm_config:
endpoint_type: openai
model: gpt-4o-mini
api_key: ${OPENAI_API_KEY}
temperature: 0.1
add_noise: true
noise_rate: 0.05使用 Ollama 的本地 LLM:
yaml
strategy: llm
llm_config:
endpoint_type: ollama
model: llama3.2
base_url: http://localhost:11434CLI 选项
text
Usage: python -m potato.simulator [OPTIONS]
Required:
--server, -s URL Potato server URL
User Configuration:
--users, -u NUM Number of simulated users (default: 10)
--competence DIST Competence distribution
Strategy:
--strategy TYPE Strategy: random, biased, llm, pattern
--llm-endpoint TYPE LLM endpoint: openai, anthropic, ollama
--llm-model NAME LLM model name
Execution:
--parallel, -p NUM Max concurrent users (default: 5)
--max-annotations, -m Max annotations per user
--fast-mode Disable waiting between annotations
Output:
--output-dir, -o DIR Output directory (default: simulator_output)
质量控制测试
测试注意力检查检测:
yaml
simulator:
users:
count: 10
competence_distribution:
adversarial: 1.0 # All users will fail
quality_control:
attention_check_fail_rate: 0.5
respond_fast_rate: 0.3输出文件
模拟完成后,结果导出到输出目录:
summary_{timestamp}.json- 汇总统计user_results_{timestamp}.json- 每用户详细结果annotations_{timestamp}.csv- 所有标注的扁平格式
摘要示例
json
{
"user_count": 20,
"total_annotations": 400,
"total_time_seconds": 125.3,
"attention_checks": {
"passed": 18,
"failed": 2,
"pass_rate": 0.9
}
}编程方式使用
python
from potato.simulator import SimulatorManager, SimulatorConfig
# Create configuration
config = SimulatorConfig(
user_count=10,
strategy="random",
competence_distribution={"good": 0.5, "average": 0.5}
)
# Create and run simulator
manager = SimulatorManager(config, "http://localhost:8000")
results = manager.run_parallel(max_annotations_per_user=20)
# Print summary and export
manager.print_summary()
manager.export_results()与测试集成
模拟器可以在 pytest fixture 中使用:
python
import pytest
from potato.simulator import SimulatorManager, SimulatorConfig
@pytest.fixture
def simulated_annotations(flask_test_server):
config = SimulatorConfig(user_count=5, strategy="random")
manager = SimulatorManager(config, flask_test_server.base_url)
return manager.run_parallel(max_annotations_per_user=10)
def test_dashboard_shows_annotations(simulated_annotations, flask_test_server):
response = requests.get(f"{flask_test_server.base_url}/admin/api/overview")
assert response.json()["total_annotations"] > 0故障排除
登录失败
- 确保服务器允许匿名注册或设置了
require_password: false - 检查服务器日志中的身份验证错误
没有可用实例
- 验证数据文件是否正确加载
- 检查分配策略设置
LLM 策略不工作
- 验证 API 密钥已设置
- 对于 Ollama,确保服务器正在运行
- 检查模型名称是否正确
延伸阅读
有关实现细节,请参阅源代码文档。