docstr: Train the model (with optional early stopping).
  
  The model is trained on a training set ``X`` using the training
  protocol described in :cite:`trouillon2016complex`.
  
  Parameters
  ----------
  X : ndarray, shape (n, 3) or str or GraphDataLoader or
      AbstractGraphPartitioner Data OR Filename of the data
      file OR Data Handle to be used for training.
  early_stopping: bool
      Flag to enable early stopping (default:`False`)
  early_stopping_params: dict
      Dictionary of hyperparameters for the early stopping heuristics.
      The following string keys are supported:
  
          - **"x_valid"** (ndarray, shape (n, 3) or str or
          GraphDataLoader or AbstractGraphPartitioner) - Numpy                 array of validation triples OR handle of Dataset adapter
          which would help retrieve data.
          - **"criteria"** (str) - Criteria for early stopping
          `'hits10'`, `'hits3'`, `'hits1'`                 or `'mrr'` (default: `'mrr'`).
          - **"x_filter"** (ndarray, shape (n, 3)) - Positive triples
          to use as filter if a `'filtered'` early                 stopping criteria is desired (i.e., filtered-MRR if
          ``'criteria':'mrr'``). Note this will affect training time
          (no filter by default). If the filter has already been set in
          the adapter, pass `True`.
          - **"burn_in"** (int) - Number of epochs to pass before
            kicking in early stopping (default: 100).
          - **"check_interval"** (int) - Early stopping interval after
            burn-in (default:10).
          - **"stop_interval"** (int) - Stop if criteria is performing
            worse over n consecutive checks (default: 3).
          - **"corruption_entities"** (list) - List of entities to be
            used for corruptions. If `'all'`, it uses all entities
            (default: `'all'`).
          - **"corrupt_side"** (str) - Specifies which side to corrupt:
          `'s'`, `'o'`, `'s+o'`, `'s,o'`                 (default: `'s,o'`).
  
  focusE_numeric_edge_values: ndarray, shape (n, 1)
      Numeric values associated with links in the training set.
      Semantically, the numeric value can signify importance,
      uncertainity, significance, confidence, etc. If the numeric value
      is unknown pass a NaN weight. The model will uniformly randomly
      assign a numeric value. One can also think about assigning
      numeric values by looking at the distribution of it per predicate.
      .. warning:: In the compatible version, this option only supports
      data passed as np.array.
  tensorboard_logs_path: str or None
      Path to store tensorboard logs, e.g., average training loss
      tracking per epoch (default: `None` indicating no logs will be
      collected). When provided it will create a folder under provided
      path and save tensorboard files there. To then view the loss in
      the terminal run: ``tensorboard --logdir <tensorboard_logs_path>``.
