提交 4d29a5d3 编写于 作者: K Kexin Zhao 提交者: Kexin Zhao

first commit

上级 defbaff2
...@@ -25,16 +25,6 @@ HIDDEN_SIZE = 256 ...@@ -25,16 +25,6 @@ HIDDEN_SIZE = 256
N = 5 N = 5
BATCH_SIZE = 32 BATCH_SIZE = 32
def create_random_lodtensor(lod, place, low, high):
# The range of data elements is [low, high]
data = np.random.random_integers(low, high, [lod[-1], 1]).astype("int64")
res = fluid.LoDTensor()
res.set(data, place)
res.set_lod([lod])
return res
word_dict = paddle.dataset.imikolov.build_dict() word_dict = paddle.dataset.imikolov.build_dict()
dict_size = len(word_dict) dict_size = len(word_dict)
...@@ -130,11 +120,23 @@ def infer(use_cuda, inference_program, save_dirname=None): ...@@ -130,11 +120,23 @@ def infer(use_cuda, inference_program, save_dirname=None):
inferencer = fluid.Inferencer( inferencer = fluid.Inferencer(
infer_func=inference_program, param_path=save_dirname, place=place) infer_func=inference_program, param_path=save_dirname, place=place)
lod = [0, 1] # Setup inputs by creating 4 LoDTensors representing 4 words. Here each word
first_word = create_random_lodtensor(lod, place, low=0, high=dict_size - 1) # is simply an index to look up for the corresponding word vector and hence
second_word = create_random_lodtensor(lod, place, low=0, high=dict_size - 1) # the shape of word (base_shape) should be [1]. The length-based level of
third_word = create_random_lodtensor(lod, place, low=0, high=dict_size - 1) # detail (lod) info of each LoDtensor should be [[1]] meaning there is only
fourth_word = create_random_lodtensor(lod, place, low=0, high=dict_size - 1) # one lod_level and there is only one sequence of one word on this level.
# Note that lod info should be a list of lists.
lod = [[1]]
base_shape = [1]
# The range of random integers is [low, high]
first_word = fluid.create_random_int_lodtensor(
lod, base_shape, place, low=0, high=dict_size - 1)
second_word = fluid.create_random_int_lodtensor(
lod, base_shape, place, low=0, high=dict_size - 1)
third_word = fluid.create_random_int_lodtensor(
lod, base_shape, place, low=0, high=dict_size - 1)
fourth_word = fluid.create_random_int_lodtensor(
lod, base_shape, place, low=0, high=dict_size - 1)
result = inferencer.infer( result = inferencer.infer(
{ {
......
...@@ -174,6 +174,7 @@ def infer(use_cuda, save_dirname=None): ...@@ -174,6 +174,7 @@ def infer(use_cuda, save_dirname=None):
# Note that lod info should be a list of lists. # Note that lod info should be a list of lists.
lod = [[1]] lod = [[1]]
base_shape = [1] base_shape = [1]
# The range of random integers is [low, high]
first_word = fluid.create_random_int_lodtensor( first_word = fluid.create_random_int_lodtensor(
lod, base_shape, place, low=0, high=dict_size - 1) lod, base_shape, place, low=0, high=dict_size - 1)
second_word = fluid.create_random_int_lodtensor( second_word = fluid.create_random_int_lodtensor(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册