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: Compute calibrated scores (:math:`0 ≤ score ≤ 1`) for the input triples.
  
  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 `GraphDataLoader` or `AbstractGraphPartitioner` instance.
  verbose: bool
      Verbosity mode (default: `False`).
  callbacks: list of keras.callbacks.Callback instances
      List of callbacks to apply during evaluation.
  
  Returns
  -------
  scores: np.array, shape (n, )
      Calibrated scores for the input triples.
  
  Example
  -------
  >>> from ampligraph.datasets import load_fb15k_237
  >>> from ampligraph.latent_features import ScoringBasedEmbeddingModel
  >>> import numpy as np
  >>> dataset = load_fb15k_237()
  >>> model = ScoringBasedEmbeddingModel(eta=5,
  >>>                                    k=300,
  >>>                                    scoring_type='ComplEx')
  >>> model.compile(optimizer='adam', loss='nll')
  >>> model.fit(dataset['train'],
  >>>           batch_size=10000,
  >>>           epochs=5)
  >>> print('Raw scores (sorted):', np.sort(model.predict(dataset['test'])))
  >>> print('Indices obtained by sorting (scores):', np.argsort(model.predict(dataset['test'])))
  Raw scores (sorted): [-1.0384613  -0.46752608 -0.45149875 ...  3.2897844  3.3034315  3.3280635 ]
  Indices obtained by sorting (scores): [ 3834 18634  4066 ...  1355 13633 10961]
  >>> model.calibrate(dataset['test'],
  >>>                 batch_size=10000,
  >>>                 positive_base_rate=0.9,
  >>>                 epochs=100)
  >>> print('Calibrated scores (sorted):', np.sort(model.predict_proba(dataset['test'])))
  >>> print('Indices obtained by sorting (Calibrated):', np.argsort(model.predict_proba(dataset['test'])))
  Calibrated scores (sorted): [0.5553725  0.5556108  0.5568415  ... 0.6211011  0.62382233 0.6297585 ]
  Indices obtained by sorting (Calibrated): [14573 11577  4404 ... 17817 17816   733]
