片段標註
高亮並標記文本片段,用於命名實體識別等任務。
片段標註允許標註者選擇並標記文本的一部分,常用於命名實體識別(NER)、詞性標註和文本高亮任務。
基本配置
annotation_schemes:
- annotation_type: span
name: entities
description: "Highlight named entities in the text"
labels:
- PERSON
- ORGANIZATION
- LOCATION配置選項
實體標籤
定義標註者可以建立的片段類型:
labels:
- PERSON
- ORGANIZATION
- LOCATION
- DATE
- EVENT標籤顏色
自定義顏色以進行視覺區分:
label_colors:
PERSON: "#3b82f6"
ORGANIZATION: "#10b981"
LOCATION: "#f59e0b"
DATE: "#8b5cf6"
EVENT: "#ec4899"顏色可以是十六進位制格式(#ff0000)或 RGB 格式(rgb(255, 0, 0))。
鍵盤快捷鍵
通過鍵盤繫結加速標註:
keyboard_shortcuts:
PERSON: "1"
ORGANIZATION: "2"
LOCATION: "3"
DATE: "4"工具提示
為每個標籤提供指導:
tooltips:
PERSON: "Names of people, characters, or personas"
ORGANIZATION: "Companies, agencies, institutions"
LOCATION: "Physical locations, addresses, geographic regions"重疊片段
允許重疊
啟用可以重疊的片段:
- annotation_type: span
name: entities
labels:
- PERSON
- ROLE
allow_discontinuous: true當同一文本可以有多個標籤時(例如 "Dr. Smith" 既是 PERSON 又有 ROLE),這很有用。
禁止重疊(預設)
- annotation_type: span
name: entities
labels:
- PERSON
- ORGANIZATION
allow_discontinuous: false # Default behavior片段選擇模式
詞級選擇
僅選擇完整的詞:
- annotation_type: span
name: entities
labels:
- ENTITY字元級選擇
允許選擇部分詞:
- annotation_type: span
name: entities
labels:
- ENTITY預標註片段
載入現有標註用於稽核或修正:
{
"id": "doc1",
"text": "John Smith works at Microsoft in Seattle.",
"spans": [
{"start": 0, "end": 10, "label": "PERSON"},
{"start": 20, "end": 29, "label": "ORGANIZATION"},
{"start": 33, "end": 40, "label": "LOCATION"}
]
}配置載入預標註:
- annotation_type: span
name: entities常見 NER 配置
標準 NER(4 種類型)
- annotation_type: span
name: ner
description: "Label named entities"
labels:
- PER # Person
- ORG # Organization
- LOC # Location
- MISC # Miscellaneous
sequential_key_binding:
PER: "1"
ORG: "2"
LOC: "3"
MISC: "4"擴充套件 NER(OntoNotes 風格)
- annotation_type: span
name: ner_extended
labels:
- PERSON
- NORP # Nationalities, religious/political groups
- FAC # Facilities
- ORG
- GPE # Geopolitical entities
- LOC
- PRODUCT
- EVENT
- WORK_OF_ART
- LAW
- LANGUAGE
- DATE
- TIME
- PERCENT
- MONEY
- QUANTITY
- ORDINAL
- CARDINAL生物醫學 NER
- annotation_type: span
name: bio_ner
labels:
- GENE
- PROTEIN
- DISEASE
- DRUG
- SPECIES社交媒體 NER
- annotation_type: span
name: social_ner
labels:
- PERSON
- ORGANIZATION
- LOCATION
- PRODUCT
- CREATIVE_WORK
- GROUP帶屬性的片段
為片段新增屬性以進行更豐富的標註:
annotation_schemes:
- annotation_type: span
name: entities
labels:
- PERSON
- ORGANIZATION
- annotation_type: radio
name: entity_type
description: "What type of entity is this?"
labels:
- Named
- Nominal
- Pronominal多片段方案
分別標註不同方面:
annotation_schemes:
# Named entities
- annotation_type: span
name: entities
description: "Label named entities"
labels:
- PERSON
- ORGANIZATION
- LOCATION
# Sentiment expressions
- annotation_type: span
name: sentiment_spans
description: "Highlight sentiment expressions"
labels:
- POSITIVE
- NEGATIVE多欄位片段標註
v2.1.0 新增
片段標註可以使用 target_field 選項定位多欄位資料中的特定文本欄位。當您的資料包含多個文本欄位並且您想在特定欄位中標註片段時,這非常有用。
配置
annotation_schemes:
- annotation_type: span
name: source_entities
description: "Label entities in the source text"
labels:
- PERSON
- ORGANIZATION
- annotation_type: span
name: summary_entities
description: "Label entities in the summary"
labels:
- PERSON
- ORGANIZATION多欄位資料格式
您的資料應包含單獨的文本欄位:
{
"id": "doc1",
"source_text": "John Smith works at Microsoft in Seattle.",
"summary": "Smith is employed by Microsoft."
}輸出格式
使用 target_field 時,標註按欄位鍵組織:
{
"id": "doc1",
"source_entities": {
"source_text": [
{"start": 0, "end": 10, "text": "John Smith", "label": "PERSON"},
{"start": 20, "end": 29, "text": "Microsoft", "label": "ORGANIZATION"}
]
},
"summary_entities": {
"summary": [
{"start": 0, "end": 5, "text": "Smith", "label": "PERSON"},
{"start": 22, "end": 31, "text": "Microsoft", "label": "ORGANIZATION"}
]
}
}完整的工作示例請參見 Potato 倉庫中的 project-hub/simple_examples/simple-multi-span/。
顯示選項
在片段中顯示標籤
在高亮片段內顯示標籤文本:
- annotation_type: span
name: entities下劃線樣式
使用下劃線代替背景高亮:
- annotation_type: span
name: entities輸出格式
片段標註以字元偏移量儲存:
{
"id": "doc1",
"entities": [
{
"start": 0,
"end": 10,
"text": "John Smith",
"label": "PERSON"
},
{
"start": 20,
"end": 29,
"text": "Microsoft",
"label": "ORGANIZATION"
}
]
}完整示例:NER 任務
task_name: "Named Entity Recognition"
data_files:
- path: data/documents.json
text_field: text
annotation_schemes:
- annotation_type: span
name: entities
description: "Highlight and label all named entities"
labels:
- PERSON
- ORGANIZATION
- LOCATION
- DATE
- MONEY
sequential_key_binding:
PERSON: "1"
ORGANIZATION: "2"
LOCATION: "3"
DATE: "4"
MONEY: "5"
allow_discontinuous: false
- annotation_type: radio
name: difficulty
description: "How difficult was this document to annotate?"
labels:
- Easy
- Medium
- Hard不連續片段
v2.2.0 新增
使用 allow_discontinuous 參數啟用不連續文本片段。這允許標註者選擇多個不相鄰的文本段作為單個片段標註,適用於不連續實體或分割表達。
- annotation_type: span
name: entities
labels:
- PERSON
- ORGANIZATION
allow_discontinuous: true啟用後,標註者可以按住修飾鍵同時選擇額外的文本段以將其新增到當前片段。輸出包含每個段的多個起始/結束對。
實體連結整合
v2.2.0 新增
通過向片段方案新增 entity_linking 配置塊,可以將片段標註連結到外部知識庫(Wikidata、UMLS 或自定義 REST API):
- annotation_type: span
name: entities
labels:
- PERSON
- ORGANIZATION
- LOCATION
entity_linking:
enabled: true
knowledge_bases:
- name: wikidata
type: wikidata
language: en啟用實體連結後,每個片段的控制欄上會出現連結圖示。點選它會開啟搜尋模態框以查詢和連結匹配的知識庫實體。詳情請參閱實體連結文件。
最佳實踐
- 使用獨特的顏色以便於視覺區分
- 為每種實體類型提供清晰的工具提示和示例
- 啟用鍵盤快捷鍵以加快標註速度
- 使用詞級選擇除非需要字元精度
- 考慮預標註以加快修正工作流程
- 根據標註指南測試重疊設定
延伸閱讀
- 實體連結 - 將片段連結到知識庫
- 共指鏈 - 分組共指提及
- 事件標註 - 帶片段參數的 N 元事件結構
- 片段連結 - 在片段之間建立關係
- 實例顯示 - 帶片段目標的多欄位內容顯示
- UI 配置 - 自定義片段顏色
- 生產力功能 - 鍵盤快捷鍵
有關實現細節,請參閱源文件。