Skip to content

スパンアノテーション

固有表現認識などのためのテキストスパンのハイライトとラベル付け。

スパンアノテーション

スパンアノテーションにより、アノテーターはテキストの一部を選択してラベルを付けることができます。固有表現認識(NER)、品詞タグ付け、テキストハイライトタスクなどに一般的に使用されます。

基本設定

yaml
annotation_schemes:
  - annotation_type: span
    name: entities
    description: "Highlight named entities in the text"
    labels:
      - PERSON
      - ORGANIZATION
      - LOCATION

設定オプション

エンティティラベル

アノテーターが作成できるスパンの種類を定義:

yaml
labels:
  - PERSON
  - ORGANIZATION
  - LOCATION
  - DATE
  - EVENT

ラベルカラー

視覚的な区別のためにカラーをカスタマイズ:

yaml
label_colors:
  PERSON: "#3b82f6"
  ORGANIZATION: "#10b981"
  LOCATION: "#f59e0b"
  DATE: "#8b5cf6"
  EVENT: "#ec4899"

カラーは16進数(#ff0000)またはRGB(rgb(255, 0, 0))で指定できます。

キーボードショートカット

キーボードバインディングでアノテーションを高速化:

yaml
keyboard_shortcuts:
  PERSON: "1"
  ORGANIZATION: "2"
  LOCATION: "3"
  DATE: "4"

ツールチップ

各ラベルのガイダンスを提供:

yaml
tooltips:
  PERSON: "Names of people, characters, or personas"
  ORGANIZATION: "Companies, agencies, institutions"
  LOCATION: "Physical locations, addresses, geographic regions"

重複スパン

重複を許可

重複可能なスパンを有効化:

yaml
- annotation_type: span
  name: entities
  labels:
    - PERSON
    - ROLE
  allow_overlapping: true

これは同じテキストに複数のラベルを付ける場合に便利です(例:「Dr. Smith」はPERSONでありROLEでもある)。

重複を無効化(デフォルト)

yaml
- annotation_type: span
  name: entities
  labels:
    - PERSON
    - ORGANIZATION
  allow_overlapping: false  # Default behavior

スパン選択モード

単語レベル選択

完全な単語のみを選択:

yaml
- annotation_type: span
  name: entities
  selection_mode: word
  labels:
    - ENTITY

文字レベル選択

部分的な単語の選択を許可:

yaml
- annotation_type: span
  name: entities
  selection_mode: character
  labels:
    - ENTITY

事前アノテーションされたスパン

レビューまたは修正のために既存のアノテーションを読み込み:

json
{
  "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"}
  ]
}

事前アノテーションの読み込みを設定:

yaml
- annotation_type: span
  name: entities
  load_pre_annotations: true
  pre_annotation_field: spans

一般的なNER設定

標準NER(4タイプ)

yaml
- annotation_type: span
  name: ner
  description: "Label named entities"
  labels:
    - PER    # Person
    - ORG    # Organization
    - LOC    # Location
    - MISC   # Miscellaneous
  label_colors:
    PER: "#3b82f6"
    ORG: "#10b981"
    LOC: "#f59e0b"
    MISC: "#6b7280"
  keyboard_shortcuts:
    PER: "1"
    ORG: "2"
    LOC: "3"
    MISC: "4"

拡張NER(OntoNotesスタイル)

yaml
- 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

yaml
- annotation_type: span
  name: bio_ner
  labels:
    - GENE
    - PROTEIN
    - DISEASE
    - DRUG
    - SPECIES
  label_colors:
    GENE: "#22c55e"
    PROTEIN: "#3b82f6"
    DISEASE: "#ef4444"
    DRUG: "#f59e0b"
    SPECIES: "#8b5cf6"

ソーシャルメディアNER

yaml
- annotation_type: span
  name: social_ner
  labels:
    - PERSON
    - ORGANIZATION
    - LOCATION
    - PRODUCT
    - CREATIVE_WORK
    - GROUP

属性付きスパン

より豊かなアノテーションのためにスパンに属性を追加:

yaml
annotation_schemes:
  - annotation_type: span
    name: entities
    labels:
      - PERSON
      - ORGANIZATION
 
  - annotation_type: radio
    name: entity_type
    description: "What type of entity is this?"
    show_for_span: entities
    labels:
      - Named
      - Nominal
      - Pronominal

複数のスパンスキーム

異なる側面を別々にアノテーション:

yaml
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
    label_colors:
      POSITIVE: "#22c55e"
      NEGATIVE: "#ef4444"

