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: Train the crf tagger based on the training data.
docstr_tok: ["Train","the","crf","tagger","based","on","the","training","data","."]
code: def _train_model(self, df_train: List[List[CRFToken]]) -> None:
      """Train the crf tagger based on the training data."""
      import sklearn_crfsuite
  
      self.entity_taggers = OrderedDict()
  
      for tag_name in self.crf_order:
          logger.debug(f"Training CRF for '{tag_name}'.")
  
          # add entity tag features for second level CRFs
          include_tag_features = tag_name != ENTITY_ATTRIBUTE_TYPE
          X_train = (
              self._crf_tokens_to_features(
                  sentence, include_tag_features
              )
              for sentence in df_train
          )
          y_train = (
              self._crf_tokens_to_tags(sentence, tag_name)
              for sentence in df_train
          )
  
          entity_tagger = sklearn_crfsuite.CRF(
              algorithm="lbfgs",
              # coefficient for L1 penalty
              c1=self.component_config["L1_c"],
              # coefficient for L2 penalty
              c2=self.component_config["L2_c"],
              # stop earlier
              max_iterations=self.component_config["max_iterations"],
              # include transitions that are possible, but not observed
              all_possible_transitions=True,
          )
          entity_tagger.fit(X_train, y_train)
  
          self.entity_taggers[tag_name] = entity_tagger
  
          logger.debug("Training finished.")
  
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 24 for calling the CRFEntityExtractor obj's underlying member method code with example usage: obj._train_model(df_train) without return types