class_docstr: Class for node embedding based dynamic graph construction.
class_docstr_tok: ["Class","for","node","embedding","based","dynamic","graph","construction","."]
docstr: Compute graph topology.
  
  Parameters
  ----------
  graph : GraphData
      The input graph data.
  
  Returns
  -------
  GraphData
      The constructed graph.
docstr_tok: ["Compute","graph","topology",".","Parameters","--","--","--","--","--","graph",":","GraphData","The","input","graph","data",".","Returns","--","--","--","-","GraphData","The","constructed","graph","."]
code: def dynamic_topology(self, graph):
      """Compute graph topology.
  
      Parameters
      ----------
      graph : GraphData
          The input graph data.
  
      Returns
      -------
      GraphData
          The constructed graph.
      """
      node_emb = graph.batch_node_features["node_feat"]
      node_mask = graph.batch_node_features["token_id"] != Vocab.PAD
  
      raw_adj = self.compute_similarity_metric(node_emb, node_mask)
      raw_adj = self.sparsify_graph(raw_adj)
      graph_reg = self.compute_graph_regularization(raw_adj, node_emb)
  
      if self.sim_metric_type in ("rbf_kernel", "weighted_cosine"):
          assert (
              raw_adj.min().item() >= 0
          ), "adjacency matrix must be non-negative!"
          adj = raw_adj / torch.clamp(
              torch.sum(raw_adj, dim=-1, keepdim=True),
              min=torch.finfo(torch.float32).eps,
          )
          reverse_adj = raw_adj / torch.clamp(
              torch.sum(raw_adj, dim=-2, keepdim=True),
              min=torch.finfo(torch.float32).eps,
          )
      elif self.sim_metric_type == "cosine":
          raw_adj = (raw_adj > 0).float()
          adj = normalize_adj(raw_adj)
          reverse_adj = adj
      else:
          adj = torch.softmax(raw_adj, dim=-1)
          reverse_adj = torch.softmax(raw_adj, dim=-2)
  
      graph = convert_adj_to_graph(graph, adj, reverse_adj, 0)
      graph.graph_attributes["graph_reg"] = graph_reg
  
      return graph
  
file_path: graph4nlp/graph4nlp/pytorch/modules/graph_construction/node_embedding_based_graph_construction.py
imports: import torch
  from nltk.tokenize import word_tokenize
  from ...data.data import GraphData
  from ..utils.generic_utils import normalize_adj
  from ..utils.vocab_utils import Vocab
  from .base import DynamicGraphConstructionBase
  from .utils import convert_adj_to_graph
label_desc: Use image node_id 2 for calling the NodeEmbeddingBasedGraphConstruction obj's underlying member method code with example usage: obj.dynamic_topology(graph) and returns: graph