abisee / pointer-generator

Code for the ACL 2017 paper "Get To The Point: Summarization with Pointer-Generator Networks"
Other
2.18k stars 813 forks source link

Error about 'Matrix already exists' under decode mode. #68

Open xiyan524 opened 6 years ago

xiyan524 commented 6 years ago

Thanks for your impressive work.

In fact, I am trying to modify something about this structure, while I did not modify anything about attention mechanism. After I train my new model successfully, I met some error in decode mode about attention. Errors are represented like follow:

`Traceback (most recent call last): File "F:/study/project/pointer-generator-master/run_summarization.py", line 329, in tf.app.run() File "F:\ANACONDA\lib\site-packages\tensorflow\python\platform\app.py", line 48, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "F:/study/project/pointer-generator-master/run_summarization.py", line 323, in main decoder = BeamSearchDecoder(model, batcher, vocab) File "F:\study\project\pointer-generator-master\decode.py", line 47, in init self._model.build_graph() File "F:\study\project\pointer-generator-master\model.py", line 333, in build_graph self._add_seq2seq() File "F:\study\project\pointer-generator-master\model.py", line 244, in _add_seq2seq decoder_outputs, self._dec_out_state, self.attn_dists, self.p_gens, self.coverage, structure_vecs, self.KL = self._add_decoder(emb_dec_inputs) File "F:\study\project\pointer-generator-master\model.py", line 156, in _add_decoder prev_coverage=prev_coverage) File "F:\study\project\pointer-generator-master\attention_decoder.py", line 216, in attention_decoder context_vector, attn_dist, coverage = attention(state, coverage) File "F:\study\project\pointer-generator-master\attention_decoder.py", line 95, in attention decoder_features = linear(decoder_state, attention_vec_size, True) # shape (batch_size, attention_vec_size) File "F:\study\project\pointer-generator-master\attention_decoder.py", line 276, in linear matrix = tf.get_variable("Matrix", [total_arg_size, output_size]) File "F:\ANACONDA\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 1203, in get_variable constraint=constraint) File "F:\ANACONDA\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 1092, in get_variable constraint=constraint) File "F:\ANACONDA\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 425, in get_variable constraint=constraint) File "F:\ANACONDA\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 394, in _true_getter use_resource=use_resource, constraint=constraint) File "F:\ANACONDA\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 742, in _get_single_variable name, "".join(traceback.format_list(tb)))) ValueError: Variable seq2seq/decoder/attention_decoder/Attention/Linear/Matrix already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:

File "F:\ANACONDA\lib\site-packages\tensorflow\python\framework\ops.py", line 1470, in init self._traceback = self._graph._extract_stack() # pylint: disable=protected-access File "F:\ANACONDA\lib\site-packages\tensorflow\python\framework\ops.py", line 2956, in create_op op_def=op_def) File "F:\ANACONDA\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper op_def=op_def)0`

I thought there may be some error in your linear function.Could you please provide some help? Thanks a lot.

alkanen commented 6 years ago

@xiyan524 , it looks like you've copied part of the model and re-used it without changing its name.

xiyan524 commented 6 years ago

Yeah, I got that from the error information. I think the error mainly comes from

File "F:\study\project\pointer-generator-master\attention_decoder.py", line 276, in linear matrix = tf.get_variable("Matrix", [total_arg_size, output_size])

I mean linear function has been used for serveral times, so Matrix definitely will be re-used. I am not sure this thought is correct or not?

alkanen commented 6 years ago

Can you post the diff of your changes? It's hard to guess without knowing what you've done, especially since this isn't my project so I don't know it by heart or anything =)

alkanen commented 6 years ago

linear() is used several times, but you'll notice that it's almost always in a "with variable_scope.variable_scope()" which makes it unique. If you don't do something similar with your matrix, that might explain your problem.

xiyan524 commented 6 years ago

Thanks a lot, I have solved my problem. I found that I changed the i value in 'attention.py' by mistake, so that it did not run with variable_scope.variable_scope(variable_scope.get_variable_scope(), reuse=True).

alkanen commented 6 years ago

Glad to hear you got it working!