Skip to content
Guides3 min read

理解 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:
  audio_key: audio_path
  text_key: transcript

多模態資料

文本 + 影像

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
{
  "id": "doc_001",
  "text": "Great product!",
  "annotations": {
    "sentiment": "Positive",
    "confidence": 5
  },
  "annotator": "user123",
  "timestamp": "2024-11-05T10:30:00Z"
}

Span 標註

json
{
  "id": "ner_001",
  "text": "Apple CEO Tim Cook visited Paris.",
  "annotations": {
    "entities": [
      {"start": 0, "end": 5, "label": "ORG", "text": "Apple"},
      {"start": 10, "end": 18, "label": "PERSON", "text": "Tim Cook"},
      {"start": 27, "end": 32, "label": "LOC", "text": "Paris"}
    ]
  }
}

多標註者

json
{
  "id": "item_001",
  "text": "Sample text",
  "annotations": [
    {
      "annotator": "ann1",
      "labels": {"sentiment": "Positive"},
      "timestamp": "2024-11-05T10:00:00Z"
    },
    {
      "annotator": "ann2",
      "labels": {"sentiment": "Positive"},
      "timestamp": "2024-11-05T11:00:00Z"
    }
  ],
  "aggregated": {
    "sentiment": "Positive",
    "agreement": 1.0
  }
}

配置參考

yaml
data_files:
  - data/items.json
 
item_properties:
  id_key: id
  text_key: text
  image_key: image_path
  audio_key: audio_path

最佳實踐

  1. 始終包含 ID:用於追蹤的唯一識別符號
  2. 大數據集使用 JSONL:更好的記憶體效率
  3. 載入前驗證:檢查 JSON 語法
  4. 包含後設資料:來源、日期、作者有助於除錯
  5. 一致的欄位名:方便下游處理

完整的資料格式文件請參閱 資料格式