Tree LSTM: Convert sentences into DGL graph

I am referring to this tree lstm and it’s using a pre-built dataset from SST, I wanted to know if I am using my own dataset, how should I proceed to convert that dataset into that form?

Here is how SST dataset is built https://github.com/dmlc/dgl/blob/master/python/dgl/data/tree.py in DGL.

It creates a networkx structure and tranform it into DGLGraph. However, this code section is legacy and you don’t have to create a networkx object. Just create a DGLGraph object and use add_node/add_nodes/add_edge/add_edges to create the graph for each sentence. To batch graphs of sentences, use dgl.batch api.

Yeah, But that code uses a text file from sst.zip (like tiny.txt,train.txt etc.) in which sentences are in the form : (3 (2 Yet) (3 (2 (2 the) (2 act)) (3 (4 (3 (2 is) (3 (2 still) (4 charming))) (2 here)) (2 .))))
so, how is this created?
Actually I’m new to Tree LSTM and wanted to try this for sequence labelling task, so I have some sentences with their sequence label which I wanted to convert into DGL graphs.

This is the constituent parsing tree representation of the sentences, you can use CoreNLP/spacy/something else to get structures like that (of course there will be errors).