片段連結
在已標註的文本片段之間建立類型化關係。
v2.1.0 新增
片段連結允許標註者在已標註的片段(文本段)之間建立類型化關係。這對關係抽取任務非常有用,您需要識別實體之間的關係,例如"PERSON works_for ORGANIZATION"或"PERSON collaborates_with PERSON"。
概述
片段連結功能提供:
- 類型化關係:定義具有不同顏色和約束的多種連結類型
- 有向和無向連結:支援方向性和對稱關係
- N 元連結:在多個片段之間建立連結(不僅限於成對)
- 視覺化弧形顯示:以彩色弧線渲染在文本上方的關係
- 標籤約束:限制哪些片段標籤可以作為源或目標
配置
要使用片段連結,您需要兩個標註方案:
- 一個
span方案用於標註實體 - 一個
span_link方案用於標註關係
yaml
annotation_schemes:
# First, define the span schema for named entities
- annotation_type: span
name: entities
description: "Highlight named entities"
labels:
- name: "PERSON"
color: "#3b82f6"
- name: "ORGANIZATION"
color: "#22c55e"
- name: "LOCATION"
color: "#f59e0b"
sequential_key_binding: true
# Then, define the span_link schema for relationships
- annotation_type: span_link
name: relations
description: "Annotate relationships between entities"
span_schema: entities # References the span schema above
link_types:
- name: "WORKS_FOR"
directed: true
allowed_source_labels: ["PERSON"]
allowed_target_labels: ["ORGANIZATION"]
color: "#dc2626"
- name: "COLLABORATES_WITH"
directed: false
allowed_source_labels: ["PERSON"]
allowed_target_labels: ["PERSON"]
color: "#06b6d4"配置選項
必填欄位
| 欄位 | 描述 |
|---|---|
annotation_type | 必須為 "span_link" |
name | 方案的唯一識別符號 |
description | 顯示給標註者的描述 |
span_schema | 要連結的片段標註方案名稱 |
link_types | 連結類型定義陣列 |
連結類型選項
| 欄位 | 類型 | 描述 |
|---|---|---|
name | string | 必填。 連結類型的名稱/標籤 |
directed | boolean | 連結是否有方向。預設:false |
color | string | 連結的十六進位制顏色程式碼 |
allowed_source_labels | array | 可以作為源的片段標籤 |
allowed_target_labels | array | 可以作為目標的片段標籤 |
max_spans | integer | 此連結類型中的最大片段數(用於 N 元連結) |
視覺顯示選項
yaml
visual_display:
enabled: true # Show arc visualization
arc_position: "above" # Position of arcs
show_labels: true # Show link type labels on arcs使用方法
建立片段
- 首先,通過選擇片段標籤並高亮文本來標註文本
- 每個高亮的片段都可用於連結
建立連結
- 從可用選項中選擇連結類型
- 點選片段將其新增到當前連結(選中的片段會高亮顯示)
- 點選"建立連結"完成連結
- 對於有向連結,第一個選中的片段是源,最後一個是目標
檢視連結
- 已建立的連結出現在"已有連結"部分
- 如果啟用了視覺顯示,弧線會在文本上方連線連結的片段
- 弧線按連結類型進行顏色編碼
刪除連結
- 點選"已有連結"部分中任何連結旁邊的刪除按鈕(x)
資料格式
輸入資料
帶有 ID 和文本欄位的標準文本資料:
json
[
{
"id": "item_1",
"text": "John Smith works at Google as a senior engineer."
}
]輸出格式
標註包括片段標註和連結標註:
json
{
"id": "item_1",
"text": "John Smith works at Google as a senior engineer.",
"entities": [
{"start": 0, "end": 10, "label": "PERSON", "text": "John Smith"},
{"start": 20, "end": 26, "label": "ORGANIZATION", "text": "Google"}
],
"relations": [
{
"link_type": "WORKS_FOR",
"span_ids": ["span_abc123", "span_def456"],
"direction": "directed"
}
]
}標籤約束
限制哪些片段標籤可以參與每種連結類型:
yaml
link_types:
- name: "WORKS_FOR"
directed: true
allowed_source_labels: ["PERSON"] # Only PERSON can be source
allowed_target_labels: ["ORGANIZATION"] # Only ORGANIZATION can be target當違反約束時,UI 會顯示錯誤訊息並阻止建立連結。
N 元連結
預設情況下,連結連線恰好 2 個片段。對於涉及更多實體的關係:
yaml
link_types:
- name: "MEETING"
directed: false
max_spans: 5 # Allow up to 5 participants
allowed_source_labels: ["PERSON"]
allowed_target_labels: ["PERSON"]示例
完整的工作示例位於:
- 配置:
project-hub/simple_examples/simple-span-linking/config.yaml - 資料:
project-hub/simple_examples/simple-span-linking/data.json
執行命令:
bash
cd project-hub/simple_examples
python ../../potato/flask_server.py start simple-span-linking/config.yaml -p 9001提示
- 先標註片段:確保在嘗試連結之前已建立片段標註
- 有效使用顏色:為不同的連結類型選擇獨特的顏色
- 考慮方向:當關繫有明確方向時使用有向連結
- 鍵盤快捷鍵:片段標籤支援鍵盤快捷鍵(1、2、3...)以加快標註
延伸閱讀
有關實現細節,請參閱源文件。