class_docstr: Implements conditional random fields (CRF) to do named entity recognition.
class_docstr_tok: ["Implements","conditional","random","fields","(","CRF",")","to","do","named","entity","recognition","."]
docstr: Take a message and convert it to crfsuite format.
docstr_tok: ["Take","a","message","and","convert","it","to","crfsuite","format","."]
code: def _convert_to_crf_tokens(self, message: Message) -> List[CRFToken]:
      """Take a message and convert it to crfsuite format."""
      crf_format = []
      tokens = message.get(TOKENS_NAMES[TEXT])
  
      text_dense_features = self._get_dense_features(message)
      tags = self._get_tags(message)
  
      for i, token in enumerate(tokens):
          pattern = self._pattern_of_token(message, i)
          entity = self.get_tag_for(tags, ENTITY_ATTRIBUTE_TYPE, i)
          group = self.get_tag_for(tags, ENTITY_ATTRIBUTE_GROUP, i)
          role = self.get_tag_for(tags, ENTITY_ATTRIBUTE_ROLE, i)
          pos_tag = token.get(POS_TAG_KEY)
          dense_features = (
              text_dense_features[i]
              if text_dense_features is not None
              else []
          )
  
          crf_format.append(
              CRFToken(
                  text=token.text,
                  pos_tag=pos_tag,
                  entity_tag=entity,
                  entity_group_tag=group,
                  entity_role_tag=role,
                  pattern=pattern,
                  dense_features=dense_features,
              )
          )
  
      return crf_format
  
imports: from __future__ import annotations
  from collections import OrderedDict
  from enum import Enum
  import logging
  import typing
  import numpy
  from typing import Any, Dict, List, Optional, Text, Tuple, Callable, Type
  import rasa.nlu.utils.bilou_utils
  import rasa.shared.utils.io
  import rasa.utils.train_utils
  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.test import determine_token_labels
  from rasa.nlu.tokenizers.spacy_tokenizer import POS_TAG_KEY
  from rasa.nlu.extractors.extractor import EntityExtractorMixin
  from rasa.nlu.tokenizers.tokenizer import Token, Tokenizer
  from rasa.shared.nlu.training_data.training_data import TrainingData
  from rasa.shared.nlu.training_data.message import Message
  from rasa.nlu.constants import TOKENS_NAMES
  from rasa.shared.nlu.constants import TEXT, ENTITIES, ENTITY_ATTRIBUTE_TYPE, ENTITY_ATTRIBUTE_GROUP, ENTITY_ATTRIBUTE_ROLE, NO_ENTITY_TAG, SPLIT_ENTITIES_BY_COMMA, SPLIT_ENTITIES_BY_COMMA_DEFAULT_VALUE
  from rasa.shared.constants import DOCS_URL_COMPONENTS
  from rasa.utils.tensorflow.constants import BILOU_FLAG, FEATURIZERS
label_desc: Use image node_id 22 for calling the CRFEntityExtractor obj's underlying member method code with example usage: obj._convert_to_crf_tokens(message) and returns: crf_format