code: def _to_one_hot(
      rows: torch.LongTensor,
      cols: torch.LongTensor,
      shape: Tuple[int, int],
  ) -> scipy.sparse.spmatrix:
      """Create a one-hot matrix given indices of non-zero elements (potentially containing duplicates)."""
      rows, cols = (
          torch.stack([rows, cols], dim=0).unique(dim=1).numpy()
      )
      values = numpy.ones(rows.shape[0], dtype=numpy.int32)
      return scipy.sparse.coo_matrix(
          (values, (rows, cols)),
          shape=shape,
          dtype=numpy.int32,
      )
  
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 4 for calling a global function with example usage: _to_one_hot(rows, cols, shape) and returns: scipy