class_docstr: Abstract Classification Model
class_docstr_tok: ["Abstract","Classification","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["keras.callbacks.Callback"] = None,
      fit_kwargs: Dict = None,
  ) -> "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]
      )
  
      model_summary = []
      self.tf_model.summary(print_fn=lambda x: model_summary.append(x))
      logger.debug("\n".join(model_summary))
  
      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,
          batch_size=batch_size,
      )
  
      if fit_kwargs is None:
          fit_kwargs = {}
  
      if valid_sample_gen:
          valid_gen = BatchDataSet(
              valid_sample_gen,
              text_processor=self.text_processor,
              label_processor=self.label_processor,
              segment=self.embedding.segment,
              seq_length=self.sequence_length,
              batch_size=batch_size,
          )
          fit_kwargs["validation_data"] = valid_gen.take()
          fit_kwargs["validation_steps"] = len(valid_gen)
  
      return self.tf_model.fit(
          train_set.take(),
          steps_per_epoch=len(train_set),
          epochs=epochs,
          callbacks=callbacks,
          **fit_kwargs,
      )
  
imports: import random
  from abc import ABC
  import numpy
  from typing import List, Dict, Any, Union
  from sklearn import metrics
  from tensorflow import keras
  import kashgari
  from kashgari.embeddings import ABCEmbedding, BareEmbedding
  from kashgari.generators import BatchDataSet, CorpusGenerator
  from kashgari.layers import L
  from kashgari.logger import logger
  from kashgari.metrics.multi_label_classification import multi_label_classification_report
  from kashgari.processors import ABCProcessor
  from kashgari.processors import ClassificationProcessor
  from kashgari.processors import SequenceProcessor
  from kashgari.tasks.abs_task_model import ABCTaskModel
  from kashgari.types import TextSamplesVar, ClassificationLabelVar, MultiLabelClassificationLabelVar
label_desc: Use image node_id 9 for calling the ABCClassificationModel obj's underlying member method code with example usage: obj.fit_generator(train_sample_gen, valid_sample_gen) and returns: self