Tutorials3 min read
構建你的第一個命名實體識別標註任務
逐步教程:建立帶有 span 標籤和鍵盤快捷鍵的命名實體識別標註任務。
Potato Team
命名實體識別(NER)是最常見的 NLP 任務之一。在本教程中,你將學習如何建立一個完整的 NER 標註介面,包含文本高亮、鍵盤快捷鍵和實體類型選擇。
我們要構建的內容
完成本教程後,你將擁有一個標註介面,標註者可以:
- 通過點選和拖動來高亮文本片段
- 分配實體類型(人物、組織、地點等)
- 使用鍵盤快捷鍵加速標註
- 編輯或刪除已有標註
前置條件
- 已安裝 Potato(
pip install potato-annotation) - 基本的 YAML 知識
- 待標註的示例文本資料
第1步:配置標註方案
建立 config.yaml 檔案:
yaml
annotation_task_name: "Named Entity Recognition"
data_files:
- data/sentences.json
item_properties:
id_key: id
text_key: text
# Enable span annotation
annotation_schemes:
- annotation_type: span
name: entities
description: "Highlight and label named entities in the text"
labels:
- name: PER
description: "Person names"
color: "#FF6B6B"
keyboard_shortcut: "p"
- name: ORG
description: "Organizations"
color: "#4ECDC4"
keyboard_shortcut: "o"
- name: LOC
description: "Locations"
color: "#45B7D1"
keyboard_shortcut: "l"
- name: DATE
description: "Dates and times"
color: "#96CEB4"
keyboard_shortcut: "d"
- name: MISC
description: "Miscellaneous entities"
color: "#FFEAA7"
keyboard_shortcut: "m"第2步:準備資料
建立 data/sentences.json,包含你的文本資料:
json
{"id": "1", "text": "Apple Inc. announced that CEO Tim Cook will visit Paris next Tuesday."}
{"id": "2", "text": "The United Nations headquarters in New York hosted delegates from Japan."}
{"id": "3", "text": "Dr. Sarah Johnson published her research at Stanford University in March 2024."}第3步:新增標註指南
用清晰的指南幫助你的標註者:
yaml
# Add to config.yaml
annotation_guidelines:
title: "NER Annotation Guidelines"
content: |
## Entity Types
**PER (Person)**: Names of people, including fictional characters
- Examples: "John Smith", "Dr. Johnson", "Batman"
**ORG (Organization)**: Companies, institutions, agencies
- Examples: "Apple Inc.", "United Nations", "Stanford University"
**LOC (Location)**: Places, including countries, cities, landmarks
- Examples: "Paris", "New York", "Mount Everest"
**DATE**: Dates, times, and temporal expressions
- Examples: "Tuesday", "March 2024", "next week"
**MISC**: Other named entities not fitting above categories
- Examples: "Nobel Prize", "iPhone", "COVID-19"
## Annotation Rules
1. Include titles (Dr., Mr.) with person names
2. For nested entities, annotate the largest meaningful span
3. Don't include articles (the, a) in entity spans第4步:開始標註
啟動你的 NER 任務:
bash
potato start config.yaml標註工作流程
- 選擇文本:點選並拖動以高亮一個片段
- 選擇實體類型:點選標籤按鈕或使用鍵盤快捷鍵
- 編輯標註:點選已有的 span 進行修改或刪除
- 提交:完成後按 Enter 或點選提交
第5步:檢視輸出
標註結果以 JSONL 格式儲存:
json
{
"id": "1",
"text": "Apple Inc. announced that CEO Tim Cook will visit Paris next Tuesday.",
"annotations": {
"entities": [
{"start": 0, "end": 10, "label": "ORG", "text": "Apple Inc."},
{"start": 30, "end": 38, "label": "PER", "text": "Tim Cook"},
{"start": 50, "end": 55, "label": "LOC", "text": "Paris"},
{"start": 61, "end": 73, "label": "DATE", "text": "next Tuesday"}
]
}
}更好的 NER 標註技巧
- 一致的指南:清晰的規則減少分歧
- 訓練示例:在標註者開始前展示邊緣案例
- 定期校準:團隊討論困難案例
- 衡量一致性:使用標註者間一致性來識別問題
下一步
- 新增訓練階段以引導標註者
- 設定多標註者以實現冗餘
- 匯出為 Hugging Face 格式用於模型訓練
需要幫助?檢視我們的 span 標註文件獲取更多詳情。