Skip to content

行为追踪

捕获详细的交互数据用于质量分析和研究。

行为追踪

Potato 的行为追踪系统在标注会话期间捕获详细的交互数据,使研究人员能够分析标注者行为、时间模式、AI 辅助使用和决策过程。

概述

行为追踪系统捕获:

  • 每个标注操作:标签选择、片段标注、文本输入
  • 精确时间戳:服务器端和客户端时间戳
  • AI 辅助使用:何时显示建议以及是否被接受
  • 焦点和时间数据:在每个元素上花费的时间、滚动深度
  • 导航历史:完整的实例浏览路径

追踪内容

交互事件

与标注界面的每次用户交互都会被捕获:

事件类型描述示例目标
click元素上的鼠标点击label:positivenav:next
focus_in元素获得焦点textbox:explanation
focus_out元素失去焦点label:negative
keypress键盘快捷键key:1nav:ArrowRight
navigation实例导航nextprevinstance_load
save标注保存事件instance:123
annotation_change标签修改schema:sentiment

AI 辅助使用

AI 辅助标注的完整生命周期追踪:

json
{
  "request_timestamp": 1706500010.0,
  "response_timestamp": 1706500012.5,
  "schema_name": "sentiment",
  "suggestions_shown": ["positive", "neutral"],
  "suggestion_accepted": "positive",
  "time_to_decision_ms": 3500
}

标注变更

所有标注的详细变更历史:

json
{
  "timestamp": 1706500002.5,
  "schema_name": "sentiment",
  "label_name": "positive",
  "action": "select",
  "old_value": null,
  "new_value": true,
  "source": "user"
}

来源类型:

  • user - 直接用户交互
  • ai_accept - 用户接受了 AI 建议
  • keyboard - 使用了键盘快捷键
  • prefill - 从配置预填充

数据格式

每个标注实例包含一个 behavioral_data 对象:

json
{
  "id": "instance_123",
  "annotations": {
    "sentiment": {"positive": true}
  },
  "behavioral_data": {
    "instance_id": "instance_123",
    "session_start": 1706500000.0,
    "session_end": 1706500045.0,
    "total_time_ms": 45000,
    "interactions": [...],
    "ai_usage": [...],
    "annotation_changes": [...],
    "navigation_history": [...],
    "focus_time_by_element": {
      "label:positive": 2500,
      "textbox:explanation": 8000
    },
    "scroll_depth_max": 75.5
  }
}

配置

行为追踪默认启用。无需额外配置。

前端调试模式

要启用交互追踪器的调试日志:

javascript
// In browser console
window.interactionTracker.setDebugMode(true);

分析示例

加载行为数据

python
import json
from pathlib import Path
 
def load_behavioral_data(annotation_dir: str) -> dict:
    data = {}
    for user_dir in Path(annotation_dir).iterdir():
        if not user_dir.is_dir():
            continue
        state_file = user_dir / 'user_state.json'
        if state_file.exists():
            with open(state_file) as f:
                user_state = json.load(f)
            user_id = user_state.get('user_id')
            behavioral = user_state.get('instance_id_to_behavioral_data', {})
            data[user_id] = behavioral
    return data

分析标注时间

python
def analyze_annotation_time(behavioral_data: dict) -> dict:
    stats = {}
    for user_id, instances in behavioral_data.items():
        times = []
        for instance_id, bd in instances.items():
            if 'total_time_ms' in bd:
                times.append(bd['total_time_ms'] / 1000)
        if times:
            stats[user_id] = {
                'mean_time': sum(times) / len(times),
                'min_time': min(times),
                'max_time': max(times),
                'total_instances': len(times)
            }
    return stats

检测可疑行为

python
def detect_suspicious_annotators(behavioral_data: dict,
                                  min_time_threshold: float = 2.0) -> list:
    suspicious = []
    for user_id, instances in behavioral_data.items():
        fast_count = 0
        for instance_id, bd in instances.items():
            time_sec = bd.get('total_time_ms', 0) / 1000
            if time_sec < min_time_threshold:
                fast_count += 1
 
        total = len(instances)
        if total > 0:
            fast_rate = fast_count / total
            if fast_rate > 0.5:
                suspicious.append({
                    'user_id': user_id,
                    'fast_rate': fast_rate,
                    'total_instances': total
                })
    return suspicious

管理员仪表板集成

管理员仪表板包含行为分析标签页,提供:

  1. 用户交互热图:交互模式的可视化表示
  2. AI 辅助指标:接受/拒绝率、决策时间
  3. 时间分布:标注时间直方图
  4. 可疑活动警报:需要审查的标记标注者

API 端点

追踪交互

http
POST /api/track_interactions
Content-Type: application/json
 
{
  "instance_id": "instance_123",
  "events": [...],
  "focus_time": {"element": ms},
  "scroll_depth": 75.5
}

获取行为数据

http
GET /api/behavioral_data/<instance_id>

返回实例的完整行为数据。

最佳实践

对于研究人员

  1. 建立基线:从已知优秀标注者收集行为数据以建立基线
  2. 质量指标:将行为数据与标注一致性结合用于质量评估
  3. 培训评估:比较培训前后的行为模式
  4. AI 影响分析:衡量 AI 辅助如何影响标注质量和速度

对于标注项目

  1. 实时监控:使用管理员仪表板尽早发现问题
  2. 设定阈值:定义时间和交互指标的可接受范围
  3. 提供反馈:使用行为洞察为标注者提供有针对性的反馈

故障排除

没有收集到行为数据

  1. 验证 interaction_tracker.js 已加载(检查浏览器网络标签页)
  2. 检查浏览器控制台是否有 JavaScript 错误
  3. 验证 API 端点可访问(/api/track_interactions

数据未持久化

  1. 检查用户状态是否正在保存(查找 user_state.json
  2. 确保标注输出目录可写

延伸阅读

有关实现细节,请参阅源代码文档