@@ -202,24 +202,35 @@ def infer(use_cuda, inference_program, save_path):
202
202
inferencer = fluid .Inferencer (
203
203
inference_program , param_path = save_path , place = place )
204
204
205
- def create_random_lodtensor (lod , place , low , high ):
206
- data = np .random .random_integers (low , high ,
207
- [lod [- 1 ], 1 ]).astype ("int64" )
208
- res = fluid .LoDTensor ()
209
- res .set (data , place )
210
- res .set_lod ([lod ])
211
- return res
212
-
213
- # Create an input example
214
- lod = [0 , 4 , 10 ]
215
- word = create_random_lodtensor (lod , place , low = 0 , high = WORD_DICT_LEN - 1 )
216
- pred = create_random_lodtensor (lod , place , low = 0 , high = PRED_DICT_LEN - 1 )
217
- ctx_n2 = create_random_lodtensor (lod , place , low = 0 , high = WORD_DICT_LEN - 1 )
218
- ctx_n1 = create_random_lodtensor (lod , place , low = 0 , high = WORD_DICT_LEN - 1 )
219
- ctx_0 = create_random_lodtensor (lod , place , low = 0 , high = WORD_DICT_LEN - 1 )
220
- ctx_p1 = create_random_lodtensor (lod , place , low = 0 , high = WORD_DICT_LEN - 1 )
221
- ctx_p2 = create_random_lodtensor (lod , place , low = 0 , high = WORD_DICT_LEN - 1 )
222
- mark = create_random_lodtensor (lod , place , low = 0 , high = MARK_DICT_LEN - 1 )
205
+ # Setup inputs by creating LoDTensors to represent sequences of words.
206
+ # Here each word is the basic element of these LoDTensors and the shape of
207
+ # each word (base_shape) should be [1] since it is simply an index to
208
+ # look up for the corresponding word vector.
209
+ # Suppose the length_based level of detail (lod) info is set to [[3, 4, 2]],
210
+ # which has only one lod level. Then the created LoDTensors will have only
211
+ # one higher level structure (sequence of words, or sentence) than the basic
212
+ # element (word). Hence the LoDTensor will hold data for three sentences of
213
+ # length 3, 4 and 2, respectively.
214
+ # Note that lod info should be a list of lists.
215
+ lod = [[3 , 4 , 2 ]]
216
+ base_shape = [1 ]
217
+ # The range of random integers is [low, high]
218
+ word = fluid .create_random_lodtensor (
219
+ lod , base_shape , place , low = 0 , high = WORD_DICT_LEN - 1 )
220
+ pred = fluid .create_random_lodtensor (
221
+ lod , base_shape , place , low = 0 , high = PRED_DICT_LEN - 1 )
222
+ ctx_n2 = fluid .create_random_lodtensor (
223
+ lod , base_shape , place , low = 0 , high = WORD_DICT_LEN - 1 )
224
+ ctx_n1 = fluid .create_random_lodtensor (
225
+ lod , base_shape , place , low = 0 , high = WORD_DICT_LEN - 1 )
226
+ ctx_0 = fluid .create_random_lodtensor (
227
+ lod , base_shape , place , low = 0 , high = WORD_DICT_LEN - 1 )
228
+ ctx_p1 = fluid .create_random_lodtensor (
229
+ lod , base_shape , place , low = 0 , high = WORD_DICT_LEN - 1 )
230
+ ctx_p2 = fluid .create_random_lodtensor (
231
+ lod , base_shape , place , low = 0 , high = WORD_DICT_LEN - 1 )
232
+ mark = fluid .create_random_lodtensor (
233
+ lod , base_shape , place , low = 0 , high = MARK_DICT_LEN - 1 )
223
234
224
235
results = inferencer .infer (
225
236
{
0 commit comments