
Graph4NLP是在图形和自然语言处理的深度学习(即DLG4NLP)的交点上易于使用的库。它既可以为数据科学家提供完整的最先进模型,也提供了灵活的界面,以为具有全层线支持的研究人员和开发人员构建定制模型。 Graph4NLP建立在包括DGL在内的高度优化的运行时库,既具有较高的运行效率又具有巨大的可扩展性。 Graph4NLP的体系结构如下图所示,其中虚线的框表示开发的功能。 Graph4NLP由四个不同的层组成:1)数据层,2)模块层,3)模型层和4)应用层。

图:Graph4NLP整体体系结构
01/20/2022: V0.5.5版本。尝试一下!
09/26/2021: V0.5.1版本。尝试一下!
09/01/2021:欢迎访问我们的DLG4NLP网站(https://dlg4nlp.github.io/index.html),以获取各种学习资源!
06/05/2021: V0.4.1版本。
| 发行 | 日期 | 特征 |
|---|---|---|
| v0.5.5 | 2022-01-20 | - 支持模型。通过引入包装器功能来预测API。 - 介绍三个新的inperion_wrapper函数:classifier_inference_wrapper,generator_inferender_wrapper,generator_inferentor_wrapper_for_tree。 - 在每个应用程序中添加推理和推理示例。 - 分开图形拓扑结构和图形嵌入过程。 - 更新所有图形构造功能。 - 模块graph_embedding分为graph_embedding_initialization和graph_embedding_learning。 - 统一数据集中的参数。我们删除模棱两可的参数 graph_type并介绍graph_name来指示图形构造方法和static_or_dynamic指示静态或动态图形构造类型。- 新:数据集现在只能通过一个参数 graph_name自动选择默认方法(例如, topology_builder )。 |
| v0.5.1 | 2021-09-26 | - 索具 - 用用户自己的数据支持测试 - 修复错误:嵌入式大小在0.4.1版本中进行了硬编码。现在它等于“ word_emb_size”参数。 - 修复错误:build_vocab()在0.4.1版本中被称为两次。 - 修复错误:知识图完成的两个主要文件示例示例错过了reking_and_hits()中的可选参数“ kg_graph”。 - 修复错误:我们已经修复了kgc readme中的预处理路径错误。 - 修复错误:将EMB_STRATEGY设置为“ W2V”时,我们已经修复了嵌入式构造错误。 |
| v0.4.1 | 2021-06-05 | - 支持Graph4NLP的整个管道 - GraphData和数据集支持 |
Graph4NLP旨在使在NLP任务中使用GNN非常容易(查看Graph4NLP文档)。这是如何使用Graph2Seq模型的示例(广泛用于机器翻译,问答,语义解析以及可以将其抽象为图形到序列问题的各种其他NLP任务,并显示出卓越的性能)。
我们还提供其他高级模型API,例如图形模型。如果您对DLG4NLP相关的研究问题感兴趣,欢迎您使用我们的图书馆并参考我们的Graph4NLP调查。
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] 我们的Graph4NLP计算流如下所示。

