
Graph4NLPは、グラフと自然言語処理(つまり、DLG4NLP)の深い学習の交差点で、R&Dの使いやすいライブラリです。データサイエンティスト向けの最先端モデルの完全な実装と、パイプライン全体のサポートを備えた研究者と開発者向けのカスタマイズされたモデルを構築するための柔軟なインターフェイスの両方を提供します。 DGLを含む高度に最適化されたランタイムライブラリに基づいて構築されたGraph4NLPは、ランニング効率が高いと大きな拡張性の両方を持っています。 graph4nlpのアーキテクチャは、次の図に示されています。ここでは、破線のあるボックスが開発中の機能を表します。 GRAPH4NLPは、4つの異なるレイヤーで構成されています。1)データレイヤー、2)モジュールレイヤー、3)モデルレイヤー、4)アプリケーションレイヤー。

図:Graph4NLP全体的なアーキテクチャ
01/20/2022: V0.5.5リリース。試してみてください!
09/26/2021: V0.5.1リリース。試してみてください!
09/01/2021:さまざまな学習リソースについては、 dlg4nlpのWebサイト(https://dlg4nlp.github.io/index.html)をご覧ください!
06/05/2021: V0.4.1リリース。
| リリース | 日付 | 特徴 |
|---|---|---|
| V0.5.5 | 2022-01-20 | - ラッパー関数を導入して、Model.predict APIをサポートします。 -3つの新しいincrence_wrapper関数を紹介します:classifier_inference_wrapper、generator_inference_wrapper、generator_inference_wrapper_for_tree。 - 各アプリケーションに推論とInference_Advanceの例を追加します。 - グラフトポロジとグラフ埋め込みプロセスを分離します。 - すべてのグラフ構造機能を更新します。 -odule graph_embeddingは、graph_embedding_initializationとgraph_embedding_learningに分割されます。 - データセットのパラメーターを統合します。あいまいなパラメーター graph_typeを削除し、 graph_nameを導入してグラフ構造方法とstatic_or_dynamicを示して、静的または動的グラフ構造タイプを示します。- 新規:データセットは、1つのパラメーター graph_nameのみでデフォルトメソッド( topology_builderなど)を自動的に選択できるようになりました。 |
| V0.5.1 | 2021-09-26 | - コードを癒します - ユーザー自身のデータでテストをサポートします - バグの修正:埋め込みサイズという単語は、0.4.1バージョンでハードコーディングされました。これで、「word_emb_size」パラメーターに等しくなります。 - バグの修正:build_vocab()は、0.4.1バージョンで2回呼び出されます。 - バグの修正:知識の2つのファイルグラフ完了の例は、モデルのトレーニングを再開するときに、ランキング_and_hits()のオプションパラメーター「kg_graph」を逃しました。 - バグの修正:KGC READMEの前処理パスエラーを修正しました。 - バグの修正:emb_strategyを「w2v」に設定するときに、埋め込みバグを修正しました。 |
| v0.4.1 | 2021-06-05 | - グラフ4nlpのパイプライン全体をサポートします -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アプリケーションの包括的なコレクションと、次のような詳細な例を提供します。
環境:トーチ1.8、ubuntu 16.04 2080ti gpus
| タスク | データセット | GNNモデル | グラフ構造 | 評価 | パフォーマンス |
|---|---|---|---|---|---|
| テキスト分類 | トレクト ケアライン CNSST | ガット | 依存 選挙区 依存 | 正確さ | 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の組み合わせにピップホイールを提供します。互換性があるため、 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を参照してください。
| プラットフォーム | 指示 |
|---|---|
| CPU | 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 (またはWindows 10を使用している場合は./configure.bat )を実行して、インストールを構成します。 Configurationプログラムでは、CUDAバージョンを指定するように求められます。 GPUがない場合は、「CPU」と入力してください。
./configure最後に、パッケージをインストールします。
python setup.py installここでよく調整されるハイパーパラメーターのいくつかを示します。
NLPタスクにグラフテクニックにディープラーニングを適用することについて詳しく学びたい場合は、DLG4NLP Webサイト(https://dlg4nlp.github.io/index.html)にアクセスしてください。この既存の研究方向の概要を提供する調査論文を参照できます。ライブラリへの詳細な参照が必要な場合は、ドキュメントを参照してください。
バグに遭遇した場合、または問題を提出して提案がある場合はお知らせください。
バグ修正から新機能や拡張機能へのすべての貢献を歓迎します。
Issue Trackerおよび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(Xiaojie Guo)、Tongji University(Hanning gau)、Sakhuchiming(shanjing Universit(shanjing)などのさまざまな産業および学術グループの大学院生で構成されています。王)。
技術的な質問がある場合は、新しい問題を提出してください。
他にご質問がある場合は、 LingfeiWu [[email protected]]およびxiaojie guo [[email protected]]にお問い合わせください。
Graph4NLPはApacheライセンス2.0を使用します。