code: def mapped_triples_to_sparse_matrices(
      mapped_triples: MappedTriples,
      num_relations: int,
  ) -> Tuple[scipy.sparse.spmatrix, scipy.sparse.spmatrix]:
      """Compute relation representations as sparse matrices of entity pairs.
  
      .. note ::
          Both sets, head-tail-set, tail-head-set, have to be created at once since they need to share the same entity
          pair to Id mapping.
  
      :param mapped_triples:
          The input triples.
      :param num_relations:
          The number of input relations
  
      :return: shape: (num_relations, num_entity_pairs)
          head-tail-set, tail-head-set matrices as {0, 1} integer matrices.
      """
      num_triples = mapped_triples.shape[0]
      # compute unique pairs in triples *and* inverted triples for consistent pair-to-id mapping
      extended_mapped_triples = torch.cat(
          [
              mapped_triples,
              mapped_triples.flip(-1),
          ],
          dim=0,
      )
      pairs, pair_id = extended_mapped_triples[:, [0, 2]].unique(
          dim=0, return_inverse=True
      )
      n_pairs = pairs.shape[0]
      forward, backward = pair_id.split(num_triples)
      relations = mapped_triples[:, 1]
      rel = _to_one_hot(
          rows=relations, cols=forward, shape=(num_relations, n_pairs)
      )
      inv = _to_one_hot(
          rows=relations, cols=backward, shape=(num_relations, n_pairs)
      )
      return rel, inv
  
imports: import logging
  from typing import Collection, Iterable, List, Mapping, Optional, Set, Tuple, TypeVar, Union, cast
  import click
  import numpy
  import scipy.sparse
  import torch
  from pykeen.datasets.base import EagerDataset
  from pykeen.triples.triples_factory import CoreTriplesFactory, TriplesFactory, cat_triples
  from pykeen.typing import MappedTriples
  from pykeen.utils import compact_mapping, get_connected_components
label_desc: Use image node_id 5 for calling a global function with example usage: mapped_triples_to_sparse_matrices(mapped_triples, num_relations) and returns: rel,  inv