class_docstr: A data generator for working with triple-based knowledge graph models, like ComplEx.
  
  This requires a StellarGraph that contains all nodes/entities and every edge/relation type that
  will be trained or predicted upon. The graph does not need to contain the edges/triples that are
  used for training or prediction.
  
  .. seealso::
  
     Models using this generator: :class:`.ComplEx`, :class:`.DistMult`, :class:`.RotatE`, :class:`.RotE`, :class:`.RotH`.
  
     Example using this generator (see individual models for more): `link prediction with ComplEx <https://stellargraph.readthedocs.io/en/stable/demos/link-prediction/complex-link-prediction.html>`__.
  
  Args:
      G (StellarGraph): the graph containing all nodes, and all edge types.
  
      batch_size (int): the size of the batches to generate
class_docstr_tok: ["A","data","generator","for","working","with","triple-based","knowledge","graph","models",",","like","ComplEx",".","This","requires","a","StellarGraph","that","contains","all","nodes\/entities","and","every","edge\/relation","type","that","will","be","trained","or","predicted","upon",".","The","graph","does","not","need","to","contain","the","edges\/triples","that","are","used","for","training","or","prediction",".","..","seealso",":",":","Models","using","this","generator",":",":","class",":","`",".ComplEx","`",",",":","class",":","`",".DistMult","`",",",":","class",":","`",".RotatE","`",",",":","class",":","`",".RotE","`",",",":","class",":","`",".RotH","`",".","Example","using","this","generator","(","see","individual","models","for","more",")",":","`","link","prediction","with","ComplEx","<","https",":","\/\/stellargraph.readthedocs.io\/en\/stable\/demos\/link-prediction\/complex-link-prediction.html",">","`","__",".","Args",":","G","(","StellarGraph",")",":","the","graph","containing","all","nodes",",","and","all","edge","types",".","batch_size","(","int",")",":","the","size","of","the","batches","to","generate"]
docstr: Create a Keras Sequence yielding the edges/triples in ``edges``, potentially with some negative
  edges.
  
  The negative edges are sampled using the "local closed world assumption", where a
  source/subject or a target/object is randomly mutated.
  
  Args:
      edges: the edges/triples to feed into a knowledge graph model.
      negative_samples (int, optional): the number of negative samples to generate for each positive edge.
  
      sample_strategy (str, optional): the sampling strategy to use for negative sampling, if ``negative_samples`` is not None. Supported values:
  
          ``uniform``
  
            Uniform sampling, where a negative edge is created from a positive edge in
            ``edges`` by replacing the source or destination entity with a uniformly sampled
            random entity in the graph (without verifying if the edge exists in the graph: for
            sparse graphs, this is unlikely). Each element in a batch is labelled as 1
            (positive) or 0 (negative). An appropriate loss function is
            :class:`tensorflow.keras.losses.BinaryCrossentropy` (probably with
            ``from_logits=True``).
  
          ``self-adversarial``
  
            Self-adversarial sampling from [1], where each edge is sampled in the same manner
            as ``uniform`` sampling. Each element in a batch is labelled as 1 (positive) or an
            integer in ``[0, -batch_size)`` (negative). An appropriate loss function is
            :class:`stellargraph.losses.SelfAdversarialNegativeSampling`.
  
            [1] Z. Sun, Z.-H. Deng, J.-Y. Nie, and J. Tang, “RotatE: Knowledge Graph Embedding by Relational Rotation in Complex Space,” `arXiv:1902.10197 <http://arxiv.org/abs/1902.10197>`_, Feb. 2019.
  
  Returns:
      A Keras sequence that can be passed to the ``fit`` and ``predict`` method of knowledge-graph models.
