crownpku / Information-Extraction-Chinese

Chinese Named Entity Recognition with IDCNN/biLSTM+CRF, and Relation Extraction with biGRU+2ATT 中文实体识别与关系提取
2.23k stars 812 forks source link

修改神经网络层数参数问题 #57

Open yuyangyang0709 opened 6 years ago

yuyangyang0709 commented 6 years ago

您好,您的程序对我用处很大,我想用自己的训练集并调一下参数,但是在改变神经网络层数这个参数时,系统报错了。 当我修改为self.num_layers = 3 时,报错:

File "", line 1, in runfile('D:/BiGRU_Attention/BiGRU_Attention/train_GRU.py', wdir='D:/BiGRU_Attention/BiGRU_Attention')

File "C:\Users\yyy\Anaconda3\envs\tensorflow\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile execfile(filename, namespace)

File "C:\Users\yyy\Anaconda3\envs\tensorflow\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "D:/BiGRU_Attention/BiGRU_Attention/train_GRU.py", line 131, in tf.app.run()

File "C:\Users\yyy\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\platform\app.py", line 48, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough))

File "D:/BiGRU_Attention/BiGRU_Attention/train_GRU.py", line 38, in main m = network.GRU(is_training=True, word_embeddings=wordembedding, settings=settings)

File "D:\BiGRU_Attention\BiGRU_Attention\network.py", line 77, in init (cell_output_forward, state_forward) = cell_forward(inputs_forward[:, step, :], state_forward)

File "C:\Users\yyy\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\rnn_cell_impl.py", line 180, in call return super(RNNCell, self).call(inputs, state)

File "C:\Users\yyy\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\layers\base.py", line 441, in call outputs = self.call(inputs, *args, **kwargs)

File "C:\Users\yyy\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\rnn_cell_impl.py", line 916, in call cur_inp, new_state = cell(cur_inp, cur_state)

File "C:\Users\yyy\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\rnn_cell_impl.py", line 752, in call output, new_state = self._cell(inputs, state, scope)

File "C:\Users\yyy\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\rnn_cell_impl.py", line 180, in call return super(RNNCell, self).call(inputs, state)

File "C:\Users\yyy\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\layers\base.py", line 441, in call outputs = self.call(inputs, *args, **kwargs)

File "C:\Users\yyy\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\rnn_cell_impl.py", line 295, in call self._kernel_initializer))

File "C:\Users\yyy\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\rnn_cell_impl.py", line 1017, in _linear initializer=kernel_initializer)

File "C:\Users\yyy\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 1065, in get_variable use_resource=use_resource, custom_getter=custom_getter)

File "C:\Users\yyy\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 962, in get_variable use_resource=use_resource, custom_getter=custom_getter)

File "C:\Users\yyy\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 360, in get_variable validate_shape=validate_shape, use_resource=use_resource)

File "C:\Users\yyy\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 1405, in wrapped_custom_getter *args, **kwargs)

File "C:\Users\yyy\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\rnn_cell_impl.py", line 183, in _rnn_get_variable variable = getter(*args, **kwargs)

File "C:\Users\yyy\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\rnn_cell_impl.py", line 183, in _rnn_get_variable variable = getter(*args, **kwargs)

File "C:\Users\yyy\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 352, in _true_getter use_resource=use_resource)

File "C:\Users\yyy\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 669, in _get_single_variable found_var.get_shape()))

ValueError: Trying to share variable model/GRU_FORWARD/multi_rnn_cell/cell_0/gru_cell/gates/kernel, but specified shape (460, 460) and found shape (330, 460).

请问这个怎么解决啊,谢谢了。

lixuanhng commented 3 years ago

维度不匹配,可以尝试一下将原来生成的checkpoint文件删掉,从头跑;要是还不行,需要检查一下维度是不是哪里出错了