Franck-Dernoncourt / NeuroNER

Named-entity recognition using neural networks. Easy-to-use and state-of-the-art results.
http://neuroner.com
MIT License
1.7k stars 475 forks source link

if I want to train this model without char,what should i do? #86

Open lovychen opened 6 years ago

lovychen commented 6 years ago

hello : if i want to train this model without char,what should i do? I want to make a comparison between the model with a char and the model with no char.

JohnGiorgi commented 6 years ago

Set use_character_lstm in src/parameters.ini to false.

lovychen commented 6 years ago

When i set use_character_lstm in src/parameters.ini to false. After i train a model,when i use the model to do some prediction,it has some wrong,i just set use_pretrained_model in src/parameters.ini to True.

File "server_debug.py", line 131, in main handler.init(argv[1:]) File "server_debug.py", line 111, in init self.nn = NeuroNER(arguments) File "/home/wcg/wcg_work/ner/NeuroNER/src_predict/neuroner.py", line 284, in init self.transition_params_trained = model.restore_from_pretrained_model(parameters, dataset, sess, token_to_vector=token_to_vector) File "/home/wcg/wcg_work/ner/NeuroNER/src_predict/entity_lstm.py", line 329, in restore_from_pretrained_model self.saver.restore(sess, pretrained_model_checkpoint_filepath) # Works only when the dimensions of tensor variables are matched. File "/home/wcg/tools/local/anaconda3/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1560, in restore {self.saver_def.filename_tensor_name: save_path}) File "/home/wcg/tools/local/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 895, in run run_metadata_ptr) File "/home/wcg/tools/local/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1124, in _run feed_dict_tensor, options, run_metadata) File "/home/wcg/tools/local/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1321, in _do_run options, run_metadata) File "/home/wcg/tools/local/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1340, in _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.NotFoundError: Key character_lstm/bidirectional_LSTM/bidirectional_rnn/bw/coupled_input_forget_gate_lstm_cell/W_0 not found in checkpoint [[Node: save/RestoreV2_4 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_arg_save/Const_0_0, save/RestoreV2_4/tensor_names, save/RestoreV2_4/shape_and_slices)]] Caused by op 'save/RestoreV2_4', defined at: File "server_debug.py", line 163, in main() File "server_debug.py", line 131, in main handler.init(argv[1:]) File "server_debug.py", line 111, in init self.nn = NeuroNER(arguments) File "/home/wcg/wcg_work/ner/NeuroNER/src_predict/neuroner.py", line 276, in init model = EntityLSTM(dataset, parameters) File "/home/wcg/wcg_work/ner/NeuroNER/src_predict/entity_lstm.py", line 216, in init self.saver = tf.train.Saver(max_to_keep=parameters['maximum_number_of_epochs']) # defaults to saving all variables File "/home/wcg/tools/local/anaconda3/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1140, in init self.build() File "/home/wcg/tools/local/anaconda3/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1172, in build filename=self._filename) File "/home/wcg/tools/local/anaconda3/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 688, in build restore_sequentially, reshape) File "/home/wcg/tools/local/anaconda3/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 407, in _AddRestoreOps tensors = self.restore_op(filename_tensor, saveable, preferred_shard) File "/home/wcg/tools/local/anaconda3/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 247, in restore_op [spec.tensor.dtype])[0]) File "/home/wcg/tools/local/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/gen_io_ops.py", line 663, in restore_v2 dtypes=dtypes, name=name) File "/home/wcg/tools/local/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op op_def=op_def) File "/home/wcg/tools/local/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2630, in create_op original_op=self._default_original_op, op_def=op_def) File "/home/wcg/tools/local/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1204, in init self._traceback = self._graph._extract_stack() # pylint: disable=protected-access

NotFoundError (see above for traceback): Key character_lstm/bidirectional_LSTM/bidirectional_rnn/bw/coupled_input_forget_gate_lstm_cell/W_0 not found in checkpoint [[Node: save/RestoreV2_4 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_arg_save/Const_0_0, save/RestoreV2_4/tensor_names, save/RestoreV2_4/shape_and_slices)]]

Exception ignored in: <bound method NeuroNER.del of <neuroner.NeuroNER object at 0x7f35981d7400>> Traceback (most recent call last): File "/home/wcg/wcg_work/ner/NeuroNER/src_predict/neuroner.py", line 524, in del self.sess.close() AttributeError: 'NeuroNER' object has no attribute 'sess'

lovychen commented 6 years ago

I've solved this problem, parameter.ini is in the wrong place

JohnGiorgi commented 6 years ago

Great! Please close issues that have been resolved, thanks:)

JokerSeven commented 6 years ago

Hi, @lovychen. I also have a problem when I load a saved model which I have trained ,and I trained my model without char. Have you ever had the same problem before? 1 Could you tell me your email address? I would like to ask you a few questions about training model , if you don't mind.