Loading repository data…
Loading repository data…
graph4ai / repository
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!
Graph4NLP is an easy-to-use library for R&D at the intersection of Deep Learning on Graphs and Natural Language Processing (i.e., DLG4NLP). It provides both full implementations of state-of-the-art models for data scientists and also flexible interfaces to build customized models for researchers and developers with whole-pipeline support. Built upon highly-optimized runtime libraries including DGL , Graph4NLP has both high running efficiency and great extensibility. The architecture of Graph4NLP is shown in the following figure, where boxes with dashed lines represents the features under development. Graph4NLP consists of four different layers: 1) Data Layer, 2) Module Layer, 3) Model Layer, and 4) Application Layer.
01/20/2022: The v0.5.5 release. Try it out! 09/26/2021: The v0.5.1 release. Try it out! 09/01/2021: Welcome to visit our DLG4NLP website (https://dlg4nlp.github.io/index.html) for various learning resources! 06/05/2021: The v0.4.1 release.
| Releases | Date | Features |
|---|---|---|
| v0.5.5 | 2022-01-20 | - Support model.predict API by introducing wrapper functions. - Introduce Three new inference_wrapper functions: classifier_inference_wrapper, generator_inference_wrapper, generator_inference_wrapper_for_tree. - Add the inference and inference_advance examples in each application. - Separate the graph topology and graph embedding process. - Renew all the graph construction functions. - Module graph_embedding is divided into graph_embedding_initialization and graph_embedding_learning. - Unify the parameters in Dataset. We remove the ambiguous parameter graph_type and introduce graph_name to indicate the graph construction method and static_or_dynamic to indicate the static or dynamic graph construction type. - New: The dataset now can automatically choose the default methods (e.g., topology_builder) by only one parameter graph_name. |
| v0.5.1 | 2021-09-26 | - Lint the codes - Support testing with users' own data - Fix the bug: The word embedding size was hard-coded in the 0.4.1 version. Now it is equal to "word_emb_size" parameter. - Fix the bug: The build_vocab() is called twice in the 0.4.1 version. - Fix the bug: The two main files of knowledge graph completion example missed the optional parameter "kg_graph" in ranking_and_hits() when resuming training the model. - Fix the bug: We have fixed the preprocessing path error in KGC readme. - Fix the bug: We have fixed embedding construction bug when setting emb_strategy to 'w2v'. |
| v0.4.1 | 2021-06-05 | - Support the whole pipeline of Graph4NLP - GraphData and Dataset support |
Graph4nlp aims to make it incredibly easy to use GNNs in NLP tasks (check out Graph4NLP Documentation). Here is an example of how to use the Graph2seq model (widely used in machine translation, question answering, semantic parsing, and various other NLP tasks that can be abstracted as graph-to-sequence problem and has shown superior performance).
We also offer other high-level model APIs such as graph-to-tree models. If you are interested in DLG4NLP related research problems, you are very welcome to use our library and refer to our graph4nlp survey.
from graph4nlp.pytorch.datasets.jobs import JobsDataset
from graph4nlp.pytorch.modules.graph_construction.dependency_graph_construction import DependencyBasedGraphConstruction
from graph4nlp.pytorch.modules.config import get_basic_args
from graph4nlp.pytorch.models.graph2seq import Graph2Seq
from graph4nlp.pytorch.modules.utils.config_utils import update_values, get_yaml_config
# build dataset
jobs_dataset = JobsDataset(root_dir='graph4nlp/pytorch/test/dataset/jobs',
topology_builder=DependencyBasedGraphConstruction,
topology_subdir='DependencyGraph') # You should run stanfordcorenlp at background
vocab_model = jobs_dataset.vocab_model
# build model
user_args = get_yaml_config("examples/pytorch/semantic_parsing/graph2seq/config/dependency_gcn_bi_sep_demo.yaml")
args = get_basic_args(graph_construction_name="node_emb", graph_embedding_name="gat", decoder_name="stdrnn")
update_values(to_args=args, from_args_list=[user_args])
graph2seq = Graph2Seq.from_args(args, vocab_model)
# calculation
batch_data = JobsDataset.collate_fn(jobs_dataset.train[0:12])
scores = graph2seq(batch_data["graph_data"], batch_data["tgt_seq"]) # [Batch_size, seq_len, Vocab_size]
Our Graph4NLP computing flow is shown as below.
We provide a comprehensive collection of NLP applications, together with detailed examples as follows:
Environment: torch 1.8, ubuntu 16.04 with 2080ti GPUs
| Task | Dataset | GNN Model | Graph construction | Evaluation | Performance |
|---|---|---|---|---|---|
| Text classification | TRECT CAirline CNSST | GAT | Dependency Constituency Dependency | Accuracy | 0.948 0.785 0.538 |
| Semantic Parsing | JOBS | SAGE | Constituency | Execution accuracy | 0.936 |
| Question generation | SQuAD | GGNN | Dependency | BLEU-4 | 0.15175 |
| Machine translation | IWSLT14 | GCN | Dynamic | BLEU-4 | 0.3212 |
| Summarization | CNN(30k) | GCN | Dependency | ROUGE-1 | 26.4 |
| Knowledge graph completion | Kinship | GCN | Dependency | MRR | 82.4 |
| Math word problem | MAWPS | SAGE | Dynamic | Solution accuracy | 76.4 |
Currently, users can install Graph4NLP via pip or source code. Graph4NLP supports the following OSes:
We provide pip wheels for all major OS/PyTorch/CUDA combinations. Note that we highly recommend Windows users refer to Installation via source code due to compatibility.
Note that >=1.6.0 is ok.
$ python -c "import torch; print(torch.__version__)"
>>> 1.6.0
$ python -c "import torch; print(torch.version.cuda)"
>>> 10.2
torchtext is needed since Graph4NLP relies on it to implement embeddings.
Please pay attention to the PyTorch requirements before installing torchtext with the following script! For detailed version matching please refer here.
pip install torchtext # >=0.7.0