Skip to content
Questa pagina non è ancora disponibile nella tua lingua. Viene mostrata la versione in inglese.

Spannen-Annotation

Textspannen für Named-Entity-Recognition und mehr hervorheben und beschriften.

Spannen-Annotation

Die Spannen-Annotation ermöglicht es Annotatoren, Textabschnitte auszuwählen und zu beschriften. Sie wird häufig für Named-Entity-Recognition (NER), Part-of-Speech-Tagging und Texthervorhebungsaufgaben verwendet.

Grundkonfiguration

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

Konfigurationsoptionen

Entitätsbeschriftungen

Typen der Spannen definieren, die Annotatoren erstellen können:

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

Beschriftungsfarben

Farben zur visuellen Unterscheidung anpassen:

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

Farben können als Hex (#ff0000) oder RGB (rgb(255, 0, 0)) angegeben werden.

Tastaturkürzel

Annotation mit Tastenbelegungen beschleunigen:

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

Tooltips

Hinweise für jede Beschriftung bereitstellen:

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

Überlappende Spannen

Überlappungen erlauben

Spannen aktivieren, die sich überlappen können:

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

Dies ist nützlich, wenn derselbe Text mehrere Beschriftungen haben kann (z. B. ist „Dr. Schmidt" sowohl eine PERSON als auch eine ROLE).

Überlappungen deaktivieren (Standard)

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

Spannen-Auswahlmodi

Wortebene

Nur vollständige Wörter auswählen:

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

Zeichenebene

Auswahl von Teilwörtern erlauben:

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

Vorannotierte Spannen

Vorhandene Annotationen zur Überprüfung oder Korrektur laden:

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

Zum Laden von Vorannotationen konfigurieren:

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

Häufige NER-Konfigurationen

Standard-NER (4 Typen)

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"

Erweitertes NER (OntoNotes-Stil)

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

Biomedizinisches 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"

Social-Media-NER

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

Spannen mit Attributen

Attribute zu Spannen für reichhaltigere Annotation hinzufügen:

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

Mehrere Spannen-Schemata

Verschiedene Aspekte separat annotieren:

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"

Mehrfeld-Spannen-Annotation

Neu in v2.1.0

Die Spannen-Annotation kann über die Option target_field auf bestimmte Textfelder in Mehrfeld-Daten abzielen. Dies ist nützlich, wenn die Daten mehrere Textfelder enthalten und Spannen in einem bestimmten Feld annotiert werden sollen.

Konfiguration

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

Mehrfeld-Datenformat

Die Daten sollten die separaten Textfelder enthalten:

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

Ausgabeformat

Bei Verwendung von target_field werden Annotationen nach Feld aufgeschlüsselt:

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

Ein vollständiges funktionierendes Beispiel ist unter project-hub/simple_examples/simple-multi-span/ im Potato-Repository verfügbar.

Anzeigeoptionen

Beschriftung in der Spanne anzeigen

Den Beschriftungstext in hervorgehobenen Spannen anzeigen:

yaml
- annotation_type: span
  name: entities
  show_label_in_span: true

Unterstrich-Stil

Unterstreichungen statt Hintergrundhervorhebung verwenden:

yaml
- annotation_type: span
  name: entities
  display_style: underline

Ausgabeformat

Spannen-Annotationen werden mit Zeichenoffsets gespeichert:

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

Vollständiges Beispiel: NER-Aufgabe

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

Diskontinuierliche Spannen

Neu in v2.2.0

Nicht-zusammenhängende Textspannen mit dem Parameter allow_discontinuous aktivieren. Dies ermöglicht Annotatoren, mehrere nicht benachbarte Textsegmente als einzelne Spannen-Annotation auszuwählen – nützlich für diskontinuierliche Entitäten oder geteilte Ausdrücke.

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

Wenn aktiviert, können Annotatoren eine Modifikatortaste gedrückt halten, während sie weitere Textsegmente auswählen, um sie zur aktuellen Spanne hinzuzufügen. Die Ausgabe enthält mehrere Start-/End-Paare für jedes Segment.

Entitätsverknüpfungs-Integration

Neu in v2.2.0

Spannen-Annotationen können durch Hinzufügen eines entity_linking-Konfigurationsblocks zum Spannen-Schema mit externen Wissensdatenbanken (Wikidata, UMLS oder benutzerdefinierte REST-APIs) verknüpft werden:

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

Wenn die Entitätsverknüpfung aktiviert ist, erscheint ein Verknüpfungssymbol in der Steuerleiste jeder Spanne. Durch Klicken öffnet sich ein Such-Modal, um passende KB-Entitäten zu finden und zu verknüpfen. Vollständige Details sind in der Entitätsverknüpfungs-Dokumentation zu finden.

Bewährte Vorgehensweisen

  1. Eindeutige Farben verwenden für einfache visuelle Unterscheidung
  2. Klare Tooltips bereitstellen mit Beispielen für jeden Entitätstyp
  3. Tastaturkürzel aktivieren für schnellere Annotation
  4. Wort-Auswahl verwenden, außer wenn Zeichenpräzision benötigt wird
  5. Vorannotation erwägen für schnellere Korrektur-Workflows
  6. Überlappungseinstellungen testen basierend auf den Annotationsrichtlinien

Weiterführende Lektüre

Implementierungsdetails sind in der Quelldokumentation zu finden.