我们提供了NLP应用程序的全面集合,以及以下详细示例:
环境:Torch 1.8,Ubuntu 16.04与2080TI GPU
| 任务 | 数据集 | GNN模型 | 图形结构 | 评估 | 表现 |
|---|---|---|---|---|---|
| 文本分类 | trect 开cairline cnsst | GAT | 依赖性 选区 依赖性 | 准确性 | 0.948 0.785 0.538 |
| 语义解析 | 工作 | 圣人 | 选区 | 执行精度 | 0.936 |
| 问题产生 | 队 | GGNN | 依赖性 | bleu-4 | 0.15175 |
| 机器翻译 | IWSLT14 | GCN | 动态的 | bleu-4 | 0.3212 |
| 摘要 | CNN(30K) | GCN | 依赖性 | Rouge-1 | 26.4 |
| 知识图完成 | 亲属关系 | GCN | 依赖性 | MRR | 82.4 |
| 数学单词问题 | mawps | 圣人 | 动态的 | 解决方案准确性 | 76.4 |
当前,用户可以通过PIP或源代码安装Graph4NLP。 Graph4NLP支持以下OS:
我们为所有主要的OS/Pytorch/CUDA组合提供PIP轮。请注意,由于兼容性,我们强烈建议Windows用户参考Installation via source code 。
请注意, >=1.6.0是可以的。
$ python -c " import torch; print(torch.__version__) "
>>> 1.6.0$ python -c " import torch; print(torch.version.cuda) "
>>> 10.2由于Graph4NLP依靠它来实现嵌入,因此需要torchtext 。在使用以下脚本安装torchtext之前,请注意Pytorch的要求!有关匹配的详细版本,请参考此处。
pip install torchtext # >=0.7.0 pip install graph4nlp ${CUDA}其中${CUDA}应由特定的CUDA版本( none (CPU版本), "-cu92" , "-cu101" , "-cu102" , "-cu110" )代替。下表显示了混凝土命令行。对于CUDA 11.1用户,请参考Installation via source code 。
| 平台 | 命令 |
|---|---|
| 中央处理器 | pip install graph4nlp |
| CUDA 9.2 | pip install graph4nlp-cu92 |
| CUDA 10.1 | pip install graph4nlp-cu101 |
| CUDA 10.2 | pip install graph4nlp-cu102 |
| CUDA 11.0 | pip install graph4nlp-cu110 |
请注意, >=1.6.0是可以的。
$ python -c " import torch; print(torch.__version__) "
>>> 1.6.0$ python -c " import torch; print(torch.version.cuda) "
>>> 10.2由于Graph4NLP依靠它来实现嵌入,因此需要torchtext 。在使用以下脚本安装torchtext之前,请注意Pytorch的要求!有关匹配的详细版本,请参考此处。
pip install torchtext # >=0.7.0 Graph4NLP的源代码: git clone https://github.com/graph4ai/graph4nlp.git
cd graph4nlp然后运行./configure (或./configure.bat (如果使用Windows 10)来配置安装。配置程序将要求您指定您的CUDA版本。如果您没有GPU,请键入“ CPU”。
./configure最后,安装软件包:
python setup.py install我们显示了一些经常在此处调整的超参数。
如果您想了解有关将图形技术应用于NLP任务的更多信息,请访问我们的DLG4NLP网站(https://dlg4nlp.github.io/index.html)获取各种学习资源!您可以参考我们的调查论文,概述了这个现有的研究方向。如果您想详细提及我们的图书馆,请参考我们的文档。
如果您遇到错误或提出问题,请告诉我们是否有任何建议。
我们欢迎从错误修复到新功能和扩展的所有贡献。
我们希望在问题跟踪器中讨论所有贡献并进行PRS。
如果您发现此代码有用,请考虑引用以下论文。
@article{wu2021graph,
title={Graph Neural Networks for Natural Language Processing: A Survey},
author={Lingfei Wu and Yu Chen and Kai Shen and Xiaojie Guo and Hanning Gao and Shucheng Li and Jian Pei and Bo Long},
journal={arXiv preprint arXiv:2106.06090},
year={2021}
}
@inproceedings{chen2020iterative,
title={Iterative Deep Graph Learning for Graph Neural Networks: Better and Robust Node Embeddings},
author={Chen, Yu and Wu, Lingfei and Zaki, Mohammed J},
booktitle={Proceedings of the 34th Conference on Neural Information Processing Systems},
month={Dec. 6-12,},
year={2020}
}
@inproceedings{chen2020reinforcement,
author = {Chen, Yu and Wu, Lingfei and Zaki, Mohammed J.},
title = {Reinforcement Learning Based Graph-to-Sequence Model for Natural Question Generation},
booktitle = {Proceedings of the 8th International Conference on Learning Representations},
month = {Apr. 26-30,},
year = {2020}
}
@article{xu2018graph2seq,
title={Graph2seq: Graph to sequence learning with attention-based neural networks},
author={Xu, Kun and Wu, Lingfei and Wang, Zhiguo and Feng, Yansong and Witbrock, Michael and Sheinin, Vadim},
journal={arXiv preprint arXiv:1804.00823},
year={2018}
}
@inproceedings{li-etal-2020-graph-tree,
title = {Graph-to-Tree Neural Networks for Learning Structured Input-Output Translation with Applications to Semantic Parsing and Math Word Problem},
author = {Li, Shucheng and
Wu, Lingfei and
Feng, Shiwei and
Xu, Fangli and
Xu, Fengyuan and
Zhong, Sheng},
booktitle = {Findings of the Association for Computational Linguistics: EMNLP 2020},
month = {Nov},
year = {2020}
}
@inproceedings{huang-etal-2020-knowledge,
title = {Knowledge Graph-Augmented Abstractive Summarization with Semantic-Driven Cloze Reward},
author = {Huang, Luyang and
Wu, Lingfei and
Wang, Lu},
booktitle = {Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics},
month = {Jul},
year = {2020},
pages = {5094--5107}
}
@inproceedings{wu-etal-2018-word,
title = {Word Mover{'}s Embedding: From {W}ord2{V}ec to Document Embedding},
author = {Wu, Lingfei and
Yen, Ian En-Hsu and
Xu, Kun and
Xu, Fangli and
Balakrishnan, Avinash and
Chen, Pin-Yu and
Ravikumar, Pradeep and
Witbrock, Michael J.},
booktitle = {Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing},
pages = {4524--4534},
year = {2018},
}
@inproceedings{chen2020graphflow,
author = {Yu Chen and
Lingfei Wu and
Mohammed J. Zaki},
title = {GraphFlow: Exploiting Conversation Flow with Graph Neural Networks
for Conversational Machine Comprehension},
booktitle = {Proceedings of the Twenty-Ninth International Joint Conference on
Artificial Intelligence, {IJCAI} 2020},
publisher = {International Joint Conferences on Artificial Intelligence Organization},
pages = {1230--1236},
year = {2020}
}
@inproceedings{shen2020hierarchical,
title={Hierarchical Attention Based Spatial-Temporal Graph-to-Sequence Learning for Grounded Video Description},
author={Shen, Kai and Wu, Lingfei and Xu, Fangli and Tang, Siliang and Xiao, Jun and Zhuang, Yueting},
booktitle = {Proceedings of the Twenty-Ninth International Joint Conference on
Artificial Intelligence, {IJCAI} 2020},
publisher = {International Joint Conferences on Artificial Intelligence Organization},
pages = {941--947},
year = {2020}
}
@inproceedings{ijcai2020-419,
title = {RDF-to-Text Generation with Graph-augmented Structural Neural Encoders},
author = {Gao, Hanning and Wu, Lingfei and Hu, Po and Xu, Fangli},
booktitle = {Proceedings of the Twenty-Ninth International Joint Conference on
Artificial Intelligence, {IJCAI-20}},
publisher = {International Joint Conferences on Artificial Intelligence Organization},
pages = {3030--3036},
year = {2020}
}
Graph4ai团队: Lingfei Wu (团队负责人),Yu Chen,Kai Shen,Xiaojie Guo,Hanning Gao,Shucheng Li,Saizhuo Wang,Xiao Liu和Jing Hu。我们热衷于开发有用的开源库,旨在促进在自然语言处理上轻松利用各种深度学习。我们的团队包括研究科学家,应用数据科学家以及来自各种工业和学术团体的研究生,包括Pinterest(Lingfei Wu),Zhejiang University(Kai Shen),Facebook AI(Yu Chen),IBM TJ Watson Research Center(Yu chen)王)。
如果您有任何技术问题,请提交新问题。
如果您还有其他疑问,请与我们联系: lingfei wu [[email protected]]和xiaojie guo [[email protected]] 。
Graph4NLP使用Apache许可证2.0。