From f3bc752ace5cbc1a6b32c83b639399fa7a75ffb8 Mon Sep 17 00:00:00 2001 From: Youwei Song Date: Wed, 10 Jul 2019 19:43:47 +0800 Subject: [PATCH] use numpy.asarray as data initializer (#769) use numpy.asarray as data initializer --- 04.word2vec/README.cn.md | 10 +++++----- 04.word2vec/README.md | 10 +++++----- 04.word2vec/index.cn.html | 10 +++++----- 04.word2vec/index.html | 10 +++++----- 04.word2vec/train.py | 10 +++++----- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/04.word2vec/README.cn.md b/04.word2vec/README.cn.md index d43a118..bf5d51b 100644 --- a/04.word2vec/README.cn.md +++ b/04.word2vec/README.cn.md @@ -444,11 +444,11 @@ def infer(use_cuda, params_dirname=None): # 用来查询embedding表获取对应的词向量,因此其形状大小是[1]。 # recursive_sequence_lengths设置的是基于长度的LoD,因此都应该设为[[1]] # 注意recursive_sequence_lengths是列表的列表 - data1 = [[211]] # 'among' - data2 = [[6]] # 'a' - data3 = [[96]] # 'group' - data4 = [[4]] # 'of' - lod = [[1]] + data1 = numpy.asarray([[211]], dtype=numpy.int64) # 'among' + data2 = numpy.asarray([[6]], dtype=numpy.int64) # 'a' + data3 = numpy.asarray([[96]], dtype=numpy.int64) # 'group' + data4 = numpy.asarray([[4]], dtype=numpy.int64) # 'of' + lod = numpy.asarray([[1]], dtype=numpy.int64) first_word = fluid.create_lod_tensor(data1, lod, place) second_word = fluid.create_lod_tensor(data2, lod, place) diff --git a/04.word2vec/README.md b/04.word2vec/README.md index 2002e47..eb3e44a 100644 --- a/04.word2vec/README.md +++ b/04.word2vec/README.md @@ -409,11 +409,11 @@ def infer(use_cuda, params_dirname=None): # Used to query the embedding table to get the corresponding word vector, so its shape size is [1]. # recursive_sequence_lengths sets the length based on LoD, so it should all be set to [[1]] # Note that recursive_sequence_lengths is a list of lists - data1 = [[211]] # 'among' - data2 = [[6]] # 'a' - data3 = [[96]] # 'group' - data4 = [[4]] # 'of' - lod = [[1]] + data1 = numpy.asarray([[211]], dtype=numpy.int64) # 'among' + data2 = numpy.asarray([[6]], dtype=numpy.int64) # 'a' + data3 = numpy.asarray([[96]], dtype=numpy.int64) # 'group' + data4 = numpy.asarray([[4]], dtype=numpy.int64) # 'of' + lod = numpy.asarray([[1]], dtype=numpy.int64) first_word = fluid.create_lod_tensor(data1, lod, place) second_word = fluid.create_lod_tensor(data2, lod, place) diff --git a/04.word2vec/index.cn.html b/04.word2vec/index.cn.html index b7b727c..73cbd2e 100644 --- a/04.word2vec/index.cn.html +++ b/04.word2vec/index.cn.html @@ -486,11 +486,11 @@ def infer(use_cuda, params_dirname=None): # 用来查询embedding表获取对应的词向量,因此其形状大小是[1]。 # recursive_sequence_lengths设置的是基于长度的LoD,因此都应该设为[[1]] # 注意recursive_sequence_lengths是列表的列表 - data1 = [[211]] # 'among' - data2 = [[6]] # 'a' - data3 = [[96]] # 'group' - data4 = [[4]] # 'of' - lod = [[1]] + data1 = numpy.asarray([[211]], dtype=numpy.int64) # 'among' + data2 = numpy.asarray([[6]], dtype=numpy.int64) # 'a' + data3 = numpy.asarray([[96]], dtype=numpy.int64) # 'group' + data4 = numpy.asarray([[4]], dtype=numpy.int64) # 'of' + lod = numpy.asarray([[1]], dtype=numpy.int64) first_word = fluid.create_lod_tensor(data1, lod, place) second_word = fluid.create_lod_tensor(data2, lod, place) diff --git a/04.word2vec/index.html b/04.word2vec/index.html index f67aeba..ab5e1f6 100644 --- a/04.word2vec/index.html +++ b/04.word2vec/index.html @@ -451,11 +451,11 @@ def infer(use_cuda, params_dirname=None): # Used to query the embedding table to get the corresponding word vector, so its shape size is [1]. # recursive_sequence_lengths sets the length based on LoD, so it should all be set to [[1]] # Note that recursive_sequence_lengths is a list of lists - data1 = [[211]] # 'among' - data2 = [[6]] # 'a' - data3 = [[96]] # 'group' - data4 = [[4]] # 'of' - lod = [[1]] + data1 = numpy.asarray([[211]], dtype=numpy.int64) # 'among' + data2 = numpy.asarray([[6]], dtype=numpy.int64) # 'a' + data3 = numpy.asarray([[96]], dtype=numpy.int64) # 'group' + data4 = numpy.asarray([[4]], dtype=numpy.int64) # 'of' + lod = numpy.asarray([[1]], dtype=numpy.int64) first_word = fluid.create_lod_tensor(data1, lod, place) second_word = fluid.create_lod_tensor(data2, lod, place) diff --git a/04.word2vec/train.py b/04.word2vec/train.py index eebf622..2b3a972 100644 --- a/04.word2vec/train.py +++ b/04.word2vec/train.py @@ -206,11 +206,11 @@ def infer(use_cuda, params_dirname=None): # meaning there is only one level of detail and there is only one sequence of # one word on this level. # Note that recursive_sequence_lengths should be a list of lists. - data1 = [[numpy.int64(211)]] # 'among' - data2 = [[numpy.int64(6)]] # 'a' - data3 = [[numpy.int64(96)]] # 'group' - data4 = [[numpy.int64(4)]] # 'of' - lod = [[numpy.int64(1)]] + data1 = numpy.asarray([[211]], dtype=numpy.int64) # 'among' + data2 = numpy.asarray([[6]], dtype=numpy.int64) # 'a' + data3 = numpy.asarray([[96]], dtype=numpy.int64) # 'group' + data4 = numpy.asarray([[4]], dtype=numpy.int64) # 'of' + lod = numpy.asarray([[1]], dtype=numpy.int64) first_word = fluid.create_lod_tensor(data1, lod, place) second_word = fluid.create_lod_tensor(data2, lod, place) -- GitLab