class_docstr: Class for handling KGE models which follows the ranking based protocol.
  
  Example
  -------
  >>> # create model and compile using user defined optimizer settings and
  >>> # user defined settings of an existing loss
  >>> from ampligraph.datasets import load_fb15k_237
  >>> from ampligraph.latent_features import ScoringBasedEmbeddingModel
  >>> from ampligraph.latent_features.loss_functions import SelfAdversarialLoss
  >>> import tensorflow as tf
  >>> X = load_fb15k_237()
  >>> loss = SelfAdversarialLoss({'margin': 0.1, 'alpha': 5, 'reduction': 'sum'})
  >>> model = ScoringBasedEmbeddingModel(eta=5,
  >>>                                    k=300,
  >>>                                    scoring_type='ComplEx',
  >>>                                    seed=0)
  >>> model.compile(optimizer='adam', loss=loss)
  >>> model.fit(X['train'],
  >>>           batch_size=10000,
  >>>           epochs=5)
  Epoch 1/5
  29/29 [==============================] - 3s 87ms/step - loss: 13496.5752
  Epoch 2/5
  29/29 [==============================] - 1s 36ms/step - loss: 13488.8682
  Epoch 3/5
  29/29 [==============================] - 1s 35ms/step - loss: 13436.2725
  Epoch 4/5
  29/29 [==============================] - 1s 35ms/step - loss: 13259.0840
  Epoch 5/5
  29/29 [==============================] - 1s 34ms/step - loss: 12977.0117
