From 33ea7c74878e1b04dd9445cec3886e7ab559dad1 Mon Sep 17 00:00:00 2001 From: frankwhzhang Date: Sat, 12 Oct 2019 16:59:10 +0800 Subject: [PATCH] update api & check version --- PaddleRec/gru4rec/README.md | 4 ++++ PaddleRec/gru4rec/infer.py | 1 + PaddleRec/gru4rec/infer_sample_neg.py | 1 + PaddleRec/gru4rec/train.py | 1 + PaddleRec/gru4rec/train_sample_neg.py | 1 + PaddleRec/gru4rec/utils.py | 14 ++++++++++++++ PaddleRec/multiview_simnet/README.md | 3 +++ PaddleRec/multiview_simnet/infer.py | 18 ++++++++++++++++++ PaddleRec/multiview_simnet/train.py | 16 ++++++++++++++++ PaddleRec/ssr/README.md | 4 ++++ PaddleRec/ssr/infer.py | 1 + PaddleRec/ssr/train.py | 1 + PaddleRec/ssr/utils.py | 14 ++++++++++++++ PaddleRec/tagspace/README.md | 1 + PaddleRec/tagspace/infer.py | 1 + PaddleRec/tagspace/train.py | 1 + PaddleRec/tagspace/utils.py | 15 +++++++++++++++ PaddleRec/word2vec/README.md | 1 + PaddleRec/word2vec/infer.py | 1 + PaddleRec/word2vec/train.py | 1 + PaddleRec/word2vec/utils.py | 14 ++++++++++++++ 21 files changed, 114 insertions(+) diff --git a/PaddleRec/gru4rec/README.md b/PaddleRec/gru4rec/README.md index 35378156..afff1f06 100644 --- a/PaddleRec/gru4rec/README.md +++ b/PaddleRec/gru4rec/README.md @@ -44,6 +44,10 @@ session-based推荐应用场景非常广泛,比如用户的商品浏览、新 运行样例程序可跳过'RSC15 数据下载及预处理'部分 + + +**要求使用PaddlePaddle 1.6及以上版本或适当的develop版本。** + ## RSC15 数据下载及预处理 运行命令 下载RSC15官网数据集 diff --git a/PaddleRec/gru4rec/infer.py b/PaddleRec/gru4rec/infer.py index bc459c28..032205cf 100644 --- a/PaddleRec/gru4rec/infer.py +++ b/PaddleRec/gru4rec/infer.py @@ -71,6 +71,7 @@ def infer(test_reader, use_cuda, model_path): if __name__ == "__main__": + utils.check_version() args = parse_args() start_index = args.start_index last_index = args.last_index diff --git a/PaddleRec/gru4rec/infer_sample_neg.py b/PaddleRec/gru4rec/infer_sample_neg.py index 48458e82..b77f3685 100644 --- a/PaddleRec/gru4rec/infer_sample_neg.py +++ b/PaddleRec/gru4rec/infer_sample_neg.py @@ -84,6 +84,7 @@ def infer(args, vocab_size, test_reader, use_cuda): if __name__ == "__main__": + utils.check_version() args = parse_args() start_index = args.start_index last_index = args.last_index diff --git a/PaddleRec/gru4rec/train.py b/PaddleRec/gru4rec/train.py index b43926b6..d7124eba 100644 --- a/PaddleRec/gru4rec/train.py +++ b/PaddleRec/gru4rec/train.py @@ -169,4 +169,5 @@ def get_device(args): if __name__ == "__main__": + utils.check_version() train() diff --git a/PaddleRec/gru4rec/train_sample_neg.py b/PaddleRec/gru4rec/train_sample_neg.py index 26424520..fbb68705 100644 --- a/PaddleRec/gru4rec/train_sample_neg.py +++ b/PaddleRec/gru4rec/train_sample_neg.py @@ -128,4 +128,5 @@ def train(): if __name__ == "__main__": + utils.check_version() train() diff --git a/PaddleRec/gru4rec/utils.py b/PaddleRec/gru4rec/utils.py index 8588a0f1..ffd05fc5 100644 --- a/PaddleRec/gru4rec/utils.py +++ b/PaddleRec/gru4rec/utils.py @@ -115,6 +115,20 @@ def prepare_data(file_dir, file_dir, buffer_size, data_type=DataType.SEQ), batch_size) return vocab_size, reader +def check_version(): + """ + Log error and exit when the installed version of paddlepaddle is + not satisfied. + """ + err = "PaddlePaddle version 1.6 or higher is required, " \ + "or a suitable develop version is satisfied as well. \n" \ + "Please make sure the version is good with your code." \ + + try: + fluid.require_version('1.6.0') + except Exception as e: + logger.error(err) + sys.exit(1) def sort_batch(reader, batch_size, sort_group_size, drop_last=False): """ diff --git a/PaddleRec/multiview_simnet/README.md b/PaddleRec/multiview_simnet/README.md index 31d6fd54..d9cf7e10 100644 --- a/PaddleRec/multiview_simnet/README.md +++ b/PaddleRec/multiview_simnet/README.md @@ -3,6 +3,9 @@ ## Introduction In personalized recommendation scenario, a user often is provided with several items from personalized interest matching model. In real world application, a user may have multiple views of features, say user-id, age, click-history of items, search queries. A item, e.g. news, may also have multiple views of features like news title, news category, images in news and so on. Multi-view Simnet is matching a model that combine users' and items' multiple views of features into one unified model. The model can be used in many industrial product like Baidu's feed news. The model is adapted from the paper A Multi-View Deep Learning(MV-DNN) Approach for Cross Domain User Modeling in Recommendation Systems, WWW 2015. The difference between our model and the MV-DNN is that we also consider multiple feature views of users. +**Now all models in PaddleRec require PaddlePaddle version 1.6 or higher, or suitable develop version.** + + ## Dataset Currently, synthetic dataset is provided for proof of concept and we aim to add more real world dataset in this project in the future. The result is inaccurate because of synthetic dataset. diff --git a/PaddleRec/multiview_simnet/infer.py b/PaddleRec/multiview_simnet/infer.py index 7b5bb080..2e871d9e 100644 --- a/PaddleRec/multiview_simnet/infer.py +++ b/PaddleRec/multiview_simnet/infer.py @@ -31,6 +31,23 @@ logger = logging.getLogger("fluid") logger.setLevel(logging.INFO) +def check_version(): + """ + Log error and exit when the installed version of paddlepaddle is + not satisfied. + """ + err = "PaddlePaddle version 1.6 or higher is required, " \ + "or a suitable develop version is satisfied as well. \n" \ + "Please make sure the version is good with your code." \ + + try: + fluid.require_version('1.6.0') + except Exception as e: + logger.error(err) + sys.exit(1) + + + def parse_args(): parser = argparse.ArgumentParser("multi-view simnet") parser.add_argument("--train_file", type=str, help="Training file") @@ -116,4 +133,5 @@ def main(): if __name__ == "__main__": + check_version() main() diff --git a/PaddleRec/multiview_simnet/train.py b/PaddleRec/multiview_simnet/train.py index f098fd10..d7920083 100644 --- a/PaddleRec/multiview_simnet/train.py +++ b/PaddleRec/multiview_simnet/train.py @@ -88,6 +88,21 @@ def parse_args(): return parser.parse_args() +def check_version(): + """ + Log error and exit when the installed version of paddlepaddle is + not satisfied. + """ + err = "PaddlePaddle version 1.6 or higher is required, " \ + "or a suitable develop version is satisfied as well. \n" \ + "Please make sure the version is good with your code." \ + + try: + fluid.require_version('1.6.0') + except Exception as e: + logger.error(err) + sys.exit(1) + def start_train(args): if args.enable_ce: SEED = 102 @@ -170,4 +185,5 @@ def main(): if __name__ == "__main__": + check_version() main() diff --git a/PaddleRec/ssr/README.md b/PaddleRec/ssr/README.md index d0b4dfb4..6ded50b9 100644 --- a/PaddleRec/ssr/README.md +++ b/PaddleRec/ssr/README.md @@ -12,6 +12,10 @@ Sequence Semantic Retrieval(SSR) Model shares the similar idea with Multi-Rate D - The idea of SSR is to model a user's personalized interest of an item through matching model structure, and the representation of a news item can be computed online even the news item does not exist in training dataset. - With the representation of news items, we are able to build an vector indexing service online for news prediction and this is the retrieval part of SSR. +## Version +**Now all models in PaddleRec require PaddlePaddle version 1.6 or higher, or suitable develop version.** + + ## Dataset Dataset preprocessing follows the method of [GRU4Rec Project](https://github.com/PaddlePaddle/models/tree/develop/fluid/PaddleRec/gru4rec). Note that you should reuse scripts from GRU4Rec project for data preprocessing. diff --git a/PaddleRec/ssr/infer.py b/PaddleRec/ssr/infer.py index 09dee039..3a44fad7 100644 --- a/PaddleRec/ssr/infer.py +++ b/PaddleRec/ssr/infer.py @@ -120,6 +120,7 @@ def infer(args, vocab_size, test_reader): if __name__ == "__main__": + utils.check_version() args = parse_args() start_index = args.start_index last_index = args.last_index diff --git a/PaddleRec/ssr/train.py b/PaddleRec/ssr/train.py index 1c0c9f8c..3c441039 100644 --- a/PaddleRec/ssr/train.py +++ b/PaddleRec/ssr/train.py @@ -165,4 +165,5 @@ def main(): if __name__ == "__main__": + utils.check_version() main() diff --git a/PaddleRec/ssr/utils.py b/PaddleRec/ssr/utils.py index ce65e32f..353cf336 100644 --- a/PaddleRec/ssr/utils.py +++ b/PaddleRec/ssr/utils.py @@ -30,6 +30,20 @@ def construct_test_data(file_dir, vocab_path, batch_size): test_reader = fluid.io.batch(y_data.test(files), batch_size=batch_size) return test_reader, vocab_size +def check_version(): + """ + Log error and exit when the installed version of paddlepaddle is + not satisfied. + """ + err = "PaddlePaddle version 1.6 or higher is required, " \ + "or a suitable develop version is satisfied as well. \n" \ + "Please make sure the version is good with your code." \ + + try: + fluid.require_version('1.6.0') + except Exception as e: + logger.error(err) + sys.exit(1) def infer_data(raw_data, place): data = [dat[0] for dat in raw_data] diff --git a/PaddleRec/tagspace/README.md b/PaddleRec/tagspace/README.md index 4263065b..818ab0cd 100644 --- a/PaddleRec/tagspace/README.md +++ b/PaddleRec/tagspace/README.md @@ -26,6 +26,7 @@ TagSpace模型的介绍可以参阅论文[#TagSpace: Semantic Embeddings from Ha Tagspace模型学习文本及标签的embedding表示,应用于工业级的标签推荐,具体应用场景有feed新闻标签推荐。 +**Now all models in PaddleRec require PaddlePaddle version 1.6 or higher, or suitable develop version.** ## 数据下载及预处理 diff --git a/PaddleRec/tagspace/infer.py b/PaddleRec/tagspace/infer.py index e8522b09..66412fc5 100644 --- a/PaddleRec/tagspace/infer.py +++ b/PaddleRec/tagspace/infer.py @@ -71,6 +71,7 @@ def infer(test_reader, vocab_tag, use_cuda, model_path, epoch): if __name__ == "__main__": + utils.check_version() args = parse_args() start_index = args.start_index last_index = args.last_index diff --git a/PaddleRec/tagspace/train.py b/PaddleRec/tagspace/train.py index 419bb1c4..2230407e 100644 --- a/PaddleRec/tagspace/train.py +++ b/PaddleRec/tagspace/train.py @@ -168,4 +168,5 @@ def get_device(args): if __name__ == "__main__": + utils.check_version() train() diff --git a/PaddleRec/tagspace/utils.py b/PaddleRec/tagspace/utils.py index f5b7e647..80b77c8e 100644 --- a/PaddleRec/tagspace/utils.py +++ b/PaddleRec/tagspace/utils.py @@ -29,6 +29,21 @@ def get_vocab_size(vocab_path): line = rf.readline() return int(line.strip()) +def check_version(): + """ + Log error and exit when the installed version of paddlepaddle is + not satisfied. + """ + err = "PaddlePaddle version 1.6 or higher is required, " \ + "or a suitable develop version is satisfied as well. \n" \ + "Please make sure the version is good with your code." \ + + try: + fluid.require_version('1.6.0') + except Exception as e: + logger.error(err) + sys.exit(1) + def prepare_data(file_dir, vocab_text_path, diff --git a/PaddleRec/word2vec/README.md b/PaddleRec/word2vec/README.md index 1eceb5b2..e8f99428 100644 --- a/PaddleRec/word2vec/README.md +++ b/PaddleRec/word2vec/README.md @@ -20,6 +20,7 @@ ## 介绍 本例实现了skip-gram模式的word2vector模型。 +**目前模型库下模型均要求使用PaddlePaddle 1.6及以上版本或适当的develop版本。** ## 数据下载 全量数据集使用的是来自1 Billion Word Language Model Benchmark的(http://www.statmt.org/lm-benchmark) 的数据集. diff --git a/PaddleRec/word2vec/infer.py b/PaddleRec/word2vec/infer.py index 2a24fe92..36357dd6 100644 --- a/PaddleRec/word2vec/infer.py +++ b/PaddleRec/word2vec/infer.py @@ -185,6 +185,7 @@ def infer_step(args, vocab_size, test_reader, use_cuda, i2w): if __name__ == "__main__": + utils.check_version() args = parse_args() start_index = args.start_index last_index = args.last_index diff --git a/PaddleRec/word2vec/train.py b/PaddleRec/word2vec/train.py index 430ec132..bcc99654 100644 --- a/PaddleRec/word2vec/train.py +++ b/PaddleRec/word2vec/train.py @@ -224,5 +224,6 @@ def train(args): if __name__ == '__main__': + utils.check_version() args = parse_args() train(args) diff --git a/PaddleRec/word2vec/utils.py b/PaddleRec/word2vec/utils.py index 14da0688..0d173005 100644 --- a/PaddleRec/word2vec/utils.py +++ b/PaddleRec/word2vec/utils.py @@ -25,6 +25,20 @@ def prepare_data(file_dir, dict_path, batch_size): reader = fluid.io.batch(test(file_dir, w2i), batch_size) return vocab_size, reader, i2w +def check_version(): + """ + Log error and exit when the installed version of paddlepaddle is + not satisfied. + """ + err = "PaddlePaddle version 1.6 or higher is required, " \ + "or a suitable develop version is satisfied as well. \n" \ + "Please make sure the version is good with your code." \ + + try: + fluid.require_version('1.6.0') + except Exception as e: + logger.error(err) + sys.exit(1) def native_to_unicode(s): if _is_unicode(s): -- GitLab