class_docstr: Abstract Knowledge Graph embedding model class.
  
  Module to define basic operations in KG embedding models, including embedding
  initialization, computing embeddings and triples' scores.
class_docstr_tok: ["Abstract","Knowledge","Graph","embedding","model","class",".","Module","to","define","basic","operations","in","KG","embedding","models",",","including","embedding","initialization",",","computing","embeddings","and","triples","'","scores","."]
docstr: Compute ranking-based evaluation metrics.
  
  Args:
    examples: Tensor of size n_examples x 3 containing triples' indices.
    filters: Dict representing entities to skip per query for evaluation in
      the filtered setting.
    batch_size: batch size to use to compute scores.
  
  Returns:
    Evaluation metrics (mean rank, mean reciprocical rank and hits).
docstr_tok: ["Compute","ranking-based","evaluation","metrics",".","Args",":","examples",":","Tensor","of","size","n_examples","x","3","containing","triples","'","indices",".","filters",":","Dict","representing","entities","to","skip","per","query","for","evaluation","in","the","filtered","setting",".","batch_size",":","batch","size","to","use","to","compute","scores",".","Returns",":","Evaluation","metrics","(","mean","rank",",","mean","reciprocical","rank","and","hits",")","."]
code: def eval(self, examples, filters, batch_size=1000):
      """Compute ranking-based evaluation metrics.
  
      Args:
        examples: Tensor of size n_examples x 3 containing triples' indices.
        filters: Dict representing entities to skip per query for evaluation in
          the filtered setting.
        batch_size: batch size to use to compute scores.
  
      Returns:
        Evaluation metrics (mean rank, mean reciprocical rank and hits).
      """
      mean_rank = {}
      mean_reciprocal_rank = {}
      hits_at = {}
      total_examples = examples.cardinality().numpy()
      batch_size = min(batch_size, total_examples)
      for missing in ["rhs", "lhs"]:
          ranks = np.ones(total_examples)
          for counter, input_tensor in enumerate(
              examples.batch(batch_size)
          ):
              if batch_size * counter >= total_examples:
                  break
              # reverse triple for head prediction
              if missing == "lhs":
                  input_tensor = tf.concat(
                      [
                          input_tensor[:, 2:],
                          input_tensor[:, 1:2] + self.sizes[1] // 2,
                          input_tensor[:, 0:1],
                      ],
                      axis=1,
                  )
              scores, targets = self.get_scores_targets(input_tensor)
              for i, query in enumerate(input_tensor):
                  query = query.numpy()
                  filter_out = filters[missing][(query[0], query[1])]
                  filter_out += [query[2]]
                  scores[i, filter_out] = -1e6
              ranks[
                  counter * batch_size : (counter + 1) * batch_size
              ] += np.sum((scores >= targets), axis=1)
  
          # compute ranking metrics
          mean_rank[missing] = np.mean(ranks)
          mean_reciprocal_rank[missing] = np.mean(1.0 / ranks)
          hits_at[missing] = {}
          for k in (1, 3, 10):
              hits_at[missing][k] = np.mean(ranks <= k)
      return mean_rank, mean_reciprocal_rank, hits_at
  
file_path: neural-structured-learning/research/kg_hyp_emb/models/base.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import abc
  from kg_hyp_emb.learning import regularizers
  import numpy
  import tensorflow
label_desc: Use image node_id 9 for calling the KGModel obj's underlying member method code with example usage: obj.eval(examples, filters, batch_size) and returns: mean_rank,  mean_reciprocal_rank,  hits_at