class_docstr_tok: ["Class","for","handling","KGE","models","which","follows","the","ranking","based","protocol",".","Example","--","--","--","-",">",">",">","#","create","model","and","compile","using","user","defined","optimizer","settings","and",">",">",">","#","user","defined","settings","of","an","existing","loss",">",">",">","from","ampligraph.datasets","import","load_fb15k_237",">",">",">","from","ampligraph.latent_features","import","ScoringBasedEmbeddingModel",">",">",">","from","ampligraph.latent_features.loss_functions","import","SelfAdversarialLoss",">",">",">","import","tensorflow","as","tf",">",">",">","X","=","load_fb15k_237","(",")",">",">",">","loss","=","SelfAdversarialLoss","(","{","'margin","'",":","0.1",",","'alpha","'",":","5",",","'reduction","'",":","'sum","'","}",")",">",">",">","model","=","ScoringBasedEmbeddingModel","(","eta=5",",",">",">",">","k=300",",",">",">",">","scoring_type='ComplEx","'",",",">",">",">","seed=0",")",">",">",">","model.compile","(","optimizer='adam","'",",","loss=loss",")",">",">",">","model.fit","(","X","[","'train","'","]",",",">",">",">","batch_size=10000",",",">",">",">","epochs=5",")","Epoch","1\/5","29\/29","[","==============================","]","-","3s","87ms\/step","-","loss",":","13496.5752","Epoch","2\/5","29\/29","[","==============================","]","-","1s","36ms\/step","-","loss",":","13488.8682","Epoch","3\/5","29\/29","[","==============================","]","-","1s","35ms\/step","-","loss",":","13436.2725","Epoch","4\/5","29\/29","[","==============================","]","-","1s","35ms\/step","-","loss",":","13259.0840","Epoch","5\/5","29\/29","[","==============================","]","-","1s","34ms\/step","-","loss",":","12977.0117"]
docstr: Fit the model on the provided data.
  
  Parameters
  ----------
  x: np.array, shape (n, 3), or str or GraphDataLoader or AbstractGraphPartitioner
      Data OR Filename of the data file OR Data Handle to be used for training.
  batch_size: int
      Batch size to use during training.
      May be overridden if **x** is a GraphDataLoader or AbstractGraphPartitioner instance.
  epochs: int
      Number of epochs to train (default: 1).
  verbose: bool
      Verbosity (default: `True`).
  callbacks: list of tf.keras.callbacks.Callback
      List of callbacks to be used during training (default: `None`).
  validation_split: float
      Validation split to carve out of **x** (default: 0.0) (currently supported only when **x** is a np.array).
  validation_data: np.array, shape (n, 3) or str or `GraphDataLoader` or `AbstractGraphPartitioner`
      Data OR Filename of the data file OR Data Handle to be used for validation.
  shuffle: bool
      Indicates whether to shuffle the data after every epoch during training (default: `True`).
  initial epoch: int
      Initial epoch number (default: 1).
  validation_batch_size: int
      Batch size to use during validation (default: 100).
      May be overridden if ``validation_data`` is `GraphDataLoader` or `AbstractGraphPartitioner` instance.
  validation_freq: int
      Indicates how often to validate (default: 50).
  validation_burn_in: int
      The burn-in time after which the validation kicks in.
  validation_filter: bool or dict
      Validation filter to be used.
  validation_entities_subset: list or np.array
      Subset of entities to be used for generating corruptions.
  
      .. Note ::
  
          One can perform early stopping using the tensorflow callback ``tf.keras.callbacks.EarlyStopping``
          as shown in the accompanying example below.
  
  focusE: bool
      Specify whether to include the FocusE layer (default: `False`).
      The FocusE layer :cite:`pai2021learning` allows to inject numeric edge attributes into the scoring layer
      of a traditional knowledge graph embedding architecture.
      Semantically, the numeric value can signify importance, uncertainity, significance, confidence...
      of a triple.
  
      .. Note ::
  
          In order to activate focusE, the training data must have shape (n, 4), where the first three columns
          store subject, predicate and object of triples, and the 4-th column stores the numerical edge value
          associated with each triple.
  
  focusE_params: dict
      If FocusE layer is included, specify its hyper-parameters.
      The following hyper-params can be passed:
  
      + `"non_linearity"`: can be one of the following values `"linear"`, `"softplus"`, `"sigmoid"`, `"tanh"`.
      + `"stop_epoch"`: specifies how long to decay (linearly) the numeric values from 1 to original value.
      + `"structural_wt"`: structural influence hyperparameter :math:`\in [0, 1]` that modulates the influence of graph topology.
  
      If ``focusE==True`` and ``focusE_params==dict()``, then the default values are passed:
      ``non_linearity="linear"``, ``stop_epoch=251`` and ``structural_wt=0.001``.
  
  partitioning_k: int
      Num of partitions to use while training (default: 1, i.e., the data is not partitioned).
      May be overridden if ``x`` is an `AbstractGraphPartitioner` instance.
  
      .. Note ::
  
          This function is quite useful when the size of your dataset is extremely large and cannot fit in memory.
          Setting this to a number strictly larger than 1 will automatically partition the data using
          ``BucketGraphPartitioner``.
          Kindly checkout the tutorials for usage in Advanced mode.
  
  Returns
  -------
  history: History object
      Its `History.history` attribute is a record of training loss values, as well as validation loss
      and validation metrics values.
  
  Example
  -------
  >>> from ampligraph.datasets import load_fb15k_237
  >>> from ampligraph.latent_features import ScoringBasedEmbeddingModel
  >>> X = load_fb15k_237()
  >>> model = ScoringBasedEmbeddingModel(eta=5,
  >>>                                    k=300,
  >>>                                    scoring_type='ComplEx',
  >>>                                    seed=0)
  >>> model.compile(optimizer='adam', loss='nll')
  >>> model.fit(X['train'],
  >>>           batch_size=10000,
  >>>           epochs=5)
  Epoch 1/5
  29/29 [==============================] - 2s 71ms/step - loss: 67361.3047
  Epoch 2/5
  29/29 [==============================] - 1s 35ms/step - loss: 67318.6094
  Epoch 3/5
  29/29 [==============================] - 1s 37ms/step - loss: 67020.0703
  Epoch 4/5
  29/29 [==============================] - 1s 35ms/step - loss: 65867.3750
  Epoch 5/5
  29/29 [==============================] - 1s 35ms/step - loss: 63517.9062
  
  >>> # Early stopping example
  >>> from ampligraph.latent_features import ScoringBasedEmbeddingModel
  >>> from ampligraph.datasets import load_fb15k_237
  >>> dataset = load_fb15k_237()
  >>> model = ScoringBasedEmbeddingModel(eta=1,
  >>>                                    k=10,
  >>>                                    scoring_type='TransE')
  >>> model.compile(optimizer='adam', loss='multiclass_nll')
  >>> import tensorflow as tf
  >>> early_stop = tf.keras.callbacks.EarlyStopping(monitor="val_mrr",            # which metrics to monitor
  >>>                                               patience=3,                   # If the monitored metric doesnt improve for these many checks the model early stops
  >>>                                               verbose=1,                    # verbosity
  >>>                                               mode="max",                   # how to compare the monitored metrics; "max" means higher is better
  >>>                                               restore_best_weights=True)    # restore the weights with best value
  >>> # the early stopping instance needs to be passed as callback to fit function
  >>> model.fit(dataset['train'],
  >>>           batch_size=10000,
  >>>           epochs=5,
  >>>           validation_freq=1,                       # validation frequency
  >>>           validation_batch_size=100,               # validation batch size
  >>>           validation_burn_in=3,                    # burn in time
  >>>           validation_corrupt_side='s,o',           # which side to corrupt
  >>>           validation_data=dataset['valid'][::100], # Validation data
  >>>           callbacks=[early_stop])                  # Pass the early stopping object as a callback
  Epoch 1/5
  29/29 [==============================] - 2s 82ms/step - loss: 6698.2188
  Epoch 2/5
  29/29 [==============================] - 1s 34ms/step - loss: 6648.8862
  Epoch 3/5
  3/3 [==============================] - 1s 446ms/steposs: 6652.895
  29/29 [==============================] - 2s 84ms/step - loss: 6590.2842 - val_mrr: 0.0811 -
  val_mr: 1776.4545 - val_hits@1: 0.0000e+00 - val_hits@10: 0.2301 - val_hits@100: 0.4148
  Epoch 4/5
  3/3 [==============================] - 0s 102ms/steposs: 6564.021
  29/29 [==============================] - 1s 47ms/step - loss: 6517.4517 - val_mrr: 0.0918 -
  val_mr: 1316.6335 - val_hits@1: 0.0000e+00 - val_hits@10: 0.2528 - val_hits@100: 0.4716
  Epoch 5/5
  3/3 [==============================] - 1s 177ms/steposs: 6468.798
  29/29 [==============================] - 2s 62ms/step - loss: 6431.8696 - val_mrr: 0.0901 -
  val_mr: 1074.8920 - val_hits@1: 0.0000e+00 - val_hits@10: 0.2386 - val_hits@100: 0.4773
