code: def test_encode_entities__with_bilou_entity_roles_and_groups():
      # Instantiate domain and configure the single state featurizer for this domain.
      # Note that there are 2 entity tags here.
      entity_tags = ["city", f"city{ENTITY_LABEL_SEPARATOR}to"]
      domain = Domain(
          intents=[],
          entities=entity_tags,
          slots=[],
          responses={},
          forms={},
          action_names=[],
          data={},
      )
      f = SingleStateFeaturizer()
      f.prepare_for_training(domain, bilou_tagging=True)
  
      # (1) example with both entities
  
      # create message that has been tokenized and where entities have been extracted
      text = "I am flying from London to Paris"
      tokens = [
          Token(text=match.group(), start=match.start())
          for match in re.finditer(r"\S+", text)
      ]
      entities = [
          {
              ENTITY_ATTRIBUTE_TYPE: entity_tags[0],
              ENTITY_ATTRIBUTE_VALUE: "London",
              ENTITY_ATTRIBUTE_START: 17,
              ENTITY_ATTRIBUTE_END: 23,
          },
          {
              ENTITY_ATTRIBUTE_TYPE: entity_tags[1],
              ENTITY_ATTRIBUTE_VALUE: "Paris",
              ENTITY_ATTRIBUTE_START: 27,
              ENTITY_ATTRIBUTE_END: 32,
          },
      ]
      message = Message(
          {TEXT: text, TOKENS_NAMES[TEXT]: tokens, ENTITIES: entities}
      )
  
      # create a lookup table that has seen this message
      precomputations = MessageContainerForCoreFeaturization()
      precomputations.add(message)
  
      # encode!
      encoded = f.encode_entities(
          {TEXT: text, ENTITIES: entities},
          precomputations=precomputations,
          bilou_tagging=True,
      )
      assert sorted(list(encoded.keys())) == sorted([ENTITY_TAGS])
      assert np.all(
          encoded[ENTITY_TAGS][0].features
          == [[0], [0], [0], [0], [4], [0], [8]]
      )
  
      # (2) example with only the "city" entity
  
      # create message that has been tokenized and where entities have been extracted
      text = "I am flying to Saint Petersburg"
      tokens = [
          Token(text=match.group(), start=match.start())
          for match in re.finditer(r"\S+", text)
      ]
      entities = [
          {
              ENTITY_ATTRIBUTE_TYPE: "city",
              ENTITY_ATTRIBUTE_VALUE: "Saint Petersburg",
              ENTITY_ATTRIBUTE_START: 15,
              ENTITY_ATTRIBUTE_END: 31,
          }
      ]
      message = Message(
          {TEXT: text, TOKENS_NAMES[TEXT]: tokens, ENTITIES: entities}
      )
  
      # create a lookup table that has seen this message
      precomputations = MessageContainerForCoreFeaturization()
      precomputations.add(message)
  
      # encode!
      encoded = f.encode_entities(
          {TEXT: text, ENTITIES: entities},
          precomputations=precomputations,
          bilou_tagging=True,
      )
      assert sorted(list(encoded.keys())) == sorted([ENTITY_TAGS])
      assert np.all(
          encoded[ENTITY_TAGS][0].features
          == [[0], [0], [0], [0], [1], [3]]
      )
  
imports: from typing import Text
  import numpy
  import re
  import scipy.sparse
  import pytest
  from rasa.nlu.tokenizers.tokenizer import Token
  from rasa.nlu.constants import TOKENS_NAMES
  from rasa.core.featurizers.precomputation import MessageContainerForCoreFeaturization
  from rasa.core.featurizers.single_state_featurizer import SingleStateFeaturizer
  from rasa.shared.nlu.training_data.features import Features
  from rasa.shared.nlu.training_data.message import Message
  from rasa.shared.nlu.constants import ACTION_TEXT, ACTION_NAME, ENTITIES, TEXT, INTENT, FEATURE_TYPE_SEQUENCE, FEATURE_TYPE_SENTENCE, ENTITY_ATTRIBUTE_TYPE, ENTITY_ATTRIBUTE_VALUE, ENTITY_ATTRIBUTE_START, ENTITY_ATTRIBUTE_END, ENTITY_TAGS
  from rasa.shared.core.domain import Domain
  from rasa.shared.core.slots import TextSlot
  from rasa.shared.core.constants import ACTION_LISTEN_NAME, ACTIVE_LOOP, PREVIOUS_ACTION, SLOTS, ENTITY_LABEL_SEPARATOR, USER
  from rasa.utils.tensorflow.constants import SENTENCE, SEQUENCE
label_desc: Use image node_id 12 for calling a global function with example usage: test_encode_entities__with_bilou_entity_roles_and_groups() without return types