docstr_tok: ["Train","the","model","(","with","optional","early","stopping",")",".","The","model","is","trained","on","a","training","set","``","X","``","using","the","training","protocol","described","in",":","cite",":","`","trouillon2016complex","`",".","Parameters","--","--","--","--","--","X",":","ndarray",",","shape","(","n",",","3",")","or","str","or","GraphDataLoader","or","AbstractGraphPartitioner","Data","OR","Filename","of","the","data","file","OR","Data","Handle","to","be","used","for","training",".","early_stopping",":","bool","Flag","to","enable","early","stopping","(","default",":","`","False","`",")","early_stopping_params",":","dict","Dictionary","of","hyperparameters","for","the","early","stopping","heuristics",".","The","following","string","keys","are","supported",":","-","*","*","''","x_valid","''","*","*","(","ndarray",",","shape","(","n",",","3",")","or","str","or","GraphDataLoader","or","AbstractGraphPartitioner",")","-","Numpy","array","of","validation","triples","OR","handle","of","Dataset","adapter","which","would","help","retrieve","data",".","-","*","*","''","criteria","''","*","*","(","str",")","-","Criteria","for","early","stopping","`","'hits10","'","`",",","`","'hits3","'","`",",","`","'hits1","'","`","or","`","'mrr","'","`","(","default",":","`","'mrr","'","`",")",".","-","*","*","''","x_filter","''","*","*","(","ndarray",",","shape","(","n",",","3",")",")","-","Positive","triples","to","use","as","filter","if","a","`","'filtered","'","`","early","stopping","criteria","is","desired","(","i.e.",",","filtered-MRR","if","``","'criteria","'",":","'mrr","'","``",")",".","Note","this","will","affect","training","time","(","no","filter","by","default",")",".","If","the","filter","has","already","been","set","in","the","adapter",",","pass","`","True","`",".","-","*","*","''","burn_in","''","*","*","(","int",")","-","Number","of","epochs","to","pass","before","kicking","in","early","stopping","(","default",":","100",")",".","-","*","*","''","check_interval","''","*","*","(","int",")","-","Early","stopping","interval","after","burn-in","(","default:10",")",".","-","*","*","''","stop_interval","''","*","*","(","int",")","-","Stop","if","criteria","is","performing","worse","over","n","consecutive","checks","(","default",":","3",")",".","-","*","*","''","corruption_entities","''","*","*","(","list",")","-","List","of","entities","to","be","used","for","corruptions",".","If","`","'all","'","`",",","it","uses","all","entities","(","default",":","`","'all","'","`",")",".","-","*","*","''","corrupt_side","''","*","*","(","str",")","-","Specifies","which","side","to","corrupt",":","`","'s","'","`",",","`","'","o","'","`",",","`","'s+o","'","`",",","`","'s",",","o","'","`","(","default",":","`","'s",",","o","'","`",")",".","focusE_numeric_edge_values",":","ndarray",",","shape","(","n",",","1",")","Numeric","values","associated","with","links","in","the","training","set",".","Semantically",",","the","numeric","value","can","signify","importance",",","uncertainity",",","significance",",","confidence",",","etc",".","If","the","numeric","value","is","unknown","pass","a","NaN","weight",".","The","model","will","uniformly","randomly","assign","a","numeric","value",".","One","can","also","think","about","assigning","numeric","values","by","looking","at","the","distribution","of","it","per","predicate",".","..","warning",":",":","In","the","compatible","version",",","this","option","only","supports","data","passed","as","np.array",".","tensorboard_logs_path",":","str","or","None","Path","to","store","tensorboard","logs",",","e.g.",",","average","training","loss","tracking","per","epoch","(","default",":","`","None","`","indicating","no","logs","will","be","collected",")",".","When","provided","it","will","create","a","folder","under","provided","path","and","save","tensorboard","files","there",".","To","then","view","the","loss","in","the","terminal","run",":","``","tensorboard","--","logdir","<","tensorboard_logs_path",">","``","."]
code: def fit(
      self,
      X,
      early_stopping=False,
      early_stopping_params={},
      focusE_numeric_edge_values=None,
      tensorboard_logs_path=None,
      callbacks=None,
      verbose=False,
  ):
      """Train the model (with optional early stopping).
  
          The model is trained on a training set ``X`` using the training
          protocol described in :cite:`trouillon2016complex`.
  
          Parameters
          ----------
          X : ndarray, shape (n, 3) or str or GraphDataLoader or
              AbstractGraphPartitioner Data OR Filename of the data
              file OR Data Handle to be used for training.
          early_stopping: bool
              Flag to enable early stopping (default:`False`)
          early_stopping_params: dict
              Dictionary of hyperparameters for the early stopping heuristics.
              The following string keys are supported:
  
                  - **"x_valid"** (ndarray, shape (n, 3) or str or
                  GraphDataLoader or AbstractGraphPartitioner) - Numpy \
                  array of validation triples OR handle of Dataset adapter
                  which would help retrieve data.
                  - **"criteria"** (str) - Criteria for early stopping
                  `'hits10'`, `'hits3'`, `'hits1'` \
                  or `'mrr'` (default: `'mrr'`).
                  - **"x_filter"** (ndarray, shape (n, 3)) - Positive triples
                  to use as filter if a `'filtered'` early \
                  stopping criteria is desired (i.e., filtered-MRR if
                  ``'criteria':'mrr'``). Note this will affect training time
                  (no filter by default). If the filter has already been set in
                  the adapter, pass `True`.
                  - **"burn_in"** (int) - Number of epochs to pass before
                    kicking in early stopping (default: 100).
                  - **"check_interval"** (int) - Early stopping interval after
                    burn-in (default:10).
                  - **"stop_interval"** (int) - Stop if criteria is performing
                    worse over n consecutive checks (default: 3).
                  - **"corruption_entities"** (list) - List of entities to be
                    used for corruptions. If `'all'`, it uses all entities
                    (default: `'all'`).
                  - **"corrupt_side"** (str) - Specifies which side to corrupt:
                  `'s'`, `'o'`, `'s+o'`, `'s,o'` \
                  (default: `'s,o'`).
  
          focusE_numeric_edge_values: ndarray, shape (n, 1)
              Numeric values associated with links in the training set.
              Semantically, the numeric value can signify importance,
              uncertainity, significance, confidence, etc. If the numeric value
              is unknown pass a NaN weight. The model will uniformly randomly
              assign a numeric value. One can also think about assigning
              numeric values by looking at the distribution of it per predicate.
              .. warning:: In the compatible version, this option only supports
              data passed as np.array.
          tensorboard_logs_path: str or None
              Path to store tensorboard logs, e.g., average training loss
              tracking per epoch (default: `None` indicating no logs will be
              collected). When provided it will create a folder under provided
              path and save tensorboard files there. To then view the loss in
              the terminal run: ``tensorboard --logdir <tensorboard_logs_path>``.
          """
      self.model = ScoringBasedEmbeddingModel(
          self.eta, self.k, scoring_type=self.model_name, seed=self.seed
      )
      if callbacks is None:
          callbacks = []
      if tensorboard_logs_path is not None:
          tensorboard_callback = tf.keras.callbacks.TensorBoard(
              log_dir=tensorboard_logs_path
          )
          callbacks.append(tensorboard_callback)
  
      regularizer = self.regularizer
      if regularizer is not None:
          regularizer = get_regularizer(
              regularizer, self.regularizer_params
          )
  
      initializer = self.initializer
      if initializer is not None:
          initializer = self._get_initializer(
              initializer, self.initializer_params
          )
  
      loss = get_loss(self.loss, self.loss_params)
      optimizer, is_back_compat_optim = self._get_optimizer(
          self.optimizer, self.optimizer_params
      )
  
      self.model.compile(
          optimizer=optimizer,
          loss=loss,
          entity_relation_initializer=initializer,
          entity_relation_regularizer=regularizer,
      )
      if not is_back_compat_optim:
          tf.keras.backend.set_value(
              self.model.optimizer.learning_rate,
              self.optimizer_params.get("lr", 0.001),
          )
  
      if len(early_stopping_params) != 0:
          checkpoint = tf.keras.callbacks.EarlyStopping(
              monitor="val_{}".format(
                  early_stopping_params.get("criteria", "mrr")
              ),
              min_delta=0,
              patience=early_stopping_params.get("stop_interval", 10),
              verbose=self.verbose,
              mode="max",
              restore_best_weights=True,
          )
          callbacks.append(checkpoint)
  
      x_filter = early_stopping_params.get("x_filter", None)
  
      if isinstance(x_filter, np.ndarray) or isinstance(x_filter, list):
          x_filter = {"test": x_filter}
      elif x_filter is None or not x_filter:
          x_filter = False
      elif isinstance(x_filter, dict):
          pass
      else:
          raise ValueError("Incorrect type for x_filter")
  
      focusE = False
      params_focusE = {}
      if focusE_numeric_edge_values is not None:
          if isinstance(
              focusE_numeric_edge_values, np.ndarray
          ) and isinstance(X, np.ndarray):
              focusE = True
              X = np.concatenate(
                  [X, focusE_numeric_edge_values], axis=1
              )
              params_focusE = {
                  "non_linearity": self.embedding_model_params.get(
                      "non_linearity", "linear"
                  ),
                  "stop_epoch": self.embedding_model_params.get(
                      "stop_epoch", 251
                  ),
                  "structural_wt": self.embedding_model_params.get(
                      "structural_wt", 0.001
                  ),
              }
          else:
              msg = (
                  "Either X or focusE_numeric_edge_values are not\
                      np.array, so focusE is not supported. "
                  "Try using Ampligraph 2 or Ampligraph 1.x APIs!"
              )
              raise ValueError(msg)
  
      self.model.fit(
          X,
          batch_size=np.ceil(X.shape[0] / self.batches_count),
          epochs=self.epochs,
          validation_freq=early_stopping_params.get(
              "check_interval", 10
          ),
          validation_burn_in=early_stopping_params.get("burn_in", 25),
          validation_batch_size=early_stopping_params.get(
              "batch_size", 100
          ),
          validation_data=early_stopping_params.get("x_valid", None),
          validation_filter=x_filter,
          validation_entities_subset=early_stopping_params.get(
              "corruption_entities", None
          ),
          callbacks=callbacks,
          verbose=verbose,
          focusE=focusE,
          focusE_params=params_focusE,
      )
      self.data_shape = self.model.data_shape
  
imports: import numpy
  import tensorflow
  from ampligraph.latent_features.loss_functions import get
  from ampligraph.latent_features.models import ScoringBasedEmbeddingModel
  from ampligraph.latent_features.optimizers import get
  from ampligraph.latent_features.regularizers import get
label_desc: Use image node_id 5 for calling the ScoringModelBase obj's underlying member method code with example usage: obj.fit(X, early_stopping, early_stopping_params, focusE_numeric_edge_values, tensorboard_logs_path, callbacks, verbose) without return types