利用paddle的hsigmoid训练词向量,出现IVector_create错误
Created by: fanfannothing
【背景】 利用paddle的hsigmoid训练词向量的时候,reader输出结果符合要求。但是出现如下错误。 在issue里面搜索过,没有找到对应的答案。麻烦看看。
【错误日志】 RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa [INFO 2018-01-04 13:35:08,759 reader.py:29] load dict success I0104 13:35:08.760479 26773 Util.cpp:166] commandline: --use_gpu=False --trainer_count=1 [INFO 2018-01-04 13:35:08,762 network_conf.py:13] input data layer name word00 [INFO 2018-01-04 13:35:08,763 network_conf.py:13] input data layer name word01 [INFO 2018-01-04 13:35:08,764 network_conf.py:13] input data layer name word02 [INFO 2018-01-04 13:35:08,765 network_conf.py:13] input data layer name word03 [INFO 2018-01-04 13:35:08,766 network_conf.py:21] output data layer name target_word I0104 13:35:15.055646 26773 GradientMachine.cpp:85] Initing parameters.. I0104 13:36:06.293507 26773 GradientMachine.cpp:92] Init parameters done. [INFO 2018-01-04 13:36:06,294 reader.py:40] [reader] load trainset from ./part-00 Traceback (most recent call last): File "train.py", line 125, in is_cloud=args.cloud) File "train.py", line 105, in train num_passes=30, event_handler=event_handler, feeding=feeding) File "/home/disk1/fengzhifan/python27-gcc482/lib/python2.7/site-packages/paddle/v2/trainer.py", line 153, in train in_args = feeder(data_batch) File "/home/disk1/fengzhifan/python27-gcc482/lib/python2.7/site-packages/py_paddle/dataprovider_converter.py", line 282, in call return self.convert(dat, argument) File "/home/disk1/fengzhifan/python27-gcc482/lib/python2.7/site-packages/paddle/v2/data_feeder.py", line 134, in convert return DataProviderConverter.convert(self, reorder_data(dat), argument) File "/home/disk1/fengzhifan/python27-gcc482/lib/python2.7/site-packages/py_paddle/dataprovider_converter.py", line 277, in convert scanner.finish_scan(argument) File "/home/disk1/fengzhifan/python27-gcc482/lib/python2.7/site-packages/py_paddle/dataprovider_converter.py", line 211, in finish_scan ids = swig_paddle.IVector.create(self.ids, self.data_in_gpu) File "/home/disk1/fengzhifan/python27-gcc482/lib/python2.7/site-packages/py_paddle/swig_paddle.py", line 881, in create return _swig_paddle.IVector_create(*args) NotImplementedError: Wrong number or type of arguments for overloaded function 'IVector_create'. Possible C/C++ prototypes are: IVector::create(std::vector< int,std::allocator< int > > const &,bool) IVector::create(std::vector< int,std::allocator< int > > const &)
【网络结构】
8 def ngram_lm(hidden_size, embed_size, dict_size, gram_num=4, is_train=True):
9 emb_layers = []
10 embed_param_attr = paddle.attr.Param(
11 name="_proj", initial_std=0.001, learning_rate=1, l2_rate=0)
12
13 for i in range(gram_num):
14 logger.info('input data layer name __word%02d__' % (i))
15 word = paddle.layer.data(
16 name="__word%02d__" % (i),
17 type=paddle.data_type.integer_value(dict_size))
18 emb_layers.append(paddle.layer.embedding(
19 input=word, size=embed_size, param_attr=embed_param_attr))
20
21 logger.info('output data layer name __target_word__')
22 target_word = paddle.layer.data(
23 name="__target_word__", type=paddle.data_type.integer_value(dict_size))
24
25 embed_context = paddle.layer.concat(input=emb_layers)
26
27 hidden_layer = paddle.layer.fc(
28 input=embed_context,
29 size=hidden_size,
30 act=paddle.activation.Sigmoid(),
31 layer_attr=paddle.attr.Extra(drop_rate=0.5),
32 bias_attr=paddle.attr.Param(learning_rate=2),
33 param_attr=paddle.attr.Param(
34 initial_std=1. / math.sqrt(embed_size * 8), learning_rate=1))
35
36 if is_train == True:
37 return paddle.layer.hsigmoid(
38 input=hidden_layer,
39 label=target_word,
40 num_classes=dict_size,
41 param_attr=paddle.attr.Param(name="sigmoid_w"),
42 bias_attr=paddle.attr.Param(name="sigmoid_b"))
43 else:
44 return paddle.layer.mixed(
45 size=dict_size - 1,
46 input=paddle.layer.trans_full_matrix_projection(
47 hidden_layer, param_attr=paddle.attr.Param(name="sigmoid_w")),
48 act=paddle.activation.Sigmoid(),
49 bias_attr=paddle.attr.Param(name="sigmoid_b"))
【reader输出数据】 [INFO 2018-01-04 14:57:47,452 reader.py:49] 0 1667662 660821 1154603 1325816 [INFO 2018-01-04 14:57:47,452 reader.py:49] 1667662 660821 1154603 1325816 1376644 [INFO 2018-01-04 14:57:47,452 reader.py:49] 660821 1154603 1325816 1376644 1457480 [INFO 2018-01-04 14:57:47,452 reader.py:49] 1154603 1325816 1376644 1457480 852167 [INFO 2018-01-04 14:57:47,452 reader.py:49] 1325816 1376644 1457480 852167 1