class_docstr: Labels each token in a sequence as belonging to 1 of N token classes.
  
  :param config: A :py:class:`finetune.config.Settings` object or None (for default config).
  :param \**kwargs: key-value pairs of config items to override.
class_docstr_tok: ["Labels","each","token","in","a","sequence","as","belonging","to","1","of","N","token","classes",".",":","param","config",":","A",":","py",":","class",":","`","finetune.config.Settings","`","object","or","None","(","for","default","config",")",".",":","param","\\","*","*","kwargs",":","key-value","pairs","of","config","items","to","override","."]
docstr: Fit a sequence labeling model
  
  If X_partial and Y_partial are provided, treat those as partial data and
  Xs and Y as fully annotated data. We only perform auto negative sampling on
  fully annotated data.
docstr_tok: ["Fit","a","sequence","labeling","model","If","X_partial","and","Y_partial","are","provided",",","treat","those","as","partial","data","and","Xs","and","Y","as","fully","annotated","data",".","We","only","perform","auto","negative","sampling","on","fully","annotated","data","."]
code: def finetune(
      self,
      Xs,
      Y=None,
      context=None,
      update_hook=None,
      log_hooks=None,
      X_partial=None,
      Y_partial=None,
  ):
      """
      Fit a sequence labeling model
  
      If X_partial and Y_partial are provided, treat those as partial data and
      Xs and Y as fully annotated data. We only perform auto negative sampling on
      fully annotated data.
      """
      if (
          self.config.chunk_long_sequences
          and self.config.auto_negative_sampling
          and Y is not None
      ):
          # clear the saver to save memory.
          self.saver.fallback  # retrieve the fallback future.
          self.saver = None
          model_copy = copy.deepcopy(self)
          if model_copy.config.tensorboard_folder:
              model_copy.config.tensorboard_folder = os.path.join(
                  model_copy.config.tensorboard_folder, "ans_run"
              )
          model_copy._initialize()
          model_copy.input_pipeline.total_epoch_offset = (
              self.config.n_epochs
          )
          self.input_pipeline.current_epoch_offset = (
              self.config.n_epochs
          )
          self.input_pipeline.total_epoch_offset = self.config.n_epochs
  
          # Train model with only positive chunks
          model_copy.config.max_empty_chunk_ratio = 0.0
          model_copy.config.auto_negative_sampling = False
          # Cannot have anything that changes pred format here.
          model_copy.config.predict_chunk_markers = False
          model_copy.finetune(
              Xs, Y=Y, context=context, update_hook=update_hook
          )
          initial_run_preds = []
  
          # Heuristic to select batch size for prediction to limit memory consumption.
          # Aim is to give us the smallest batch size that will give us full batches.
          approx_max_tokens_per_doc = max(len(x) for x in Xs) / 5
          approx_chunks_per_doc = approx_max_tokens_per_doc / (
              self.config.max_length
              - self.input_pipeline.chunker.total_context_width
          )
  
          if self.config.low_memory_ans:
              outer_batch_size = min(
                  max(
                      int(
                          self.config.predict_batch_size
                          / approx_chunks_per_doc
                      ),
                      1,
                  ),
                  self.config.predict_batch_size,
              )
          else:
              outer_batch_size = len(Xs)
  
          with self.cached_predict():
              for b_start in range(0, len(Xs), outer_batch_size):
                  initial_run_preds += model_copy.predict(
                      Xs[b_start : b_start + outer_batch_size]
                  )
          del model_copy
  
          # Tag negative predictions with <PAD> label and add to label set
          Y_with_neg_samples = negative_samples(
              initial_run_preds, Y, pad=self.config.pad_token
          )
  
          # this means we get the same absolute number of randomly sampled empty chunks with or without this option.
          self.config.max_empty_chunk_ratio *= sum(
              len(yi) for yi in Y
          ) / sum(len(yi) for yi in Y_with_neg_samples)
          Y = Y_with_neg_samples
  
          # Reinitialize the model including rebuilding the saver.
          self._initialize()
  
          # If training with partial labels, combine output of auto negative sampling on
          # gold data with partial labels data
          if X_partial and Y_partial:
              Xs = Xs + X_partial
              Y = Y + Y_partial
  
              # Set empty chunks ratio to 0 to remove empty chunks from partially labeled
              # data, which will only have a sample of true labels
              # TODO Determine if we need something more sophisticated for chunking
              self.config.max_empty_chunk_ratio = 0.0
  
      return super().finetune(
          Xs,
          Y=Y,
          context=context,
          update_hook=update_hook,
          log_hooks=log_hooks,
      )
  
imports: import copy
  import os
  from collections import Counter, defaultdict
  import math
  from typing import Dict, List, Tuple, Union
  import tensorflow
  import numpy
  from finetune.base import BaseModel
  from finetune.encoding.target_encoders import SequenceLabelingEncoder, SequenceMultiLabelingEncoder
  from finetune.nn.target_blocks import sequence_labeler
  from finetune.nn.crf import sequence_decode
  from finetune.encoding.sequence_encoder import finetune_to_indico_sequence
  from finetune.encoding.input_encoder import get_spacy
  from finetune.input_pipeline import BasePipeline
  from finetune.util.metrics import sequences_overlap
  from finetune.encoding.input_encoder import tokenize_context
label_desc: Use image node_id 4 for calling the SequenceLabeler obj's underlying member method code with example usage: obj.finetune(Xs, Y, context, update_hook, log_hooks, X_partial, Y_partial) and returns: super