graph4ai / graph4nlp

Graph4nlp is the library for the easy use of Graph Neural Networks for NLP. Welcome to visit our DLG4NLP website (https://dlg4nlp.github.io/index.html) for various learning resources!
Apache License 2.0
1.66k stars 201 forks source link

Could you please provide a simple example to use the NodeEmbeddingBasedRefinedGraphConstruction class? #587

Open smousav9 opened 1 year ago

smousav9 commented 1 year ago

❓ Questions and Help

I am trying to come up with a simple example of how to use the NodeEmbeddingBasedRefinedGraphConstruction class, but I am getting the following error. could you please let me know how to congif the class to make it work?

from graph4nlp.pytorch.modules.graph_construction.node_embedding_based_refined_graph_construction import NodeEmbeddingBasedRefinedGraphConstruction
raw_data = "James went to the corner-shop. And bought some eggs."
gl = NodeEmbeddingBasedRefinedGraphConstruction(alpha_fusion= 0.2, input_size=(len(raw_data)))
graphdata = gl.init_topology(raw_data, lower_case=True)
graph = gl.dynamic_topology(graphdata)

But here is the error that I get.

    152 def __repr__(self):
--> 153     return self._graph._get_batch_node_features()

File ~/.conda/envs/graph4nlp/lib/python3.10/site-packages/graph4nlp-0.5.5-py3.10.egg/graph4nlp/pytorch/data/data.py:930, in GraphData._get_batch_node_features(self, item)
    915 """
    916 Get the batched view of node feature tensors, i.e., tensors in (B, N, D) view
    917 
   (...)
    927     batch-view tensors, or just the specified tensor.
    928 """
    929 if not self._is_batch:
--> 930     raise Exception("Calling batch_node_features() method on a non-batch graph.")
    931 if item is None:
    932     batch_node_features = dict()

Exception: Calling batch_node_features() method on a non-batch graph.

Any working simple example is highly appreciated.

hugochan commented 1 year ago

Hi @smousav9, thanks for your interest to the library! You can find one such example here.