docstr_tok: ["Fit","the","model","on","the","provided","data",".","Parameters","--","--","--","--","--","x",":","np.array",",","shape","(","n",",","3",")",",","or","str","or","GraphDataLoader","or","AbstractGraphPartitioner","Data","OR","Filename","of","the","data","file","OR","Data","Handle","to","be","used","for","training",".","batch_size",":","int","Batch","size","to","use","during","training",".","May","be","overridden","if","*","*","x","*","*","is","a","GraphDataLoader","or","AbstractGraphPartitioner","instance",".","epochs",":","int","Number","of","epochs","to","train","(","default",":","1",")",".","verbose",":","bool","Verbosity","(","default",":","`","True","`",")",".","callbacks",":","list","of","tf.keras.callbacks.Callback","List","of","callbacks","to","be","used","during","training","(","default",":","`","None","`",")",".","validation_split",":","float","Validation","split","to","carve","out","of","*","*","x","*","*","(","default",":","0.0",")","(","currently","supported","only","when","*","*","x","*","*","is","a","np.array",")",".","validation_data",":","np.array",",","shape","(","n",",","3",")","or","str","or","`","GraphDataLoader","`","or","`","AbstractGraphPartitioner","`","Data","OR","Filename","of","the","data","file","OR","Data","Handle","to","be","used","for","validation",".","shuffle",":","bool","Indicates","whether","to","shuffle","the","data","after","every","epoch","during","training","(","default",":","`","True","`",")",".","initial","epoch",":","int","Initial","epoch","number","(","default",":","1",")",".","validation_batch_size",":","int","Batch","size","to","use","during","validation","(","default",":","100",")",".","May","be","overridden","if","``","validation_data","``","is","`","GraphDataLoader","`","or","`","AbstractGraphPartitioner","`","instance",".","validation_freq",":","int","Indicates","how","often","to","validate","(","default",":","50",")",".","validation_burn_in",":","int","The","burn-in","time","after","which","the","validation","kicks","in",".","validation_filter",":","bool","or","dict","Validation","filter","to","be","used",".","validation_entities_subset",":","list","or","np.array","Subset","of","entities","to","be","used","for","generating","corruptions",".","..","Note",":",":","One","can","perform","early","stopping","using","the","tensorflow","callback","``","tf.keras.callbacks.EarlyStopping","``","as","shown","in","the","accompanying","example","below",".","focusE",":","bool","Specify","whether","to","include","the","FocusE","layer","(","default",":","`","False","`",")",".","The","FocusE","layer",":","cite",":","`","pai2021learning","`","allows","to","inject","numeric","edge","attributes","into","the","scoring","layer","of","a","traditional","knowledge","graph","embedding","architecture",".","Semantically",",","the","numeric","value","can","signify","importance",",","uncertainity",",","significance",",","confidence","...","of","a","triple",".","..","Note",":",":","In","order","to","activate","focusE",",","the","training","data","must","have","shape","(","n",",","4",")",",","where","the","first","three","columns","store","subject",",","predicate","and","object","of","triples",",","and","the","4-th","column","stores","the","numerical","edge","value","associated","with","each","triple",".","focusE_params",":","dict","If","FocusE","layer","is","included",",","specify","its","hyper-parameters",".","The","following","hyper-params","can","be","passed",":","+","`","``","non_linearity","''","`",":","can","be","one","of","the","following","values","`","``","linear","''","`",",","`","``","softplus","''","`",",","`","``","sigmoid","''","`",",","`","``","tanh","''","`",".","+","`","``","stop_epoch","''","`",":","specifies","how","long","to","decay","(","linearly",")","the","numeric","values","from","1","to","original","value",".","+","`","``","structural_wt","''","`",":","structural","influence","hyperparameter",":","math",":","`","\\in","[","0",",","1","]","`","that","modulates","the","influence","of","graph","topology",".","If","``","focusE==True","``","and","``","focusE_params==dict","(",")","``",",","then","the","default","values","are","passed",":","``","non_linearity=","''","linear","''","``",",","``","stop_epoch=251","``","and","``","structural_wt=0.001","``",".","partitioning_k",":","int","Num","of","partitions","to","use","while","training","(","default",":","1",",","i.e.",",","the","data","is","not","partitioned",")",".","May","be","overridden","if","``","x","``","is","an","`","AbstractGraphPartitioner","`","instance",".","..","Note",":",":","This","function","is","quite","useful","when","the","size","of","your","dataset","is","extremely","large","and","can","not","fit","in","memory",".","Setting","this","to","a","number","strictly","larger","than","1","will","automatically","partition","the","data","using","``","BucketGraphPartitioner","``",".","Kindly","checkout","the","tutorials","for","usage","in","Advanced","mode",".","Returns","--","--","--","-","history",":","History","object","Its","`","History.history","`","attribute","is","a","record","of","training","loss","values",",","as","well","as","validation","loss","and","validation","metrics","values",".","Example","--","--","--","-",">",">",">","from","ampligraph.datasets","import","load_fb15k_237",">",">",">","from","ampligraph.latent_features","import","ScoringBasedEmbeddingModel",">",">",">","X","=","load_fb15k_237","(",")",">",">",">","model","=","ScoringBasedEmbeddingModel","(","eta=5",",",">",">",">","k=300",",",">",">",">","scoring_type='ComplEx","'",",",">",">",">","seed=0",")",">",">",">","model.compile","(","optimizer='adam","'",",","loss='nll","'",")",">",">",">","model.fit","(","X","[","'train","'","]",",",">",">",">","batch_size=10000",",",">",">",">","epochs=5",")","Epoch","1\/5","29\/29","[","==============================","]","-","2s","71ms\/step","-","loss",":","67361.3047","Epoch","2\/5","29\/29","[","==============================","]","-","1s","35ms\/step","-","loss",":","67318.6094","Epoch","3\/5","29\/29","[","==============================","]","-","1s","37ms\/step","-","loss",":","67020.0703","Epoch","4\/5","29\/29","[","==============================","]","-","1s","35ms\/step","-","loss",":","65867.3750","Epoch","5\/5","29\/29","[","==============================","]","-","1s","35ms\/step","-","loss",":","63517.9062",">",">",">","#","Early","stopping","example",">",">",">","from","ampligraph.latent_features","import","ScoringBasedEmbeddingModel",">",">",">","from","ampligraph.datasets","import","load_fb15k_237",">",">",">","dataset","=","load_fb15k_237","(",")",">",">",">","model","=","ScoringBasedEmbeddingModel","(","eta=1",",",">",">",">","k=10",",",">",">",">","scoring_type='TransE","'",")",">",">",">","model.compile","(","optimizer='adam","'",",","loss='multiclass_nll","'",")",">",">",">","import","tensorflow","as","tf",">",">",">","early_stop","=","tf.keras.callbacks.EarlyStopping","(","monitor=","''","val_mrr","''",",","#","which","metrics","to","monitor",">",">",">","patience=3",",","#","If","the","monitored","metric","doesnt","improve","for","these","many","checks","the","model","early","stops",">",">",">","verbose=1",",","#","verbosity",">",">",">","mode=","''","max","''",",","#","how","to","compare","the","monitored","metrics",";","``","max","''","means","higher","is","better",">",">",">","restore_best_weights=True",")","#","restore","the","weights","with","best","value",">",">",">","#","the","early","stopping","instance","needs","to","be","passed","as","callback","to","fit","function",">",">",">","model.fit","(","dataset","[","'train","'","]",",",">",">",">","batch_size=10000",",",">",">",">","epochs=5",",",">",">",">","validation_freq=1",",","#","validation","frequency",">",">",">","validation_batch_size=100",",","#","validation","batch","size",">",">",">","validation_burn_in=3",",","#","burn","in","time",">",">",">","validation_corrupt_side=","'s",",","o","'",",","#","which","side","to","corrupt",">",">",">","validation_data=dataset","[","'valid","'","]","[",":",":100","]",",","#","Validation","data",">",">",">","callbacks=","[","early_stop","]",")","#","Pass","the","early","stopping","object","as","a","callback","Epoch","1\/5","29\/29","[","==============================","]","-","2s","82ms\/step","-","loss",":","6698.2188","Epoch","2\/5","29\/29","[","==============================","]","-","1s","34ms\/step","-","loss",":","6648.8862","Epoch","3\/5","3\/3","[","==============================","]","-","1s","446ms\/steposs",":","6652.895","29\/29","[","==============================","]","-","2s","84ms\/step","-","loss",":","6590.2842","-","val_mrr",":","0.0811","-","val_mr",":","1776.4545","-","val_hits","@","1",":","0.0000e+00","-","val_hits","@","10",":","0.2301","-","val_hits","@","100",":","0.4148","Epoch","4\/5","3\/3","[","==============================","]","-","0s","102ms\/steposs",":","6564.021","29\/29","[","==============================","]","-","1s","47ms\/step","-","loss",":","6517.4517","-","val_mrr",":","0.0918","-","val_mr",":","1316.6335","-","val_hits","@","1",":","0.0000e+00","-","val_hits","@","10",":","0.2528","-","val_hits","@","100",":","0.4716","Epoch","5\/5","3\/3","[","==============================","]","-","1s","177ms\/steposs",":","6468.798","29\/29","[","==============================","]","-","2s","62ms\/step","-","loss",":","6431.8696","-","val_mrr",":","0.0901","-","val_mr",":","1074.8920","-","val_hits","@","1",":","0.0000e+00","-","val_hits","@","10",":","0.2386","-","val_hits","@","100",":","0.4773"]
code: def fit(
      self,
      x=None,
      batch_size=1,
      epochs=1,
      verbose=True,
      callbacks=None,
      validation_split=0.0,
      validation_data=None,
      shuffle=True,
      initial_epoch=0,
      validation_batch_size=100,
      validation_corrupt_side="s,o",
      validation_freq=50,
      validation_burn_in=100,
      validation_filter=False,
      validation_entities_subset=None,
      partitioning_k=1,
      focusE=False,
      focusE_params={},
  ):
      """Fit the model on the provided data.
  
      Parameters
      ----------
      x: np.array, shape (n, 3), or str or GraphDataLoader or AbstractGraphPartitioner
          Data OR Filename of the data file OR Data Handle to be used for training.
      batch_size: int
          Batch size to use during training.
          May be overridden if **x** is a GraphDataLoader or AbstractGraphPartitioner instance.
      epochs: int
          Number of epochs to train (default: 1).
      verbose: bool
          Verbosity (default: `True`).
      callbacks: list of tf.keras.callbacks.Callback
          List of callbacks to be used during training (default: `None`).
      validation_split: float
          Validation split to carve out of **x** (default: 0.0) (currently supported only when **x** is a np.array).
      validation_data: np.array, shape (n, 3) or str or `GraphDataLoader` or `AbstractGraphPartitioner`
          Data OR Filename of the data file OR Data Handle to be used for validation.
      shuffle: bool
          Indicates whether to shuffle the data after every epoch during training (default: `True`).
      initial epoch: int
          Initial epoch number (default: 1).
      validation_batch_size: int
          Batch size to use during validation (default: 100).
          May be overridden if ``validation_data`` is `GraphDataLoader` or `AbstractGraphPartitioner` instance.
      validation_freq: int
          Indicates how often to validate (default: 50).
      validation_burn_in: int
          The burn-in time after which the validation kicks in.
      validation_filter: bool or dict
          Validation filter to be used.
      validation_entities_subset: list or np.array
          Subset of entities to be used for generating corruptions.
  
          .. Note ::
  
              One can perform early stopping using the tensorflow callback ``tf.keras.callbacks.EarlyStopping``
              as shown in the accompanying example below.
  
      focusE: bool
          Specify whether to include the FocusE layer (default: `False`).
          The FocusE layer :cite:`pai2021learning` allows to inject numeric edge attributes into the scoring layer
          of a traditional knowledge graph embedding architecture.
          Semantically, the numeric value can signify importance, uncertainity, significance, confidence...
          of a triple.
  
          .. Note ::
  
              In order to activate focusE, the training data must have shape (n, 4), where the first three columns
              store subject, predicate and object of triples, and the 4-th column stores the numerical edge value
              associated with each triple.
  
      focusE_params: dict
          If FocusE layer is included, specify its hyper-parameters.
          The following hyper-params can be passed:
  
          + `"non_linearity"`: can be one of the following values `"linear"`, `"softplus"`, `"sigmoid"`, `"tanh"`.
          + `"stop_epoch"`: specifies how long to decay (linearly) the numeric values from 1 to original value.
          + `"structural_wt"`: structural influence hyperparameter :math:`\\in [0, 1]` that modulates the influence of graph topology.
  
          If ``focusE==True`` and ``focusE_params==dict()``, then the default values are passed:
          ``non_linearity="linear"``, ``stop_epoch=251`` and ``structural_wt=0.001``.
  
      partitioning_k: int
          Num of partitions to use while training (default: 1, i.e., the data is not partitioned).
          May be overridden if ``x`` is an `AbstractGraphPartitioner` instance.
  
          .. Note ::
  
              This function is quite useful when the size of your dataset is extremely large and cannot fit in memory.
              Setting this to a number strictly larger than 1 will automatically partition the data using
              ``BucketGraphPartitioner``.
              Kindly checkout the tutorials for usage in Advanced mode.
  
      Returns
      -------
      history: History object
          Its `History.history` attribute is a record of training loss values, as well as validation loss
          and validation metrics values.
  
      Example
      -------
      >>> from ampligraph.datasets import load_fb15k_237
      >>> from ampligraph.latent_features import ScoringBasedEmbeddingModel
      >>> X = load_fb15k_237()
      >>> model = ScoringBasedEmbeddingModel(eta=5,
      >>>                                    k=300,
      >>>                                    scoring_type='ComplEx',
      >>>                                    seed=0)
      >>> model.compile(optimizer='adam', loss='nll')
      >>> model.fit(X['train'],
      >>>           batch_size=10000,
      >>>           epochs=5)
      Epoch 1/5
      29/29 [==============================] - 2s 71ms/step - loss: 67361.3047
      Epoch 2/5
      29/29 [==============================] - 1s 35ms/step - loss: 67318.6094
      Epoch 3/5
      29/29 [==============================] - 1s 37ms/step - loss: 67020.0703
      Epoch 4/5
      29/29 [==============================] - 1s 35ms/step - loss: 65867.3750
      Epoch 5/5
      29/29 [==============================] - 1s 35ms/step - loss: 63517.9062
  
      >>> # Early stopping example
      >>> from ampligraph.latent_features import ScoringBasedEmbeddingModel
      >>> from ampligraph.datasets import load_fb15k_237
      >>> dataset = load_fb15k_237()
      >>> model = ScoringBasedEmbeddingModel(eta=1,
      >>>                                    k=10,
      >>>                                    scoring_type='TransE')
      >>> model.compile(optimizer='adam', loss='multiclass_nll')
      >>> import tensorflow as tf
      >>> early_stop = tf.keras.callbacks.EarlyStopping(monitor="val_mrr",            # which metrics to monitor
      >>>                                               patience=3,                   # If the monitored metric doesnt improve for these many checks the model early stops
      >>>                                               verbose=1,                    # verbosity
      >>>                                               mode="max",                   # how to compare the monitored metrics; "max" means higher is better
      >>>                                               restore_best_weights=True)    # restore the weights with best value
      >>> # the early stopping instance needs to be passed as callback to fit function
      >>> model.fit(dataset['train'],
      >>>           batch_size=10000,
      >>>           epochs=5,
      >>>           validation_freq=1,                       # validation frequency
      >>>           validation_batch_size=100,               # validation batch size
      >>>           validation_burn_in=3,                    # burn in time
      >>>           validation_corrupt_side='s,o',           # which side to corrupt
      >>>           validation_data=dataset['valid'][::100], # Validation data
      >>>           callbacks=[early_stop])                  # Pass the early stopping object as a callback
      Epoch 1/5
      29/29 [==============================] - 2s 82ms/step - loss: 6698.2188
      Epoch 2/5
      29/29 [==============================] - 1s 34ms/step - loss: 6648.8862
      Epoch 3/5
      3/3 [==============================] - 1s 446ms/steposs: 6652.895
      29/29 [==============================] - 2s 84ms/step - loss: 6590.2842 - val_mrr: 0.0811 -
      val_mr: 1776.4545 - val_hits@1: 0.0000e+00 - val_hits@10: 0.2301 - val_hits@100: 0.4148
      Epoch 4/5
      3/3 [==============================] - 0s 102ms/steposs: 6564.021
      29/29 [==============================] - 1s 47ms/step - loss: 6517.4517 - val_mrr: 0.0918 -
      val_mr: 1316.6335 - val_hits@1: 0.0000e+00 - val_hits@10: 0.2528 - val_hits@100: 0.4716
      Epoch 5/5
      3/3 [==============================] - 1s 177ms/steposs: 6468.798
      29/29 [==============================] - 2s 62ms/step - loss: 6431.8696 - val_mrr: 0.0901 -
      val_mr: 1074.8920 - val_hits@1: 0.0000e+00 - val_hits@10: 0.2386 - val_hits@100: 0.4773
  
      """
      # verifies if compile has been called before calling fit
      self._assert_compile_was_called()
      # focusE
      self.current_epoch = 0
      self.use_focusE = focusE
  
      # use train test unseen to split training set
      if validation_split:
          assert isinstance(
              x, np.ndarray
          ), "Validation split supported for numpy arrays only!"
          x, validation_data = train_test_split_no_unseen(
              x,
              test_size=validation_split,
              seed=self.seed,
              allow_duplication=False,
          )
  
      with training_utils.RespectCompiledTrainableState(self):
          # create data handler for the data
          self.data_handler = data_adapter.DataHandler(
              x,
              model=self,
              batch_size=batch_size,
              dataset_type="train",
              epochs=epochs,
              initial_epoch=initial_epoch,
              use_filter=False,
              # if model is already
              # trained use the old
              # indexer
              use_indexer=self.data_indexer,
              partitioning_k=partitioning_k,
          )
  
          self.partitioner_metadata = (
              self.data_handler.get_update_partitioner_metadata(
                  self.base_dir
              )
          )
          # get the mapping details
          self.data_indexer = self.data_handler.get_mapper()
          # get the maximum entities and relations that will be trained
          # (useful during partitioning)
          self.max_ent_size = self.data_handler._adapter.max_entities
          self.max_rel_size = self.data_handler._adapter.max_relations
          # Number of columns (i.e., only triples or also weights?)
          if isinstance(
              self.data_handler._adapter, PartitionDataManager
          ):
              self.data_shape = (
                  self.data_handler._parent_adapter.backend.data_shape
              )
          else:
              self.data_shape = (
                  self.data_handler._adapter.backend.data_shape
              )
  
          # FocusE
          if self.data_shape < 4:
              self.use_focusE = False
          else:
              if self.use_focusE:
                  assert isinstance(
                      focusE_params, dict
                  ), "focusE parameters need to be in a dict!"
                  # Define FocusE params
                  (
                      non_linearity,
                      stop_epoch,
                      structure_weight,
                  ) = self.get_focusE_params(focusE_params)
                  self.focusE_params = {
                      "non_linearity": non_linearity,
                      "stop_epoch": stop_epoch,
                      "structural_wt": structure_weight,
                  }
              else:
                  print(
                      "Data shape is {}: not only triples were given, but focusE is not active!".format(
                          self.data_shape
                      )
                  )
  
          # Container that configures and calls `tf.keras.Callback`s.
          if not isinstance(callbacks, callbacks_module.CallbackList):
              callbacks = callbacks_module.CallbackList(
                  callbacks,
                  add_history=True,
                  add_progbar=verbose != 0,
                  model=self,
                  verbose=verbose,
                  epochs=epochs,
              )
  
          # This variable is used by callbacks to stop training in case of
          # any error
          self.stop_training = False
          self.is_partitioned_training = (
              self.data_handler.using_partitioning
          )
          self.optimizer.set_partitioned_training(
              self.is_partitioned_training
          )
  
          # set some partition related params if it is partitioned training
          if self.is_partitioned_training:
              self.partitioner_k = (
                  self.data_handler._adapter.partitioner_k
              )
              self.encoding_layer.max_ent_size = self.max_ent_size
              self.encoding_layer.max_rel_size = self.max_rel_size
  
          # make the train function that will be used to process each batch
          # of data
          train_function = self.make_train_function()
          # before training begins call this callback function
          callbacks.on_train_begin()
  
          if (
              isinstance(validation_entities_subset, str)
              and validation_entities_subset == "all"
          ):
              # if the subset is set to none, it will use all entities in the
              # graph for generating corruptions
              validation_entities_subset = None
  
          # enumerate over the data
          for epoch, iterator in self.data_handler.enumerate_epochs():
              # current epoch number
              self.current_epoch = epoch
              # before epoch begins call this callback function
              callbacks.on_epoch_begin(epoch)
              # Update focusE parameter
              if self.use_focusE:
                  self.update_focusE_params()
              # handle the stop iteration of data iterator in this scope
              with self.data_handler.catch_stop_iteration():
                  # iterate over the dataset
                  for step in self.data_handler.steps():
                      # before a batch is processed call this callback
                      # function
                      callbacks.on_train_batch_begin(step)
  
                      # process this batch
                      logs = train_function(iterator)
                      # after a batch is processed call this callback
                      # function
                      callbacks.on_train_batch_end(step, logs)
  
              # store the logs of the last batch of the epoch
              epoch_logs = copy.copy(logs)
              # if validation is enabled
              if (
                  epoch >= (validation_burn_in - 1)
                  and validation_data is not None
                  and self._should_eval(epoch, validation_freq)
              ):
                  if (
                      self.data_shape > 3
                      and validation_data.shape[1] == 3
                  ):
                      nan_weights = np.empty(validation_data.shape[0])
                      nan_weights.fill(np.nan)
                      validation_data = np.concatenate(
                          [validation_data, nan_weights], axis=1
                      )
                  # evaluate on the validation
                  ranks = self.evaluate(
                      validation_data,
                      batch_size=validation_batch_size or batch_size,
                      use_filter=validation_filter,
                      dataset_type="valid",
                      corrupt_side=validation_corrupt_side,
                      entities_subset=validation_entities_subset,
                  )
                  # compute all the metrics
                  val_logs = {
                      "val_mrr": mrr_score(ranks),
                      "val_mr": mr_score(ranks),
                      "val_hits@1": hits_at_n_score(ranks, 1),
                      "val_hits@10": hits_at_n_score(ranks, 10),
                      "val_hits@100": hits_at_n_score(ranks, 100),
                  }
                  # update the epoch logs with validation details
                  epoch_logs.update(val_logs)
  
              # after an epoch is completed, call this callback function
              callbacks.on_epoch_end(epoch, epoch_logs)
              if self.stop_training:
                  break
  
          # on training end call this method
          callbacks.on_train_end()
          self.is_fitted = True
          # all the training and validation logs are stored in the history
          # object by keras.Model
          return self.history
  
