class_docstr: A training loop that is based upon the local closed world assumption (LCWA).
  
  Under the LCWA, for a given true training triple $(h, r, t) \in \mathcal{T}_{train}$, all triples
  $(h, r, t') \notin \mathcal{T}_{train}$ are assumed to be false. The training approach thus uses a 1-n scoring,
  where it efficiently computes scores for all triples $(h, r, t')$ for $t' \in \mathcal{E}$, i.e., sharing the
  same (head, relation)-pair.
  
  This implementation slightly generalizes the original LCWA, and allows to make the same assumption for relation, or
  head entity. In particular the second, i.e., predicting the relation, is commonly encountered in visual relation
  prediction.
  
  [ruffinelli2020]_ call the LCWA ``KvsAll`` in their work.
class_docstr_tok: ["A","training","loop","that","is","based","upon","the","local","closed","world","assumption","(","LCWA",")",".","Under","the","LCWA",",","for","a","given","true","training","triple","$","(","h",",","r",",","t",")","\\in","\\mathcal","{","T","}","_","{","train","}","$",",","all","triples","$","(","h",",","r",",","t","'",")","\\notin","\\mathcal","{","T","}","_","{","train","}","$","are","assumed","to","be","false",".","The","training","approach","thus","uses","a","1-n","scoring",",","where","it","efficiently","computes","scores","for","all","triples","$","(","h",",","r",",","t","'",")","$","for","$","t","'","\\in","\\mathcal","{","E","}","$",",","i.e.",",","sharing","the","same","(","head",",","relation",")","-pair",".","This","implementation","slightly","generalizes","the","original","LCWA",",","and","allows","to","make","the","same","assumption","for","relation",",","or","head","entity",".","In","particular","the","second",",","i.e.",",","predicting","the","relation",",","is","commonly","encountered","in","visual","relation","prediction",".","[","ruffinelli2020","]","_","call","the","LCWA","``","KvsAll","``","in","their","work","."]
docstr: Initialize the training loop.
  
  :param target:
      The target column. From {0, 1, 2} for head/relation/tail prediction. Defaults to 2, i.e., tail prediction.
  :param kwargs:
      Additional keyword-based parameters passed to TrainingLoop.__init__
  :raises ValueError:
      If an invalid target column is given
docstr_tok: ["Initialize","the","training","loop",".",":","param","target",":","The","target","column",".","From","{","0",",","1",",","2","}","for","head\/relation\/tail","prediction",".","Defaults","to","2",",","i.e.",",","tail","prediction",".",":","param","kwargs",":","Additional","keyword-based","parameters","passed","to","TrainingLoop.__init__",":","raises","ValueError",":","If","an","invalid","target","column","is","given"]
code: def __init__(
      self,
      *,
      target: Union[None, str, int] = None,
      **kwargs,
  ):
      """
      Initialize the training loop.
  
      :param target:
          The target column. From {0, 1, 2} for head/relation/tail prediction. Defaults to 2, i.e., tail prediction.
      :param kwargs:
          Additional keyword-based parameters passed to TrainingLoop.__init__
      :raises ValueError:
          If an invalid target column is given
      """
      super().__init__(**kwargs)
  
      # normalize target column
      if target is None:
          target = 2
      if isinstance(target, str):
          target = name_to_index[target]
      self.target = target
  
      # The type inference is so confusing between the function switching
      # and polymorphism introduced by slicability that these need to be ignored
      if self.target == 0:
          self.score_method = self.model.score_h  # type: ignore
      elif self.target == 1:
          self.score_method = self.model.score_r  # type: ignore
      elif self.target == 2:
          self.score_method = self.model.score_t  # type: ignore
      else:
          raise ValueError(
              f"Invalid target column: {self.target}. Must be from {{0, 1, 2}}."
          )
  
      # Explicit mentioning of num_transductive_entities since in the evaluation there will be a different number
      # of total entities from another inductive inference factory
      self.num_targets = (
          self.model.num_relations
          if self.target == 1
          else self.model._get_entity_len(mode=self.mode)
      )
  
imports: import logging
  from math import ceil
  from typing import Callable, ClassVar, Optional, Tuple, Union
  import torch
  from torch.nn import functional
  from torch.utils.data import DataLoader, TensorDataset
  from .training_loop import TrainingLoop
  from ..losses import Loss
  from ..models import Model
  from ..triples import CoreTriplesFactory
  from ..triples.instances import LCWABatchType, LCWASampleType
  from ..typing import InductiveMode, MappedTriples
label_desc: Use image node_id 1 to create a new LCWATrainingLoop object from inherited base classes: TrainingLoop with example: obj = LCWATrainingLoop()