Skip to content

Annotation de spans

Surlignez et étiquetez des spans de texte dans Potato pour la NER, l'extraction de relations et le sentiment. Configurez types de spans, couleurs, spans chevauchants et raccourcis clavier.

L'annotation de spans permet aux annotateurs de sélectionner et d'étiqueter des portions de texte. Elle sert couramment à la reconnaissance d'entités nommées (NER), à l'étiquetage morphosyntaxique et aux tâches de surlignage de texte.

Interface d'annotation de spans avec surlignage d'entitésAnnotation de spans avec étiquettes d'entités colorées dans Potato

Configuration de base

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

Options de configuration

Étiquettes d'entités

Définissez les types de spans que les annotateurs peuvent créer :

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

Couleurs

Personnalisez les couleurs pour une distinction visuelle :

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

Les couleurs peuvent être en hexadécimal (#ff0000) ou en RGB (rgb(255, 0, 0)).

Raccourcis clavier

Accélérez l'annotation avec des raccourcis clavier :

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

Infobulles

Fournissez des consignes pour chaque étiquette :

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

Spans chevauchants

Autoriser le chevauchement

Activez les spans qui peuvent se chevaucher :

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

C'est utile quand un même texte peut porter plusieurs étiquettes (par exemple, « Dr. Smith » est à la fois une PERSON et porte un ROLE).

Désactiver le chevauchement (par défaut)

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

Modes de sélection de span

Sélection au niveau du mot

Sélectionner uniquement des mots entiers :

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

Sélection au niveau du caractère

Autoriser la sélection de portions de mots :

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

Spans pré-annotés

Chargez des annotations existantes pour révision ou correction :

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

Configurez le chargement des pré-annotations :

yaml
- annotation_type: span
  name: entities

Configurations NER courantes

NER standard (4 types)

yaml
- 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 étendue (style 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 biomédicale

yaml
- annotation_type: span
  name: bio_ner
  labels:
    - GENE
    - PROTEIN
    - DISEASE
    - DRUG
    - SPECIES

NER pour réseaux sociaux

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

Spans avec attributs

Ajoutez des attributs aux spans pour une annotation plus riche :

yaml
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

Plusieurs schémas de spans

Annotez séparément différents aspects :

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

Annotation de spans multi-champs

Nouveau en v2.1.0

L'annotation de spans peut cibler des champs de texte précis dans des données multi-champs via l'option target_field. C'est utile quand vos données contiennent plusieurs champs de texte et que vous voulez annoter les spans dans l'un d'eux en particulier.

Configuration

yaml
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

Format des données multi-champs

Vos données doivent inclure les champs de texte séparés :

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

Format de sortie

Avec target_field, les annotations sont indexées par champ :

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

Pour un exemple complet et fonctionnel, voir project-hub/simple_examples/simple-multi-span/ dans le dépôt Potato.

Options d'affichage

Afficher l'étiquette dans le span

Affichez le texte de l'étiquette à l'intérieur des spans surlignés :

yaml
- annotation_type: span
  name: entities

Style souligné

Utilisez des soulignements au lieu d'un surlignage de fond :

yaml
- annotation_type: span
  name: entities

Format de sortie

Les annotations de spans sont enregistrées avec des décalages de caractères :

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

Exemple complet : tâche de NER

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

Spans discontinus

Nouveau en v2.2.0

Activez les spans de texte non contigus avec le paramètre allow_discontinuous. Les annotateurs peuvent alors sélectionner plusieurs segments de texte non adjacents comme une seule annotation de span, ce qui sert pour les entités discontinues ou les expressions scindées.

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

Une fois activé, les annotateurs peuvent maintenir une touche de modification pendant qu'ils sélectionnent des segments de texte supplémentaires pour les ajouter au span courant. La sortie contient plusieurs paires début/fin, une par segment.

Intégration du liage d'entités

Nouveau en v2.2.0

Les annotations de spans peuvent être liées à des bases de connaissances externes (Wikidata, UMLS ou API REST personnalisées) en ajoutant un bloc de configuration entity_linking au schéma de span :

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

Quand le liage d'entités est activé, une icône de lien apparaît dans la barre de contrôle de chaque span. Un clic ouvre une fenêtre de recherche pour trouver et lier les entités correspondantes de la base. Voir la documentation Liage d'entités pour tous les détails.

Bonnes pratiques

  1. Utilisez des couleurs distinctes pour une différenciation visuelle facile
  2. Fournissez des infobulles claires avec des exemples pour chaque type d'entité
  3. Activez les raccourcis clavier pour annoter plus vite
  4. Utilisez la sélection au niveau du mot sauf si une précision au caractère est nécessaire
  5. Envisagez la pré-annotation pour accélérer les flux de correction
  6. Testez les réglages de chevauchement selon vos consignes d'annotation

Pour aller plus loin

Pour les détails d'implémentation, voir la documentation source.