
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。