class_docstr: Abstract Labeling Model
class_docstr_tok: ["Abstract","Labeling","Model"]
docstr: Trains the model for a given number of epochs with given data generator.
  
  Data generator must be the subclass of `CorpusGenerator`
  
  Args:
      train_sample_gen: train data generator.
      valid_sample_gen: valid data generator.
      batch_size: Number of samples per gradient update, default to 64.
      epochs: Number of epochs to train the model.
          An epoch is an iteration over the entire `x` and `y` data provided.
      callbacks: List of `tf.keras.callbacks.Callback` instances.
          List of callbacks to apply during training.
          See `tf.keras.callbacks`.
      fit_kwargs: fit_kwargs: additional arguments passed to :meth:`tf.keras.Model.fit`
  
  Returns:
      A :py:class:`tf.keras.callback.History`  object. Its `History.history` attribute is
      a record of training loss values and metrics values
      at successive epochs, as well as validation loss values
      and validation metrics values (if applicable).
docstr_tok: ["Trains","the","model","for","a","given","number","of","epochs","with","given","data","generator",".","Data","generator","must","be","the","subclass","of","`","CorpusGenerator","`","Args",":","train_sample_gen",":","train","data","generator",".","valid_sample_gen",":","valid","data","generator",".","batch_size",":","Number","of","samples","per","gradient","update",",","default","to","64.","epochs",":","Number","of","epochs","to","train","the","model",".","An","epoch","is","an","iteration","over","the","entire","`","x","`","and","`","y","`","data","provided",".","callbacks",":","List","of","`","tf.keras.callbacks.Callback","`","instances",".","List","of","callbacks","to","apply","during","training",".","See","`","tf.keras.callbacks","`",".","fit_kwargs",":","fit_kwargs",":","additional","arguments","passed","to",":","meth",":","`","tf.keras.Model.fit","`","Returns",":","A",":","py",":","class",":","`","tf.keras.callback.History","`","object",".","Its","`","History.history","`","attribute","is","a","record","of","training","loss","values","and","metrics","values","at","successive","epochs",",","as","well","as","validation","loss","values","and","validation","metrics","values","(","if","applicable",")","."]
code: def fit_generator(
      self,
      train_sample_gen: CorpusGenerator,
      valid_sample_gen: CorpusGenerator = None,
      batch_size: int = 64,
      epochs: int = 5,
      callbacks: List["tf.keras.callbacks.Callback"] = None,
      fit_kwargs: Dict = None,
  ) -> "tf.keras.callbacks.History":
      """
      Trains the model for a given number of epochs with given data generator.
  
      Data generator must be the subclass of `CorpusGenerator`
  
      Args:
          train_sample_gen: train data generator.
          valid_sample_gen: valid data generator.
          batch_size: Number of samples per gradient update, default to 64.
          epochs: Number of epochs to train the model.
              An epoch is an iteration over the entire `x` and `y` data provided.
          callbacks: List of `tf.keras.callbacks.Callback` instances.
              List of callbacks to apply during training.
              See `tf.keras.callbacks`.
          fit_kwargs: fit_kwargs: additional arguments passed to :meth:`tf.keras.Model.fit`
  
      Returns:
          A :py:class:`tf.keras.callback.History`  object. Its `History.history` attribute is
          a record of training loss values and metrics values
          at successive epochs, as well as validation loss values
          and validation metrics values (if applicable).
      """
      self.build_model_generator(
          [g for g in [train_sample_gen, valid_sample_gen] if g]
      )
  
      train_set = BatchDataSet(
          train_sample_gen,
          text_processor=self.text_processor,
          label_processor=self.label_processor,
          segment=self.embedding.segment,
          seq_length=self.sequence_length,
          max_position=self.embedding.max_position,
          batch_size=batch_size,
      )
  
      if fit_kwargs is None:
          fit_kwargs = {}
      if valid_sample_gen:
          valid_set = BatchDataSet(
              valid_sample_gen,
              text_processor=self.text_processor,
              label_processor=self.label_processor,
              segment=self.embedding.segment,
              seq_length=self.sequence_length,
              max_position=self.embedding.max_position,
              batch_size=batch_size,
          )
          fit_kwargs["validation_data"] = valid_set.take()
          fit_kwargs["validation_steps"] = len(valid_set)
  
      for x, y in train_set.take(1):
          logger.debug("fit input shape: {}".format(np.array(x).shape))
          logger.debug("fit input shape: {}".format(np.array(y).shape))
      return self.tf_model.fit(
          train_set.take(),
          steps_per_epoch=len(train_set),
          epochs=epochs,
          callbacks=callbacks,
          **fit_kwargs,
      )
  
imports: from abc import ABC
  from typing import List, Dict, Any, Union, Optional
  import numpy
  import tensorflow
  import kashgari
  from kashgari.embeddings import ABCEmbedding, BareEmbedding
  from kashgari.generators import CorpusGenerator, BatchDataSet
  from kashgari.layers import KConditionalRandomField
  from kashgari.logger import logger
  from kashgari.metrics.sequence_labeling import get_entities
  from kashgari.metrics.sequence_labeling import sequence_labeling_report
  from kashgari.processors import SequenceProcessor
  from kashgari.tasks.abs_task_model import ABCTaskModel
  from kashgari.types import TextSamplesVar
label_desc: Use image node_id 7 for calling the ABCLabelingModel obj's underlying member method code with example usage: obj.fit_generator(train_sample_gen, valid_sample_gen, batch_size, epochs, callbacks, fit_kwargs) and returns: self