マルチフィールドスパンアノテーション

v2.1.0の新機能

スパンアノテーションはtarget_fieldオプションを使用して、マルチフィールドデータの特定のテキストフィールドをターゲットにできます。データに複数のテキストフィールドがあり、特定のフィールドのスパンをアノテーションしたい場合に便利です。

設定

yaml
annotation_schemes:
  - annotation_type: span
    name: source_entities
    description: "Label entities in the source text"
    target_field: "source_text"
    labels:
      - PERSON
      - ORGANIZATION
 
  - annotation_type: span
    name: summary_entities
    description: "Label entities in the summary"
    target_field: "summary"
    labels:
      - PERSON
      - ORGANIZATION

マルチフィールドデータ形式

データに個別のテキストフィールドを含める必要があります:

json
{
  "id": "doc1",
  "source_text": "John Smith works at Microsoft in Seattle.",
  "summary": "Smith is employed by Microsoft."
}

出力形式

target_fieldを使用する場合、アノテーションはフィールドごとにキー付けされます:

json
{
  "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/を参照してください。

表示オプション

スパン内にラベルを表示

ハイライトされたスパン内にラベルテキストを表示:

yaml
- annotation_type: span
  name: entities
  show_label_in_span: true

アンダーラインスタイル

背景ハイライトの代わりにアンダーラインを使用:

yaml
- annotation_type: span
  name: entities
  display_style: underline

出力形式

スパンアノテーションは文字オフセットで保存されます:

json
{
  "id": "doc1",
  "entities": [
    {
      "start": 0,
      "end": 10,
      "text": "John Smith",
      "label": "PERSON"
    },
    {
      "start": 20,
      "end": 29,
      "text": "Microsoft",
      "label": "ORGANIZATION"
    }
  ]
}

完全な例:NERタスク

yaml
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
    label_colors:
      PERSON: "#3b82f6"
      ORGANIZATION: "#10b981"
      LOCATION: "#f59e0b"
      DATE: "#8b5cf6"
      MONEY: "#ec4899"
    keyboard_shortcuts:
      PERSON: "1"
      ORGANIZATION: "2"
      LOCATION: "3"
      DATE: "4"
      MONEY: "5"
    tooltips:
      PERSON: "Names of people"
      ORGANIZATION: "Companies, agencies, institutions"
      LOCATION: "Cities, countries, addresses"
      DATE: "Dates and time expressions"
      MONEY: "Monetary values"
    allow_overlapping: false
    selection_mode: word
 
  - annotation_type: radio
    name: difficulty
    description: "How difficult was this document to annotate?"
    labels:
      - Easy
      - Medium
      - Hard

不連続スパン

v2.2.0の新機能

allow_discontinuousパラメータで非連続テキストスパンを有効にします。これにより、アノテーターは複数の非隣接テキストセグメントを単一のスパンアノテーションとして選択できます。不連続エンティティや分割表現に便利です。

yaml
- annotation_type: span
  name: entities
  labels:
    - PERSON
    - ORGANIZATION
  allow_discontinuous: true

有効にすると、アノテーターは修飾キーを押しながら追加のテキストセグメントを選択して現在のスパンに追加できます。出力には各セグメントの複数のstart/endペアが含まれます。

エンティティリンキング統合

v2.2.0の新機能

スパンアノテーションにスパンスキーマにentity_linking設定ブロックを追加することで、外部知識ベース(Wikidata、UMLS、またはカスタムREST API)にリンクできます:

yaml
- annotation_type: span
  name: entities
  labels:
    - PERSON
    - ORGANIZATION
    - LOCATION
  entity_linking:
    enabled: true
    knowledge_bases:
      - name: wikidata
        type: wikidata
        language: en

エンティティリンキングが有効な場合、各スパンのコントロールバーにリンクアイコンが表示されます。クリックすると一致するKBエンティティを検索するモーダルが開きます。詳細はエンティティリンキングのドキュメントを参照してください。

ベストプラクティス

  1. 区別しやすいカラーを使用 - 視覚的な区別を容易にする
  2. 各エンティティタイプに例付きの明確なツールチップを提供
  3. キーボードショートカットを有効化 - より高速なアノテーションのため
  4. 文字精度が不要な場合は単語レベル選択を使用
  5. 事前アノテーションを検討 - 修正ワークフローの高速化
  6. アノテーションガイドラインに基づいて重複設定をテスト

関連資料

実装の詳細については、ソースドキュメントを参照してください。