docstr_tok: ["Compute","calibrated","scores","(",":","math",":","`","0","\u2264","score","\u2264","1","`",")","for","the","input","triples",".","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","`","GraphDataLoader","`","or","`","AbstractGraphPartitioner","`","instance",".","verbose",":","bool","Verbosity","mode","(","default",":","`","False","`",")",".","callbacks",":","list","of","keras.callbacks.Callback","instances","List","of","callbacks","to","apply","during","evaluation",".","Returns","--","--","--","-","scores",":","np.array",",","shape","(","n",",",")","Calibrated","scores","for","the","input","triples",".","Example","--","--","--","-",">",">",">","from","ampligraph.datasets","import","load_fb15k_237",">",">",">","from","ampligraph.latent_features","import","ScoringBasedEmbeddingModel",">",">",">","import","numpy","as","np",">",">",">","dataset","=","load_fb15k_237","(",")",">",">",">","model","=","ScoringBasedEmbeddingModel","(","eta=5",",",">",">",">","k=300",",",">",">",">","scoring_type='ComplEx","'",")",">",">",">","model.compile","(","optimizer='adam","'",",","loss='nll","'",")",">",">",">","model.fit","(","dataset","[","'train","'","]",",",">",">",">","batch_size=10000",",",">",">",">","epochs=5",")",">",">",">","print","(","'Raw","scores","(","sorted",")",":","'",",","np.sort","(","model.predict","(","dataset","[","'test","'","]",")",")",")",">",">",">","print","(","'Indices","obtained","by","sorting","(","scores",")",":","'",",","np.argsort","(","model.predict","(","dataset","[","'test","'","]",")",")",")","Raw","scores","(","sorted",")",":","[","-1.0384613","-0.46752608","-0.45149875","...","3.2897844","3.3034315","3.3280635","]","Indices","obtained","by","sorting","(","scores",")",":","[","3834","18634","4066","...","1355","13633","10961","]",">",">",">","model.calibrate","(","dataset","[","'test","'","]",",",">",">",">","batch_size=10000",",",">",">",">","positive_base_rate=0.9",",",">",">",">","epochs=100",")",">",">",">","print","(","'Calibrated","scores","(","sorted",")",":","'",",","np.sort","(","model.predict_proba","(","dataset","[","'test","'","]",")",")",")",">",">",">","print","(","'Indices","obtained","by","sorting","(","Calibrated",")",":","'",",","np.argsort","(","model.predict_proba","(","dataset","[","'test","'","]",")",")",")","Calibrated","scores","(","sorted",")",":","[","0.5553725","0.5556108","0.5568415","...","0.6211011","0.62382233","0.6297585","]","Indices","obtained","by","sorting","(","Calibrated",")",":","[","14573","11577","4404","...","17817","17816","733","]"]
code: def predict_proba(self, x, batch_size=32, verbose=0, callbacks=None):
      """
      Compute calibrated scores (:math:`0 ≤ score ≤ 1`) for the input triples.
  
      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 `GraphDataLoader` or `AbstractGraphPartitioner` instance.
      verbose: bool
          Verbosity mode (default: `False`).
      callbacks: list of keras.callbacks.Callback instances
          List of callbacks to apply during evaluation.
  
      Returns
      -------
      scores: np.array, shape (n, )
          Calibrated scores for the input triples.
  
      Example
      -------
      >>> from ampligraph.datasets import load_fb15k_237
      >>> from ampligraph.latent_features import ScoringBasedEmbeddingModel
      >>> import numpy as np
      >>> dataset = load_fb15k_237()
      >>> model = ScoringBasedEmbeddingModel(eta=5,
      >>>                                    k=300,
      >>>                                    scoring_type='ComplEx')
      >>> model.compile(optimizer='adam', loss='nll')
      >>> model.fit(dataset['train'],
      >>>           batch_size=10000,
      >>>           epochs=5)
      >>> print('Raw scores (sorted):', np.sort(model.predict(dataset['test'])))
      >>> print('Indices obtained by sorting (scores):', np.argsort(model.predict(dataset['test'])))
      Raw scores (sorted): [-1.0384613  -0.46752608 -0.45149875 ...  3.2897844  3.3034315  3.3280635 ]
      Indices obtained by sorting (scores): [ 3834 18634  4066 ...  1355 13633 10961]
      >>> model.calibrate(dataset['test'],
      >>>                 batch_size=10000,
      >>>                 positive_base_rate=0.9,
      >>>                 epochs=100)
      >>> print('Calibrated scores (sorted):', np.sort(model.predict_proba(dataset['test'])))
      >>> print('Indices obtained by sorting (Calibrated):', np.argsort(model.predict_proba(dataset['test'])))
      Calibrated scores (sorted): [0.5553725  0.5556108  0.5568415  ... 0.6211011  0.62382233 0.6297585 ]
      Indices obtained by sorting (Calibrated): [14573 11577  4404 ... 17817 17816   733]
      """
      if not self.is_calibrated:
          msg = "Model has not been calibrated. \
              Please call `model.calibrate(...)` before predicting probabilities."
  
          raise RuntimeError(msg)
  
      self.data_handler_test = data_adapter.DataHandler(
          x,
          batch_size=batch_size,
          dataset_type="test",
          epochs=1,
          use_filter=False,
          use_indexer=self.data_indexer,
      )
  
      if not isinstance(callbacks, callbacks_module.CallbackList):
          callbacks = callbacks_module.CallbackList(
              callbacks,
              add_history=True,
              add_progbar=verbose != 0,
              model=self,
              verbose=verbose,
              epochs=1,
              steps=self.data_handler_test.inferred_steps,
          )
  
      predict_function = self.make_predict_function()
      callbacks.on_predict_begin()
      outputs = []
      for _, iterator in self.data_handler_test.enumerate_epochs():
          with self.data_handler_test.catch_stop_iteration():
              for step in self.data_handler_test.steps():
                  callbacks.on_predict_batch_begin(step)
                  batch_outputs = predict_function(iterator)
                  probas = self.calibration_layer(
                      batch_outputs, training=0
                  )
                  outputs.append(probas)
  
                  callbacks.on_predict_batch_end(
                      step, {"outputs": batch_outputs}
                  )
      callbacks.on_predict_end()
      return np.concatenate(outputs)
  
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 37 for calling the ScoringBasedEmbeddingModel obj's underlying member method code with example usage: obj.predict_proba(x, batch_size, verbose, callbacks) and returns: np