Skip to content
指南阅读约需 4 分钟

理解 Potato 数据格式

深入介绍 JSON 和 JSONL 数据格式,包含文本、图像、音频和多模态标注的示例。

Potato Team

Potato 使用 JSON 和 JSONL 格式处理输入数据和输出标注。本指南涵盖所有数据类型的格式规范、示例和最佳实践。

输入数据格式

JSON Lines (JSONL) - 推荐

每行一个 JSON 对象:

json
{"id": "001", "text": "First document text here."}
{"id": "002", "text": "Second document text here."}
{"id": "003", "text": "Third document text here."}

优势:

  • 流式处理(内存高效)
  • 便于追加数据
  • 单行损坏不会影响整个文件

JSON 数组

标准 JSON 数组:

json
[
  {"id": "001", "text": "First document."},
  {"id": "002", "text": "Second document."},
  {"id": "003", "text": "Third document."}
]

配置:

yaml
data_files:
  - data/items.json

文本标注数据

基本文本

json
{"id": "doc_001", "text": "The product quality exceeded my expectations."}

带元数据

json
{
  "id": "review_001",
  "text": "Great product, fast shipping!",
  "metadata": {
    "source": "amazon",
    "date": "2024-01-15",
    "author": "user123",
    "rating": 5
  }
}

带预标注

json
{
  "id": "ner_001",
  "text": "Apple announced new products in Cupertino.",
  "pre_annotations": {
    "entities": [
      {"start": 0, "end": 5, "label": "ORG", "text": "Apple"},
      {"start": 31, "end": 40, "label": "LOC", "text": "Cupertino"}
    ]
  }
}

配置:

yaml
data_files:
  - data/texts.json
 
item_properties:
  id_key: id
  text_key: text

图像标注数据

本地图像

json
{
  "id": "img_001",
  "image_path": "/data/images/photo_001.jpg",
  "caption": "Street scene in Paris"
}

远程图像

json
{
  "id": "img_002",
  "image_url": "https://example.com/images/photo.jpg"
}

带边界框

json
{
  "id": "detection_001",
  "image_path": "/images/street.jpg",
  "pre_annotations": {
    "objects": [
      {"bbox": [100, 150, 200, 300], "label": "person"},
      {"bbox": [350, 200, 450, 280], "label": "car"}
    ]
  }
}

配置:

yaml
data_files:
  - data/images.json
 
item_properties:
  id_key: id
  image_key: image_path  # or image_url

音频标注数据

本地音频

json
{
  "id": "audio_001",
  "audio_path": "/data/audio/recording.wav",
  "duration": 45.5,
  "transcript": "Hello, how are you today?"
}

带分段

json
{
  "id": "audio_002",
  "audio_path": "/audio/meeting.mp3",
  "segments": [
    {"start": 0.0, "end": 5.5, "speaker": "Speaker1"},
    {"start": 5.5, "end": 12.0, "speaker": "Speaker2"}
  ]
}

配置:

yaml
data_files:
  - data/audio.json
 
item_properties:
  id_key: id
  text_key: transcript
 
instance_display:
  fields:
    - key: audio_path
      type: audio
      display_options:
        controls: true

多模态数据

文本 + 图像

json
{
  "id": "mm_001",
  "text": "What is shown in this image?",
  "image_path": "/images/scene.jpg"
}

文本 + 音频

json
{
  "id": "mm_002",
  "text": "Transcribe this audio:",
  "audio_path": "/audio/clip.wav",
  "reference_transcript": "Expected transcription here"
}

输出标注格式

基本输出

json
{
  "instance_id": "doc_001",
  "user_id": "user123",
  "labels": {
    "sentiment": {"Positive": "true"},
    "confidence": {"5": "true"}
  },
  "spans": {},
  "links": {}
}

Span 标注

跨度按标注方案名称分组。每条跨度存的是偏移量,标签放在 name 里,jsonl 导出器还会补上这些偏移覆盖到的 text:

json
{
  "instance_id": "ner_001",
  "user_id": "user123",
  "labels": {},
  "spans": {
    "entities": [
      {"schema": "entities", "name": "ORG", "start": 0, "end": 5, "text": "Apple"},
      {"schema": "entities", "name": "PERSON", "start": 10, "end": 18, "text": "Tim Cook"},
      {"schema": "entities", "name": "LOC", "start": 27, "end": 32, "text": "Paris"}
    ]
  },
  "links": {}
}

多标注者

导出是每个标注者、每个条目一条记录,所以同一条目上的两个标注者是两行,而不是一条嵌套记录。Potato 不写任何聚合字段;多数投票和一致性都要你自己从这些行里算:

json
{"instance_id": "item_001", "user_id": "ann1", "labels": {"sentiment": {"Positive": "true"}}, "spans": {}, "links": {}}
{"instance_id": "item_001", "user_id": "ann2", "labels": {"sentiment": {"Positive": "true"}}, "spans": {}, "links": {}}

配置参考

yaml
data_files:
  - data/items.json
 
item_properties:
  id_key: id
  text_key: text
  image_key: image_path
 
instance_display:
  fields:
    - key: audio_path
      type: audio

最佳实践

  1. 始终包含 ID:用于追踪的唯一标识符
  2. 大数据集使用 JSONL:更好的内存效率
  3. 加载前验证:检查 JSON 语法
  4. 包含元数据:来源、日期、作者有助于调试
  5. 一致的字段名:方便下游处理

完整的数据格式文档请参阅 数据格式。