class_docstr: Read a knowledge graph to memory
class_docstr_tok: ["Read","a","knowledge","graph","to","memory"]
docstr: Get all next actions (edge, next_entity) from current nodes.
docstr_tok: ["Get","all","next","actions","(","edge",",","next_entity",")","from","current","nodes","."]
code: def get_next_kg_actions(
      self,
      current_ents,
      query_rels,
      max_kg_relations=None,
      mode="train",
      all_answers=None,
  ):
      """Get all next actions (edge, next_entity) from current nodes."""
      if not max_kg_relations:
          max_kg_relations = self.max_kg_relations
      actions = np.ones(
          (current_ents.shape[0], max_kg_relations, 2), dtype=np.int32
      )
      actions[:, :, 0] *= self.entity_vocab[self.entity_pad_token]
      actions[:, :, 1] *= self.relation_vocab[self.relation_pad_token]
      for i in range(current_ents.shape[0]):
          e1 = current_ents[i]
          # actions[i, 0, 0] = e1
          # actions[i, 0, 1] = self.relation_vocab[self.no_op_relation]
          naction = 0
          for e2 in self.kg_data[e1]:
              if naction == max_kg_relations:
                  break
              for r in self.kg_data[e1][e2]:
                  if naction == max_kg_relations:
                      break
                  # if r == query_rels[i] and e2 == answers[i]:
                  if (
                      mode == "train"
                      and r == query_rels[i]
                      and e2 in all_answers[i]
                  ):
                      actions[i, naction, 0] = self.ePAD
                      actions[i, naction, 1] = self.rPAD
                  else:
                      actions[i, naction, 0] = e2
                      actions[i, naction, 1] = r
                  naction += 1
  
      return actions
  
file_path: neural-structured-learning/research/a2n/graph.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from collections import defaultdict
  import csv
  from absl import logging
  import numpy
label_desc: Use image node_id 8 for calling the Graph obj's underlying member method code with example usage: obj.get_next_kg_actions(current_ents, query_rels, max_kg_relations, mode, all_answers) and returns: actions