實體連結
將片段標註連結到外部知識庫,如Wikidata、UMLS或自定義API。
實體連結使標註者能夠將片段標註連線到外部知識庫(KB),如 Wikidata 或 UMLS。這在文本提及和規範實體之間建立語義連結,對命名實體識別、概念規範化和知識圖譜構建非常有價值。
工作原理
當為片段標註方案啟用實體連結時:
- 標註者高亮文本並分配標籤(例如 "PERSON"、"ORGANIZATION")
- 片段控制欄上出現連結圖示
- 點選圖示開啟搜尋模態框以查詢匹配的知識庫實體
- 所選實體 ID 與片段標註一起儲存
- 已連結的片段顯示填充圖示,並在懸停時顯示實體詳情
快速入門
通過向片段方案新增 entity_linking 配置來啟用實體連結:
yaml
annotation_schemes:
- annotation_type: span
name: ner
description: Named Entity Recognition with KB linking
labels:
- name: PERSON
tooltip: "People's names"
- name: ORGANIZATION
tooltip: "Companies, agencies, institutions"
- name: LOCATION
tooltip: "Places, cities, countries"
entity_linking:
enabled: true
knowledge_bases:
- name: wikidata
type: wikidata
language: en配置選項
| 選項 | 類型 | 預設值 | 描述 |
|---|---|---|---|
enabled | boolean | false | 為此方案啟用實體連結 |
knowledge_bases | list | [] | 知識庫配置列表 |
auto_search | boolean | true | 開啟模態框時自動搜尋 |
required | boolean | false | 儲存片段前要求實體連結 |
multi_select | boolean | false | 允許連結到多個實體 |
知識庫配置
| 選項 | 類型 | 預設值 | 描述 |
|---|---|---|---|
name | string | 必填 | 此知識庫的唯一識別符號 |
type | string | 必填 | 知識庫類型:wikidata、umls 或 rest |
api_key | string | null | 需要認證的服務的 API 金鑰 |
base_url | string | null | REST API 的基礎 URL |
language | string | "en" | 搜尋結果的語言程式碼 |
timeout | integer | 10 | 請求超時時間(秒) |
支援的知識庫
Wikidata
免費、開放的知識庫,擁有超過 1 億個實體。無需 API 金鑰。
yaml
entity_linking:
enabled: true
knowledge_bases:
- name: wikidata
type: wikidata
language: en支援多語言標籤、實體別名(例如 "NYC" 可找到 "New York City")以及 Wikipedia 文章連結。
UMLS
全面的醫學和生物醫學術語庫。需要從 UTS 獲取免費的 API 金鑰。
yaml
entity_linking:
enabled: true
knowledge_bases:
- name: umls
type: umls
api_key: ${UMLS_API_KEY}包含醫學概念、藥物、疾病、手術,以及對 200 多個源詞彙表(SNOMED CT、ICD-10、MeSH、RxNorm)的交叉引用。
自定義 REST API
連線到任何具有 REST API 的知識庫:
yaml
entity_linking:
enabled: true
knowledge_bases:
- name: internal_kb
type: rest
base_url: https://api.example.com
api_key: optional_api_key
extra_params:
search_endpoint: /search
entity_endpoint: /entity/{entity_id}
search_query_param: q
results_path: data.results
entity_id_field: id
label_field: name
description_field: description多知識庫
配置多個知識庫,讓標註者選擇最合適的來源:
yaml
entity_linking:
enabled: true
knowledge_bases:
- name: wikidata
type: wikidata
language: en
- name: umls
type: umls
api_key: ${UMLS_API_KEY}
- name: company_entities
type: rest
base_url: https://internal.company.com/api/entities搜尋模態框中的下拉選單允許標註者在配置的知識庫之間切換。
多選模式
啟用多選以允許將片段連結到多個實體,對歧義提及很有用:
yaml
entity_linking:
enabled: true
multi_select: true
knowledge_bases:
- name: wikidata
type: wikidata
language: en資料格式
實體連結的片段在輸出中包含額外欄位:
json
{
"id": "instance_001",
"text": "Albert Einstein was born in Ulm, Germany in 1879.",
"annotations": {
"ner": {
"spans": [
{
"text": "Albert Einstein",
"start": 0,
"end": 15,
"label": "PERSON",
"kb_id": "Q937",
"kb_source": "wikidata",
"kb_label": "Albert Einstein"
},
{
"text": "Ulm",
"start": 28,
"end": 31,
"label": "LOCATION",
"kb_id": "Q3012",
"kb_source": "wikidata",
"kb_label": "Ulm"
}
]
}
}
}最佳實踐
- 啟用自動搜尋以提高效率 - 用片段文本預填充搜尋
- 除非必要,不要求求連結 - 找不到實體時不要阻止標註
- 為慢速網路設定適當的超時時間
- 將知識庫與實體類型匹配 - 通用實體使用 Wikidata,生物醫學術語使用 UMLS,領域特定實體使用自定義 API
- 為歧義提及使用多選 - 縮寫、常見名稱、多義詞
延伸閱讀
有關實現細節,請參閱源文件。