Skip to content

Anotación de Segmentos

Resalta y etiqueta segmentos de texto para reconocimiento de entidades nombradas y más.

Anotación de Segmentos

La anotación de segmentos permite a los anotadores seleccionar y etiquetar porciones de texto, comúnmente usada para reconocimiento de entidades nombradas (NER), etiquetado de partes del discurso y tareas de resaltado de texto.

Configuración Básica

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

Opciones de Configuración

Etiquetas de Entidad

Define los tipos de segmentos que los anotadores pueden crear:

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

Colores de Etiquetas

Personaliza colores para distinción visual:

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

Los colores pueden ser hex (#ff0000) o RGB (rgb(255, 0, 0)).

Atajos de Teclado

Acelera la anotación con asignaciones de teclado:

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

Tooltips

Proporciona guía para cada etiqueta:

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

Segmentos Superpuestos

Permitir Superposición

Habilita segmentos que pueden superponerse:

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

Esto es útil cuando el mismo texto puede tener múltiples etiquetas (por ejemplo, "Dr. Smith" es tanto PERSON como tiene un ROLE).

Deshabilitar Superposición (Predeterminado)

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

Modos de Selección de Segmentos

Selección a Nivel de Palabra

Selecciona solo palabras completas:

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

Selección a Nivel de Carácter

Permite selección de partes de palabras:

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

Segmentos Pre-Anotados

Carga anotaciones existentes para revisión o corrección:

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

Configura para cargar pre-anotaciones:

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

Configuraciones NER Comunes

NER Estándar (4 Tipos)

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 Extendido (Estilo 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édico

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 de Redes Sociales

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

Segmentos con Atributos

Añade atributos a los segmentos para una anotación más rica:

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

Múltiples Esquemas de Segmentos

Anota diferentes aspectos por separado:

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"

Anotación de Segmentos Multi-Campo

Nuevo en v2.1.0

La anotación de segmentos puede apuntar a campos de texto específicos en datos multi-campo usando la opción target_field. Esto es útil cuando tus datos contienen múltiples campos de texto y quieres anotar segmentos en uno en particular.

Configuración

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

Formato de Datos Multi-Campo

Tus datos deben incluir los campos de texto separados:

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

Formato de Salida

Cuando se usa target_field, las anotaciones se indexan por campo:

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

Para un ejemplo funcional completo, consulta project-hub/simple_examples/simple-multi-span/ en el repositorio de Potato.

Opciones de Visualización

Mostrar Etiqueta en el Segmento

Muestra el texto de la etiqueta dentro de los segmentos resaltados:

yaml
- annotation_type: span
  name: entities
  show_label_in_span: true

Estilo Subrayado

Usa subrayados en lugar de resaltado de fondo:

yaml
- annotation_type: span
  name: entities
  display_style: underline

Formato de Salida

Las anotaciones de segmentos se guardan con desplazamientos de caracteres:

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

Ejemplo Completo: Tarea 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

Segmentos Discontinuos

Nuevo en v2.2.0

Habilita segmentos de texto no contiguos con el parámetro allow_discontinuous. Esto permite a los anotadores seleccionar múltiples segmentos de texto no adyacentes como una sola anotación de segmento, útil para entidades discontinuas o expresiones divididas.

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

Cuando está habilitado, los anotadores pueden mantener presionada una tecla modificadora mientras seleccionan segmentos de texto adicionales para añadirlos al segmento actual. La salida incluye múltiples pares inicio/fin para cada segmento.

Integración de Vinculación de Entidades

Nuevo en v2.2.0

Las anotaciones de segmentos se pueden vincular a bases de conocimiento externas (Wikidata, UMLS o APIs REST personalizadas) añadiendo un bloque de configuración entity_linking al esquema de segmentos:

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

Cuando la vinculación de entidades está habilitada, aparece un icono de enlace en la barra de control de cada segmento. Al hacer clic se abre un modal de búsqueda para encontrar y vincular entidades KB coincidentes. Consulta la documentación de Vinculación de Entidades para detalles completos.

Mejores Prácticas

  1. Usar colores distintos para fácil diferenciación visual
  2. Proporcionar tooltips claros con ejemplos para cada tipo de entidad
  3. Habilitar atajos de teclado para una anotación más rápida
  4. Usar selección a nivel de palabra a menos que se necesite precisión a nivel de carácter
  5. Considerar pre-anotación para flujos de trabajo de corrección más rápidos
  6. Probar configuraciones de superposición según tus directrices de anotación

Lectura Adicional

Para detalles de implementación, consulta la documentación fuente.