From 0ad3a7f0dd974c8b4ee8feaec331e9a74ed6c8be Mon Sep 17 00:00:00 2001 From: Meiyim Date: Thu, 4 Jun 2020 19:18:36 +0800 Subject: [PATCH] Update setup.py (#484) * Update setup.py * reorganize seq2seq * update lac dependency --- {experimental => demo}/seq2seq/README.md | 0 {experimental => demo}/seq2seq/decode.py | 3 +- .../seq2seq/eval_cnndm/cnndm/__init__.py | 0 .../seq2seq/eval_cnndm/cnndm/bs_pyrouge.py | 0 .../seq2seq/eval_cnndm/cnndm/eval.py | 0 .../seq2seq/eval_cnndm/cnndm_eval.sh | 0 .../seq2seq/eval_cnndm/file2rouge/README.txt | 0 .../eval_cnndm/file2rouge/RELEASE-NOTE.txt | 0 .../eval_cnndm/file2rouge/ROUGE-1.5.5.pl | 0 .../seq2seq/eval_cnndm/file2rouge/XML/DOM.pm | 0 .../eval_cnndm/file2rouge/XML/DOM/AttDef.pod | 0 .../file2rouge/XML/DOM/AttlistDecl.pod | 0 .../eval_cnndm/file2rouge/XML/DOM/Attr.pod | 0 .../file2rouge/XML/DOM/CDATASection.pod | 0 .../file2rouge/XML/DOM/CharacterData.pod | 0 .../eval_cnndm/file2rouge/XML/DOM/Comment.pod | 0 .../file2rouge/XML/DOM/DOMException.pm | 0 .../file2rouge/XML/DOM/DOMImplementation.pod | 0 .../file2rouge/XML/DOM/Document.pod | 0 .../file2rouge/XML/DOM/DocumentFragment.pod | 0 .../file2rouge/XML/DOM/DocumentType.pod | 0 .../eval_cnndm/file2rouge/XML/DOM/Element.pod | 0 .../file2rouge/XML/DOM/ElementDecl.pod | 0 .../eval_cnndm/file2rouge/XML/DOM/Entity.pod | 0 .../file2rouge/XML/DOM/EntityReference.pod | 0 .../file2rouge/XML/DOM/NamedNodeMap.pm | 0 .../file2rouge/XML/DOM/NamedNodeMap.pod | 0 .../eval_cnndm/file2rouge/XML/DOM/Node.pod | 0 .../eval_cnndm/file2rouge/XML/DOM/NodeList.pm | 0 .../file2rouge/XML/DOM/NodeList.pod | 0 .../file2rouge/XML/DOM/Notation.pod | 0 .../eval_cnndm/file2rouge/XML/DOM/Parser.pod | 0 .../eval_cnndm/file2rouge/XML/DOM/PerlSAX.pm | 0 .../XML/DOM/ProcessingInstruction.pod | 0 .../eval_cnndm/file2rouge/XML/DOM/Text.pod | 0 .../eval_cnndm/file2rouge/XML/DOM/XMLDecl.pod | 0 .../file2rouge/XML/Handler/BuildDOM.pm | 0 .../eval_cnndm/file2rouge/XML/RegExp.pm | 0 .../data/WordNet-1.6-Exceptions/adj.exc | 0 .../data/WordNet-1.6-Exceptions/adv.exc | 0 .../WordNet-1.6-Exceptions/buildExeptionDB.pl | 0 .../data/WordNet-1.6-Exceptions/noun.exc | 0 .../data/WordNet-1.6-Exceptions/verb.exc | 0 .../data/WordNet-2.0-Exceptions/adj.exc | 0 .../data/WordNet-2.0-Exceptions/adv.exc | 0 .../WordNet-2.0-Exceptions/buildExeptionDB.pl | 0 .../data/WordNet-2.0-Exceptions/noun.exc | 0 .../data/WordNet-2.0-Exceptions/verb.exc | 0 .../file2rouge/data/WordNet-2.0.exc.db | Bin .../file2rouge/data/smart_common_words.txt | 0 .../eval_cnndm/file2rouge/runROUGE-test.pl | 0 .../eval_cnndm/pyrouge_set_rouge_path.py | 0 .../seq2seq/finetune_seq2seq_dygraph.py | 3 +- ernie/modeling_ernie.py | 78 +++++++++++++++- experimental/seq2seq | 1 + experimental/seq2seq/modeling_ernie_gen.py | 87 ------------------ requirements.txt | 1 + setup.py | 2 +- 58 files changed, 82 insertions(+), 93 deletions(-) rename {experimental => demo}/seq2seq/README.md (100%) rename {experimental => demo}/seq2seq/decode.py (99%) rename {experimental => demo}/seq2seq/eval_cnndm/cnndm/__init__.py (100%) rename {experimental => demo}/seq2seq/eval_cnndm/cnndm/bs_pyrouge.py (100%) rename {experimental => demo}/seq2seq/eval_cnndm/cnndm/eval.py (100%) rename {experimental => demo}/seq2seq/eval_cnndm/cnndm_eval.sh (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/README.txt (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/RELEASE-NOTE.txt (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/ROUGE-1.5.5.pl (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM.pm (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/AttDef.pod (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/AttlistDecl.pod (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/Attr.pod (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/CDATASection.pod (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/CharacterData.pod (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/Comment.pod (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/DOMException.pm (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/DOMImplementation.pod (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/Document.pod (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/DocumentFragment.pod (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/DocumentType.pod (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/Element.pod (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/ElementDecl.pod (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/Entity.pod (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/EntityReference.pod (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/NamedNodeMap.pm (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/NamedNodeMap.pod (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/Node.pod (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/NodeList.pm (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/NodeList.pod (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/Notation.pod (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/Parser.pod (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/PerlSAX.pm (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/ProcessingInstruction.pod (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/Text.pod (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/DOM/XMLDecl.pod (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/Handler/BuildDOM.pm (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/XML/RegExp.pm (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/adj.exc (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/adv.exc (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/buildExeptionDB.pl (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/noun.exc (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/verb.exc (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/adj.exc (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/adv.exc (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/buildExeptionDB.pl (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/noun.exc (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/verb.exc (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0.exc.db (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/data/smart_common_words.txt (100%) rename {experimental => demo}/seq2seq/eval_cnndm/file2rouge/runROUGE-test.pl (100%) rename {experimental => demo}/seq2seq/eval_cnndm/pyrouge_set_rouge_path.py (100%) rename {experimental => demo}/seq2seq/finetune_seq2seq_dygraph.py (99%) create mode 120000 experimental/seq2seq delete mode 100644 experimental/seq2seq/modeling_ernie_gen.py diff --git a/experimental/seq2seq/README.md b/demo/seq2seq/README.md similarity index 100% rename from experimental/seq2seq/README.md rename to demo/seq2seq/README.md diff --git a/experimental/seq2seq/decode.py b/demo/seq2seq/decode.py similarity index 99% rename from experimental/seq2seq/decode.py rename to demo/seq2seq/decode.py index 49155e9..2ea427b 100644 --- a/experimental/seq2seq/decode.py +++ b/demo/seq2seq/decode.py @@ -30,11 +30,10 @@ import paddle.fluid as F import paddle.fluid.layers as L import paddle.fluid.dygraph as D -from ernie.modeling_ernie import ErnieModel, ErnieModelForPretraining +from ernie.modeling_ernie import ErnieModel, ErnieModelForPretraining, ErnieModelForGeneration from ernie.modeling_ernie import _build_linear, _build_ln, append_name from ernie.tokenizing_ernie import ErnieTokenizer -from experimental.seq2seq.modeling_ernie_gen import ErnieModelForGeneration from propeller import log import propeller.paddle as propeller diff --git a/experimental/seq2seq/eval_cnndm/cnndm/__init__.py b/demo/seq2seq/eval_cnndm/cnndm/__init__.py similarity index 100% rename from experimental/seq2seq/eval_cnndm/cnndm/__init__.py rename to demo/seq2seq/eval_cnndm/cnndm/__init__.py diff --git a/experimental/seq2seq/eval_cnndm/cnndm/bs_pyrouge.py b/demo/seq2seq/eval_cnndm/cnndm/bs_pyrouge.py similarity index 100% rename from experimental/seq2seq/eval_cnndm/cnndm/bs_pyrouge.py rename to demo/seq2seq/eval_cnndm/cnndm/bs_pyrouge.py diff --git a/experimental/seq2seq/eval_cnndm/cnndm/eval.py b/demo/seq2seq/eval_cnndm/cnndm/eval.py similarity index 100% rename from experimental/seq2seq/eval_cnndm/cnndm/eval.py rename to demo/seq2seq/eval_cnndm/cnndm/eval.py diff --git a/experimental/seq2seq/eval_cnndm/cnndm_eval.sh b/demo/seq2seq/eval_cnndm/cnndm_eval.sh similarity index 100% rename from experimental/seq2seq/eval_cnndm/cnndm_eval.sh rename to demo/seq2seq/eval_cnndm/cnndm_eval.sh diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/README.txt b/demo/seq2seq/eval_cnndm/file2rouge/README.txt similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/README.txt rename to demo/seq2seq/eval_cnndm/file2rouge/README.txt diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/RELEASE-NOTE.txt b/demo/seq2seq/eval_cnndm/file2rouge/RELEASE-NOTE.txt similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/RELEASE-NOTE.txt rename to demo/seq2seq/eval_cnndm/file2rouge/RELEASE-NOTE.txt diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/ROUGE-1.5.5.pl b/demo/seq2seq/eval_cnndm/file2rouge/ROUGE-1.5.5.pl similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/ROUGE-1.5.5.pl rename to demo/seq2seq/eval_cnndm/file2rouge/ROUGE-1.5.5.pl diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM.pm b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM.pm similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM.pm rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM.pm diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/AttDef.pod b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/AttDef.pod similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/AttDef.pod rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/AttDef.pod diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/AttlistDecl.pod b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/AttlistDecl.pod similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/AttlistDecl.pod rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/AttlistDecl.pod diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/Attr.pod b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/Attr.pod similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/Attr.pod rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/Attr.pod diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/CDATASection.pod b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/CDATASection.pod similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/CDATASection.pod rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/CDATASection.pod diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/CharacterData.pod b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/CharacterData.pod similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/CharacterData.pod rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/CharacterData.pod diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/Comment.pod b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/Comment.pod similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/Comment.pod rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/Comment.pod diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/DOMException.pm b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/DOMException.pm similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/DOMException.pm rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/DOMException.pm diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/DOMImplementation.pod b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/DOMImplementation.pod similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/DOMImplementation.pod rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/DOMImplementation.pod diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/Document.pod b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/Document.pod similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/Document.pod rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/Document.pod diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/DocumentFragment.pod b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/DocumentFragment.pod similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/DocumentFragment.pod rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/DocumentFragment.pod diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/DocumentType.pod b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/DocumentType.pod similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/DocumentType.pod rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/DocumentType.pod diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/Element.pod b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/Element.pod similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/Element.pod rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/Element.pod diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/ElementDecl.pod b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/ElementDecl.pod similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/ElementDecl.pod rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/ElementDecl.pod diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/Entity.pod b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/Entity.pod similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/Entity.pod rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/Entity.pod diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/EntityReference.pod b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/EntityReference.pod similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/EntityReference.pod rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/EntityReference.pod diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/NamedNodeMap.pm b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/NamedNodeMap.pm similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/NamedNodeMap.pm rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/NamedNodeMap.pm diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/NamedNodeMap.pod b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/NamedNodeMap.pod similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/NamedNodeMap.pod rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/NamedNodeMap.pod diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/Node.pod b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/Node.pod similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/Node.pod rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/Node.pod diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/NodeList.pm b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/NodeList.pm similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/NodeList.pm rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/NodeList.pm diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/NodeList.pod b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/NodeList.pod similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/NodeList.pod rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/NodeList.pod diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/Notation.pod b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/Notation.pod similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/Notation.pod rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/Notation.pod diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/Parser.pod b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/Parser.pod similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/Parser.pod rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/Parser.pod diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/PerlSAX.pm b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/PerlSAX.pm similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/PerlSAX.pm rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/PerlSAX.pm diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/ProcessingInstruction.pod b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/ProcessingInstruction.pod similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/ProcessingInstruction.pod rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/ProcessingInstruction.pod diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/Text.pod b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/Text.pod similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/Text.pod rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/Text.pod diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/XMLDecl.pod b/demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/XMLDecl.pod similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/DOM/XMLDecl.pod rename to demo/seq2seq/eval_cnndm/file2rouge/XML/DOM/XMLDecl.pod diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/Handler/BuildDOM.pm b/demo/seq2seq/eval_cnndm/file2rouge/XML/Handler/BuildDOM.pm similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/Handler/BuildDOM.pm rename to demo/seq2seq/eval_cnndm/file2rouge/XML/Handler/BuildDOM.pm diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/XML/RegExp.pm b/demo/seq2seq/eval_cnndm/file2rouge/XML/RegExp.pm similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/XML/RegExp.pm rename to demo/seq2seq/eval_cnndm/file2rouge/XML/RegExp.pm diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/adj.exc b/demo/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/adj.exc similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/adj.exc rename to demo/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/adj.exc diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/adv.exc b/demo/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/adv.exc similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/adv.exc rename to demo/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/adv.exc diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/buildExeptionDB.pl b/demo/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/buildExeptionDB.pl similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/buildExeptionDB.pl rename to demo/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/buildExeptionDB.pl diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/noun.exc b/demo/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/noun.exc similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/noun.exc rename to demo/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/noun.exc diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/verb.exc b/demo/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/verb.exc similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/verb.exc rename to demo/seq2seq/eval_cnndm/file2rouge/data/WordNet-1.6-Exceptions/verb.exc diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/adj.exc b/demo/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/adj.exc similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/adj.exc rename to demo/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/adj.exc diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/adv.exc b/demo/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/adv.exc similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/adv.exc rename to demo/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/adv.exc diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/buildExeptionDB.pl b/demo/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/buildExeptionDB.pl similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/buildExeptionDB.pl rename to demo/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/buildExeptionDB.pl diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/noun.exc b/demo/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/noun.exc similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/noun.exc rename to demo/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/noun.exc diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/verb.exc b/demo/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/verb.exc similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/verb.exc rename to demo/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0-Exceptions/verb.exc diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0.exc.db b/demo/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0.exc.db similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0.exc.db rename to demo/seq2seq/eval_cnndm/file2rouge/data/WordNet-2.0.exc.db diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/data/smart_common_words.txt b/demo/seq2seq/eval_cnndm/file2rouge/data/smart_common_words.txt similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/data/smart_common_words.txt rename to demo/seq2seq/eval_cnndm/file2rouge/data/smart_common_words.txt diff --git a/experimental/seq2seq/eval_cnndm/file2rouge/runROUGE-test.pl b/demo/seq2seq/eval_cnndm/file2rouge/runROUGE-test.pl similarity index 100% rename from experimental/seq2seq/eval_cnndm/file2rouge/runROUGE-test.pl rename to demo/seq2seq/eval_cnndm/file2rouge/runROUGE-test.pl diff --git a/experimental/seq2seq/eval_cnndm/pyrouge_set_rouge_path.py b/demo/seq2seq/eval_cnndm/pyrouge_set_rouge_path.py similarity index 100% rename from experimental/seq2seq/eval_cnndm/pyrouge_set_rouge_path.py rename to demo/seq2seq/eval_cnndm/pyrouge_set_rouge_path.py diff --git a/experimental/seq2seq/finetune_seq2seq_dygraph.py b/demo/seq2seq/finetune_seq2seq_dygraph.py similarity index 99% rename from experimental/seq2seq/finetune_seq2seq_dygraph.py rename to demo/seq2seq/finetune_seq2seq_dygraph.py index 44ee4fd..f9ddebc 100644 --- a/experimental/seq2seq/finetune_seq2seq_dygraph.py +++ b/demo/seq2seq/finetune_seq2seq_dygraph.py @@ -32,13 +32,12 @@ import paddle.fluid.dygraph as D from tqdm import tqdm -from ernie.modeling_ernie import ErnieModel, ErnieModelForPretraining +from ernie.modeling_ernie import ErnieModel, ErnieModelForPretraining, ErnieModelForGeneration from ernie.modeling_ernie import _build_linear, _build_ln, append_name from ernie.tokenizing_ernie import ErnieTokenizer from ernie.optimization import AdamW, LinearDecay from experimental.seq2seq.decode import beam_search_infilling, post_process -from experimental.seq2seq.modeling_ernie_gen import ErnieModelForGeneration from propeller import log import propeller.paddle as propeller diff --git a/ernie/modeling_ernie.py b/ernie/modeling_ernie.py index b3b3bbe..c9e16a3 100644 --- a/ernie/modeling_ernie.py +++ b/ernie/modeling_ernie.py @@ -298,6 +298,8 @@ class ErnieModel(D.Layer, PretrainedModel): output logits of pooler classifier encoded(`Variable` of shape `[batch_size, seq_len, hidden_size]`): output logits of transformer stack + info (Dictionary): + addtional middle level info, inclues: all hidden stats, k/v caches. """ #d_batch, d_seqlen = src_ids.shape assert len(src_ids.shape) == 2, 'expect src_ids.shape = [batch, sequecen], got %s' % (repr(src_ids.shape)) @@ -551,7 +553,7 @@ class ErnieModelForPretraining(ErnieModel): nsp_labels (optional, `Variable` of shape [batch_size]): labels for `next sentence prediction` tasks mlm_pos (optional, `Variable` of shape [n_mask, 2]): - index of mask_id in `src_ids`, can obtain from `fluid.layers.where(src_ids==mask_id)` + index of mask_id in `src_ids`, can be obtained from `fluid.layers.where(src_ids==mask_id)` labels (optional, `Variable` of shape [n_mask]): labels for `mask language model` tasks, the original token indices in masked position in `src_ids` Returns: @@ -582,3 +584,77 @@ class ErnieModelForPretraining(ErnieModel): total_loss = mlm_loss + nsp_loss return total_loss, mlm_loss, nsp_loss + +class ErnieModelForGeneration(ErnieModel): + """ + Ernie Model for sequence to sequence generation. + """ + resource_map = { + 'ernie-gen-base-en': ErnieModel.bce + 'model-ernie-gen-base-en.1.tar.gz', + 'ernie-gen-large-en': ErnieModel.bce + 'model-ernie-gen-large-en.1.tar.gz', + 'ernie-gen-large-160g-en': ErnieModel.bce + 'model-ernie-gen-large-160g-en.1.tar.gz', + 'ernie-1.0': ErnieModel.bce + 'model-ernie1.0.1.tar.gz', + } + def __init__(self, cfg, name=None): + cfg['return_additional_info'] = True + cfg['has_pooler'] = False + super(ErnieModelForGeneration, self).__init__(cfg, name=name) + initializer = F.initializer.TruncatedNormal(scale=cfg['initializer_range']) + d_model = cfg['hidden_size'] + d_vocab = cfg['vocab_size'] + + self.mlm = _build_linear(d_model, d_model, append_name(name, 'mask_lm_trans_fc'), initializer, act=cfg['hidden_act']) + self.mlm_ln = _build_ln(d_model, name = append_name(name, 'mask_lm_trans')) + self.mlm_bias = L.create_parameter( + dtype='float32', + shape=[d_vocab], + attr=F.ParamAttr( + name=append_name(name, 'mask_lm_out_fc.b_0'), + initializer=F.initializer.Constant(value=0.0) + ), + is_bias=True, + ) + + @add_docstring(ErnieModel.forward.__doc__) + def forward(self, *args, **kwargs): + """ + Args + tgt_labels(`Variable` of shape [batch_size, seqlen] or [batch, seqlen, vocab_size]): + ground trouth target sequence id (hard label) or distribution (soft label) + tgt_pos(`Variable` of shape [n_targets, 2]): + index of tgt_labels in `src_ids`, can be obtained from `fluid.layers.where(src_ids==mask_id)` + encoder_only(Bool): + if set, will not return loss, logits_2d + Returns: + loss(`Variable` of shape []): + cross entropy loss mean over every target label. if `encode_only`, returns None. + logits(`Variable` of shape [n_targets, vocab_size]): + logits for every targets. if `encode_only`, returns None. + info(Dictionary): see `ErnieModel` + """ + tgt_labels = kwargs.pop('tgt_labels', None) + tgt_pos = kwargs.pop('tgt_pos', None) + encode_only = kwargs.pop('encode_only', False) + _, encoded, info = ErnieModel.forward(self, *args, **kwargs) + if encode_only: + return None, None, info + elif tgt_labels is None or tgt_pos is None: + encoded = self.mlm(encoded) + encoded = self.mlm_ln(encoded) + logits = L.matmul(encoded, self.word_emb.weight, transpose_y=True) + self.mlm_bias + output_ids = L.argmax(logits, -1) + return output_ids, logits, info + else: + encoded_2d = L.gather_nd(encoded, tgt_pos) + encoded_2d = self.mlm(encoded_2d) + encoded_2d = self.mlm_ln(encoded_2d) + logits_2d = L.matmul(encoded_2d, self.word_emb.weight, transpose_y=True) + self.mlm_bias + if len(tgt_labels.shape) == 1: + tgt_labels = L.reshape(tgt_labels, [-1, 1]) + + loss = L.reduce_mean( + L.softmax_with_cross_entropy(logits_2d, tgt_labels, soft_label=(tgt_labels.shape[-1] != 1)) + ) + return loss, logits_2d, info + + diff --git a/experimental/seq2seq b/experimental/seq2seq new file mode 120000 index 0000000..390e351 --- /dev/null +++ b/experimental/seq2seq @@ -0,0 +1 @@ +../demo/seq2seq \ No newline at end of file diff --git a/experimental/seq2seq/modeling_ernie_gen.py b/experimental/seq2seq/modeling_ernie_gen.py deleted file mode 100644 index 06c2a6d..0000000 --- a/experimental/seq2seq/modeling_ernie_gen.py +++ /dev/null @@ -1,87 +0,0 @@ -# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import division -from __future__ import absolute_import -from __future__ import print_function -from __future__ import unicode_literals - -import sys -import logging -import numpy as np - -import paddle.fluid as F -import paddle.fluid.layers as L -import paddle.fluid.dygraph as D - -from ernie.modeling_ernie import ErnieModel -from ernie.modeling_ernie import _build_linear, _build_ln, append_name - -class ErnieModelForGeneration(ErnieModel): - resource_map = { - 'ernie-gen-base-en': ErnieModel.bce + 'model-ernie-gen-base-en.1.tar.gz', - 'ernie-gen-large-en': ErnieModel.bce + 'model-ernie-gen-large-en.1.tar.gz', - 'ernie-gen-large-160g-en': ErnieModel.bce + 'model-ernie-gen-large-160g-en.1.tar.gz', - 'ernie-1.0': ErnieModel.bce + 'model-ernie1.0.1.tar.gz', - } - def __init__(self, cfg, name=None): - cfg['return_additional_info'] = True - cfg['has_pooler'] = False - super(ErnieModelForGeneration, self).__init__(cfg, name=name) - initializer = F.initializer.TruncatedNormal(scale=cfg['initializer_range']) - d_model = cfg['hidden_size'] - d_vocab = cfg['vocab_size'] - - self.mlm = _build_linear(d_model, d_model, append_name(name, 'mask_lm_trans_fc'), initializer, act=cfg['hidden_act']) - self.mlm_ln = _build_ln(d_model, name = append_name(name, 'mask_lm_trans')) - self.mlm_bias = L.create_parameter( - dtype='float32', - shape=[d_vocab], - attr=F.ParamAttr( - name=append_name(name, 'mask_lm_out_fc.b_0'), - initializer=F.initializer.Constant(value=0.0) - ), - is_bias=True, - ) - - def forward(self, src_ids, *args, **kwargs): - tgt_labels = kwargs.pop('tgt_labels', None) - tgt_pos = kwargs.pop('tgt_pos', None) - encode_only = kwargs.pop('encode_only', False) - _, encoded, info = ErnieModel.forward(self, src_ids, *args, **kwargs) - #log.debug('hidden_-1 %r'% L.reduce_mean(info['hiddens'][0]).numpy()) - #log.debug('hidden_0 %r'% L.reduce_mean(info['hiddens'][1]).numpy()) - if encode_only: - return None, None, info - elif tgt_labels is None: - encoded = self.mlm(encoded) - encoded = self.mlm_ln(encoded) - logits = L.matmul(encoded, self.word_emb.weight, transpose_y=True) + self.mlm_bias - output_ids = L.argmax(logits, -1) - return output_ids, logits, info - else: - encoded_2d = L.gather_nd(encoded, tgt_pos) - #log.debug('input shape %s' % repr(src_ids.shape)) - #log.debug(L.gather_nd(src_ids, tgt_pos).numpy()) - encoded_2d = self.mlm(encoded_2d) - encoded_2d = self.mlm_ln(encoded_2d) - logits_2d = L.matmul(encoded_2d, self.word_emb.weight, transpose_y=True) + self.mlm_bias - if len(tgt_labels.shape) == 1: - tgt_labels = L.reshape(tgt_labels, [-1, 1]) - - loss = L.reduce_mean( - L.softmax_with_cross_entropy(logits_2d, tgt_labels, soft_label=(tgt_labels.shape[-1] != 1)) - ) - return loss, logits_2d, info - diff --git a/requirements.txt b/requirements.txt index 54a1009..23fc00f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ pyzmq==18.0.2 six==1.11.0 sklearn==0.0 sentencepiece==0.1.8 +LAC diff --git a/setup.py b/setup.py index c385899..8a91668 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ with open("README.md", "r", encoding='utf-8') as fh: setuptools.setup( name="paddle-ernie", # Replace with your own username - version="0.0.3dev1", + version="0.0.4dev1", author="Baidu Ernie Team", author_email="ernieernie.team@gmail.com", description="A pretrained NLP model for every NLP tasks", -- GitLab