class_docstr: Relation Classifier to predict the relation between two entities.
  
  Task
  ----
  Relation Classification (RC) is the task of identifying the semantic relation between two entities in a text.
  In contrast to (end-to-end) Relation Extraction (RE), RC requires pre-labelled entities.
  
  Example:
  --------
  For the `founded_by` relation from `ORG` (head) to `PER` (tail) and the sentence
  "Larry Page and Sergey Brin founded Google .", we extract the relations
  - founded_by(head='Google', tail='Larry Page') and
  - founded_by(head='Google', tail='Sergey Brin').
  
  Architecture
  ------------
  The Relation Classifier Model builds upon a text classifier.
  The model generates an encoded sentence for each entity pair
  in the cross product of all entities in the original sentence.
  In the encoded representation, the entities in the current entity pair are masked/marked with control tokens.
  (For an example, see the docstrings of different encoding strategies, e.g. :class:`TypedEntityMarker`.)
  Then, for each encoded sentence, the model takes its document embedding and puts the resulting
  text representation(s) through a linear layer to get the class relation label.
  
  The implemented encoding strategies are taken from this paper by Zhou et al.: https://arxiv.org/abs/2102.01373
  
  .. warning::
      Currently, the model has no multi-label support.
class_docstr_tok: ["Relation","Classifier","to","predict","the","relation","between","two","entities",".","Task","--","--","Relation","Classification","(","RC",")","is","the","task","of","identifying","the","semantic","relation","between","two","entities","in","a","text",".","In","contrast","to","(","end-to-end",")","Relation","Extraction","(","RE",")",",","RC","requires","pre-labelled","entities",".","Example",":","--","--","--","--","For","the","`","founded_by","`","relation","from","`","ORG","`","(","head",")","to","`","PER","`","(","tail",")","and","the","sentence","''","Larry","Page","and","Sergey","Brin","founded","Google",".","``",",","we","extract","the","relations","-","founded_by","(","head='Google","'",",","tail='Larry","Page","'",")","and","-","founded_by","(","head='Google","'",",","tail='Sergey","Brin","'",")",".","Architecture","--","--","--","--","--","--","The","Relation","Classifier","Model","builds","upon","a","text","classifier",".","The","model","generates","an","encoded","sentence","for","each","entity","pair","in","the","cross","product","of","all","entities","in","the","original","sentence",".","In","the","encoded","representation",",","the","entities","in","the","current","entity","pair","are","masked\/marked","with","control","tokens",".","(","For","an","example",",","see","the","docstrings","of","different","encoding","strategies",",","e.g",".",":","class",":","`","TypedEntityMarker","`",".",")","Then",",","for","each","encoded","sentence",",","the","model","takes","its","document","embedding","and","puts","the","resulting","text","representation","(","s",")","through","a","linear","layer","to","get","the","class","relation","label",".","The","implemented","encoding","strategies","are","taken","from","this","paper","by","Zhou","et","al",".",":","https",":","\/\/arxiv.org\/abs\/2102.01373","..","warning",":",":","Currently",",","the","model","has","no","multi-label","support","."]
docstr: Create Encoded Sentences and Relation pairs for Training.
  
  Same as `self._encode_sentence_for_inference`.
  
  with the option of disabling cross augmentation via `self.cross_augmentation`
  (and that the relation with reference to the original sentence is not returned).
docstr_tok: ["Create","Encoded","Sentences","and","Relation","pairs","for","Training",".","Same","as","`","self._encode_sentence_for_inference","`",".","with","the","option","of","disabling","cross","augmentation","via","`","self.cross_augmentation","`","(","and","that","the","relation","with","reference","to","the","original","sentence","is","not","returned",")","."]
code: def _encode_sentence_for_training(
      self, sentence: Sentence
  ) -> Iterator[EncodedSentence]:
      """Create Encoded Sentences and Relation pairs for Training.
  
      Same as `self._encode_sentence_for_inference`.
  
      with the option of disabling cross augmentation via `self.cross_augmentation`
      (and that the relation with reference to the original sentence is not returned).
      """
      for head, tail, gold_label in self._entity_pair_permutations(
          sentence
      ):
          if gold_label is None:
              if self.cross_augmentation:
                  gold_label = self.zero_tag_value
              else:
                  continue  # Skip generated data points that do not express an originally annotated relation
  
          masked_sentence: EncodedSentence = self._encode_sentence(
              head=head,
              tail=tail,
              gold_label=gold_label,
          )
  
          yield masked_sentence
  
imports: import itertools
  import logging
  import typing
  from abc import ABC, abstractmethod
  from pathlib import Path
  from typing import Any, Dict, Iterator, List, NamedTuple, Optional, Sequence, Set, Tuple, Union, cast
  import torch
  from torch.utils.data.dataset import Dataset
  import flair
  from flair.data import Corpus, Dictionary, Label, Relation, Sentence, Span, Token, _iter_dataset
  from flair.datasets import DataLoader, FlairDatapointDataset
  from flair.embeddings import DocumentEmbeddings, TransformerDocumentEmbeddings
  from flair.tokenization import SpaceTokenizer
label_desc: Use image node_id 6 for calling the RelationClassifier obj's underlying member method code with example usage: obj._encode_sentence_for_training(sentence) without return types