class_docstr: Triples and mappings to their indices for LCWA.
class_docstr_tok: ["Triples","and","mappings","to","their","indices","for","LCWA","."]
docstr: Create LCWA instances from triples.
  
  :param mapped_triples: shape: (num_triples, 3)
      The ID-based triples.
  :param num_entities:
      The number of entities.
  :param num_relations:
      The number of relations.
  :param target:
      The column to predict
  :param kwargs:
      Keyword arguments (thrown out)
  
  :return:
      The instances.
docstr_tok: ["Create","LCWA","instances","from","triples",".",":","param","mapped_triples",":","shape",":","(","num_triples",",","3",")","The","ID-based","triples",".",":","param","num_entities",":","The","number","of","entities",".",":","param","num_relations",":","The","number","of","relations",".",":","param","target",":","The","column","to","predict",":","param","kwargs",":","Keyword","arguments","(","thrown","out",")",":","return",":","The","instances","."]
code: def from_triples(
      cls,
      mapped_triples: MappedTriples,
      *,
      num_entities: int,
      num_relations: int,
      target: Optional[int] = None,
      **kwargs,
  ) -> Instances:
      """
      Create LCWA instances from triples.
  
      :param mapped_triples: shape: (num_triples, 3)
          The ID-based triples.
      :param num_entities:
          The number of entities.
      :param num_relations:
          The number of relations.
      :param target:
          The column to predict
      :param kwargs:
          Keyword arguments (thrown out)
  
      :return:
          The instances.
      """
      if target is None:
          target = 2
      mapped_triples = mapped_triples.numpy()
      other_columns = sorted(set(range(3)).difference({target}))
      unique_pairs, pair_idx_to_triple_idx = np.unique(
          mapped_triples[:, other_columns], return_inverse=True, axis=0
      )
      num_pairs = unique_pairs.shape[0]
      tails = mapped_triples[:, target]
      target_size = num_relations if target == 1 else num_entities
      compressed = scipy.sparse.coo_matrix(
          (
              np.ones(mapped_triples.shape[0], dtype=np.float32),
              (pair_idx_to_triple_idx, tails),
          ),
          shape=(num_pairs, target_size),
      )
      # convert to csr for fast row slicing
      compressed = compressed.tocsr()
      return cls(pairs=unique_pairs, compressed=compressed)
  
imports: import math
  from abc import ABC, abstractmethod
  from typing import Callable, Generic, Iterable, Iterator, List, NamedTuple, Optional, Tuple, TypeVar
  import numpy
  import scipy.sparse
  import torch
  from class_resolver import HintOrType, OptionalKwargs
  from torch.utils import data
  from .utils import compute_compressed_adjacency_list
  from ..sampling import NegativeSampler, negative_sampler_resolver
  from ..typing import MappedTriples
label_desc: Use image node_id 2 for calling the LCWAInstances obj's underlying member method code with example usage: obj.from_triples(cls, mapped_triples) and returns: cls