class_docstr: A Mitie Entity Extractor (which is a thin wrapper around `Dlib-ml`).
class_docstr_tok: ["A","Mitie","Entity","Extractor","(","which","is","a","thin","wrapper","around","`","Dlib-ml","`",")","."]
docstr: Prepare a message so that it can be passed to a MITIE trainer.
docstr_tok: ["Prepare","a","message","so","that","it","can","be","passed","to","a","MITIE","trainer","."]
code: def _prepare_mitie_sample(training_example: Message) -> Any:
      """Prepare a message so that it can be passed to a MITIE trainer."""
      import mitie
  
      text = training_example.get(TEXT)
      tokens = training_example.get(TOKENS_NAMES[TEXT])
      sample = mitie.ner_training_instance([t.text for t in tokens])
      for ent in training_example.get(ENTITIES, []):
          try:
              # if the token is not aligned an exception will be raised
              start, end = MitieEntityExtractor.find_entity(
                  ent, text, tokens
              )
          except ValueError as e:
              rasa.shared.utils.io.raise_warning(
                  f"Failed to use example '{text}' to train MITIE "
                  f"entity extractor. Example will be skipped."
                  f"Error: {e}"
              )
              continue
          try:
              # mitie will raise an exception on malicious
              # input - e.g. on overlapping entities
              sample.add_entity(list(range(start, end)), ent["entity"])
          except Exception as e:
              rasa.shared.utils.io.raise_warning(
                  f"Failed to add entity example "
                  f"'{e!s}' of sentence '{text!s}'. "
                  f"Example will be ignored. Reason: "
                  f"{e}"
              )
              continue
      return sample
  
imports: from __future__ import annotations
  import logging
  from rasa.nlu.tokenizers.tokenizer import Tokenizer
  import typing
  from typing import Any, Dict, List, Optional, Text, Type
  from rasa.engine.graph import GraphComponent, ExecutionContext
  from rasa.engine.recipes.default_recipe import DefaultV1Recipe
  from rasa.engine.storage.resource import Resource
  from rasa.engine.storage.storage import ModelStorage
  from rasa.nlu.constants import TOKENS_NAMES
  from rasa.shared.nlu.constants import ENTITY_ATTRIBUTE_CONFIDENCE, ENTITY_ATTRIBUTE_START, ENTITY_ATTRIBUTE_END, ENTITY_ATTRIBUTE_TYPE, ENTITY_ATTRIBUTE_VALUE, TEXT, ENTITIES
  from rasa.nlu.utils.mitie_utils import MitieModel, MitieNLP
  from rasa.nlu.extractors.extractor import EntityExtractorMixin
  from rasa.shared.nlu.training_data.training_data import TrainingData
  from rasa.shared.nlu.training_data.message import Message
  import rasa.shared.utils.io
  from rasa.shared.exceptions import InvalidConfigException
label_desc: Use image node_id 8 for calling the MitieEntityExtractor obj's underlying member method code with example usage: obj._prepare_mitie_sample(training_example) and returns: sample