imports: import tensorflow
  import copy
  import shelve
  import pickle
  import numpy
  import os
  import tempfile
  import logging
  from ampligraph.evaluation.metrics import mrr_score, hits_at_n_score, mr_score
  from ampligraph.datasets import data_adapter
  from ampligraph.datasets.partitioned_data_manager import PartitionDataManager
  from ampligraph.latent_features.layers.scoring.AbstractScoringLayer import SCORING_LAYER_REGISTRY
  from ampligraph.latent_features.layers.encoding import EmbeddingLookupLayer
  from ampligraph.latent_features.layers.calibration import CalibrationLayer
  from ampligraph.latent_features.layers.corruption_generation import CorruptionGenerationLayerTrain
  from ampligraph.datasets.data_indexer import DataIndexer
  from ampligraph.latent_features import optimizers
  from ampligraph.latent_features import loss_functions
  from ampligraph.evaluation import train_test_split_no_unseen
  from tensorflow.python.keras import callbacks
  from tensorflow.python.keras.engine import training_utils
  from tensorflow.python.eager import def_function
  from tensorflow.python.keras import metrics
  from tensorflow.python.keras.engine import compile_utils
label_desc: Use image node_id 15 for calling the ScoringBasedEmbeddingModel obj's underlying member method code with example usage: obj.fit(x, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, initial_epoch, validation_batch_size, validation_corrupt_side, validation_freq, validation_burn_in, validation_filter, validation_entities_subset, partitioning_k, focusE, focusE_params) and returns: self