docstr_tok: ["Create","a","Keras","Sequence","yielding","the","edges\/triples","in","``","edges","``",",","potentially","with","some","negative","edges",".","The","negative","edges","are","sampled","using","the","``","local","closed","world","assumption","''",",","where","a","source\/subject","or","a","target\/object","is","randomly","mutated",".","Args",":","edges",":","the","edges\/triples","to","feed","into","a","knowledge","graph","model",".","negative_samples","(","int",",","optional",")",":","the","number","of","negative","samples","to","generate","for","each","positive","edge",".","sample_strategy","(","str",",","optional",")",":","the","sampling","strategy","to","use","for","negative","sampling",",","if","``","negative_samples","``","is","not","None",".","Supported","values",":","``","uniform","``","Uniform","sampling",",","where","a","negative","edge","is","created","from","a","positive","edge","in","``","edges","``","by","replacing","the","source","or","destination","entity","with","a","uniformly","sampled","random","entity","in","the","graph","(","without","verifying","if","the","edge","exists","in","the","graph",":","for","sparse","graphs",",","this","is","unlikely",")",".","Each","element","in","a","batch","is","labelled","as","1","(","positive",")","or","0","(","negative",")",".","An","appropriate","loss","function","is",":","class",":","`","tensorflow.keras.losses.BinaryCrossentropy","`","(","probably","with","``","from_logits=True","``",")",".","``","self-adversarial","``","Self-adversarial","sampling","from","[","1","]",",","where","each","edge","is","sampled","in","the","same","manner","as","``","uniform","``","sampling",".","Each","element","in","a","batch","is","labelled","as","1","(","positive",")","or","an","integer","in","``","[","0",",","-batch_size",")","``","(","negative",")",".","An","appropriate","loss","function","is",":","class",":","`","stellargraph.losses.SelfAdversarialNegativeSampling","`",".","[","1","]","Z",".","Sun",",","Z.-H.","Deng",",","J.-Y",".","Nie",",","and","J.","Tang",",","\u201c","RotatE",":","Knowledge","Graph","Embedding","by","Relational","Rotation","in","Complex","Space",",","\u201d","`","arXiv:1902.10197","<","http",":","\/\/arxiv.org\/abs\/1902.10197",">","`","_",",","Feb.","2019",".","Returns",":","A","Keras","sequence","that","can","be","passed","to","the","``","fit","``","and","``","predict","``","method","of","knowledge-graph","models","."]
code: def flow(
      self,
      edges,
      negative_samples=None,
      sample_strategy="uniform",
      shuffle=False,
      seed=None,
  ):
      """
      Create a Keras Sequence yielding the edges/triples in ``edges``, potentially with some negative
      edges.
  
      The negative edges are sampled using the "local closed world assumption", where a
      source/subject or a target/object is randomly mutated.
  
      Args:
          edges: the edges/triples to feed into a knowledge graph model.
          negative_samples (int, optional): the number of negative samples to generate for each positive edge.
  
          sample_strategy (str, optional): the sampling strategy to use for negative sampling, if ``negative_samples`` is not None. Supported values:
  
              ``uniform``
  
                Uniform sampling, where a negative edge is created from a positive edge in
                ``edges`` by replacing the source or destination entity with a uniformly sampled
                random entity in the graph (without verifying if the edge exists in the graph: for
                sparse graphs, this is unlikely). Each element in a batch is labelled as 1
                (positive) or 0 (negative). An appropriate loss function is
                :class:`tensorflow.keras.losses.BinaryCrossentropy` (probably with
                ``from_logits=True``).
  
              ``self-adversarial``
  
                Self-adversarial sampling from [1], where each edge is sampled in the same manner
                as ``uniform`` sampling. Each element in a batch is labelled as 1 (positive) or an
                integer in ``[0, -batch_size)`` (negative). An appropriate loss function is
                :class:`stellargraph.losses.SelfAdversarialNegativeSampling`.
  
                [1] Z. Sun, Z.-H. Deng, J.-Y. Nie, and J. Tang, “RotatE: Knowledge Graph Embedding by Relational Rotation in Complex Space,” `arXiv:1902.10197 <http://arxiv.org/abs/1902.10197>`_, Feb. 2019.
  
      Returns:
          A Keras sequence that can be passed to the ``fit`` and ``predict`` method of knowledge-graph models.
      """
      if isinstance(edges, pd.DataFrame):
          sources = edges[SOURCE]
          rels = edges[TYPE_ATTR_NAME]
          targets = edges[TARGET]
      else:
          raise TypeError(
              f"edges: expected pandas.DataFrame; found {type(edges).__name__}"
          )
  
      if negative_samples is not None:
          require_integer_in_range(
              negative_samples, "negative_samples", min_val=0
          )
  
      supported_strategies = ["uniform", "self-adversarial"]
      if sample_strategy not in supported_strategies:
          raise ValueError(
              f"sample_strategy: expected one of {comma_sep(supported_strategies)}, found {sample_strategy!r}"
          )
  
      source_ilocs = self.G.node_ids_to_ilocs(sources)
      rel_ilocs = self.G.edge_type_names_to_ilocs(rels)
      target_ilocs = self.G.node_ids_to_ilocs(targets)
  
      return KGTripleSequence(
          max_node_iloc=self.G.number_of_nodes(),
          source_ilocs=source_ilocs,
          rel_ilocs=rel_ilocs,
          target_ilocs=target_ilocs,
          batch_size=self.batch_size,
          shuffle=shuffle,
          negative_samples=negative_samples,
          sample_strategy=sample_strategy,
          seed=seed,
      )
  
file_path: stellargraph/stellargraph/mapper/knowledge_graph.py
imports: import threading
  import numpy
  import pandas
  from tensorflow.keras.utils import Sequence
  from ..globalvar import SOURCE, TARGET, TYPE_ATTR_NAME
  from ..random import random_state, SeededPerBatch
  from .base import Generator
  from ..core.validation import comma_sep, require_integer_in_range
label_desc: Use image node_id 3 for calling the KGTripleGenerator obj's underlying member method code with example usage: obj.flow(edges, negative_samples, sample_strategy, shuffle, seed) and returns: KGTripleSequence