code: def _evaluate_batch(
      batch: MappedTriples,
      model: Model,
      target: Target,
      evaluator: Evaluator,
      slice_size: Optional[int],
      all_pos_triples: Optional[MappedTriples],
      relation_filter: Optional[torch.BoolTensor],
      restrict_entities_to: Optional[torch.LongTensor],
      *,
      mode: Optional[InductiveMode],
  ) -> torch.BoolTensor:
      """
      Evaluate ranking for batch.
  
      :param batch: shape: (batch_size, 3)
          The batch of currently evaluated triples.
      :param model:
          The model to evaluate.
      :param target:
          The prediction target.
      :param evaluator:
          The evaluator
      :param slice_size:
          An optional slice size for computing the scores.
      :param all_pos_triples:
          All positive triples (required if filtering is necessary).
      :param relation_filter:
          The relation filter. Can be re-used.
      :param restrict_entities_to:
          Restriction to evaluate only for these entities.
      :param mode:
          the inductive mode, or None for transductive evaluation
  
      :raises ValueError:
          if all positive triples are required (either due to filtered evaluation, or requiring dense masks).
  
      :return:
          The relation filter, which can be re-used for the same batch.
      """
      scores = model.predict(
          hrt_batch=batch,
          target=target,
          slice_size=slice_size,
          mode=mode,
      )
  
      if evaluator.filtered or evaluator.requires_positive_mask:
          column = TARGET_TO_INDEX[target]
          if all_pos_triples is None:
              raise ValueError(
                  "If filtering_necessary of positive_masks_required is True, all_pos_triples has to be "
                  "provided, but is None."
              )
  
          # Create filter
          (
              positive_filter,
              relation_filter,
          ) = create_sparse_positive_filter_(
              hrt_batch=batch,
              all_pos_triples=all_pos_triples,
              relation_filter=relation_filter,
              filter_col=column,
          )
      else:
          positive_filter = relation_filter = None
  
      if evaluator.filtered:
          assert positive_filter is not None
          # Select scores of true
          true_scores = scores[
              torch.arange(0, batch.shape[0]), batch[:, column]
          ]
          # overwrite filtered scores
          scores = filter_scores_(
              scores=scores, filter_batch=positive_filter
          )
          # The scores for the true triples have to be rewritten to the scores tensor
          scores[
              torch.arange(0, batch.shape[0]), batch[:, column]
          ] = true_scores
          # the rank-based evaluators needs the true scores with trailing 1-dim
          true_scores = true_scores.unsqueeze(dim=-1)
      else:
          true_scores = None
  
      # Create a positive mask with the size of the scores from the positive filter
      if evaluator.requires_positive_mask:
          assert positive_filter is not None
          positive_mask = create_dense_positive_mask_(
              zero_tensor=torch.zeros_like(scores),
              filter_batch=positive_filter,
          )
      else:
          positive_mask = None
  
      # Restrict to entities of interest
      if restrict_entities_to is not None:
          scores = scores[:, restrict_entities_to]
          if positive_mask is not None:
              positive_mask = positive_mask[:, restrict_entities_to]
  
      # process scores
      evaluator.process_scores_(
          hrt_batch=batch,
          target=target,
          true_scores=true_scores,
          scores=scores,
          dense_positive_mask=positive_mask,
      )
  
      return relation_filter
  
imports: from __future__ import annotations
  import logging
  import timeit
  import warnings
  from abc import ABC, abstractmethod
  from collections import ChainMap
  from typing import Any, ClassVar, Collection, Generic, List, Mapping, NamedTuple, Optional, Tuple, Type, TypeVar, Union, cast
  import pandas
  import torch
  from torch_max_mem import maximize_memory_utilization
  from tqdm.autonotebook import tqdm
  from ..constants import COLUMN_LABELS, TARGET_TO_INDEX, TARGET_TO_KEY_LABELS
  from ..metrics.utils import Metric
  from ..models import Model
  from ..triples.triples_factory import restrict_triples
  from ..triples.utils import get_entities, get_relations
  from ..typing import LABEL_HEAD, LABEL_RELATION, LABEL_TAIL, InductiveMode, MappedTriples, Target
  from ..utils import flatten_dictionary, format_relative_comparison, normalize_string, prepare_filter_triples
label_desc: Use image node_id 6 for calling a global function with example usage: _evaluate_batch(batch, model, target, evaluator, slice_size, all_pos_triples, relation_filter, restrict_entities_to) and returns: relation_filter