graph4nlp icon indicating copy to clipboard operation
graph4nlp copied to clipboard

How can I use copy mechanism with multi-token nodes?

Open sunnyeo opened this issue 2 years ago • 2 comments

Thank you for developing such a nice library!

I have a problem when using the graph2seq model with my custom graph which has multi-token nodes.

I set the config file as follows to use the decoder's copy mechanism with multi_token nodes:

...
    single_token_item: false
...
    use_copy: true
...

However, I encountered the following error:

Traceback (most recent call last):
  ...
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/graph4nlp_cu111-0.5.5-py3.8.egg/graph4nlp/pytorch/models/graph2seq.py", line 238, in forward
    return self.encoder_decoder(batch_graph=batch_graph, oov_dict=oov_dict, tgt_seq=tgt_seq)
  File "/usr/local/lib/python3.8/dist-packages/graph4nlp_cu111-0.5.5-py3.8.egg/graph4nlp/pytorch/models/graph2seq.py", line 180, in encoder_decoder
    prob, enc_attn_weights, coverage_vectors = self.seq_decoder(
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/graph4nlp_cu111-0.5.5-py3.8.egg/graph4nlp/pytorch/modules/prediction/generation/StdRNNDecoder.py", line 577, in forward
    return self._run_forward_pass(**params)
  File "/usr/local/lib/python3.8/dist-packages/graph4nlp_cu111-0.5.5-py3.8.egg/graph4nlp/pytorch/modules/prediction/generation/StdRNNDecoder.py", line 349, in _run_forward_pass
    ) = self.decode_step(
  File "/usr/local/lib/python3.8/dist-packages/graph4nlp_cu111-0.5.5-py3.8.egg/graph4nlp/pytorch/modules/prediction/generation/StdRNNDecoder.py", line 501, in decode_step
    output.scatter_add_(1, src_seq, prob_ptr * ptr_output)
RuntimeError: Index tensor must have the same number of dimensions as self tensor

This error occurs since src_seq has 3 dimensions but output has 2 dimensions. How can I handle this error?

sunnyeo avatar Jun 30 '22 08:06 sunnyeo

I apologize for the late reply since we have been busy during the past two months. Do you still have the problem?

AlanSwift avatar Aug 06 '22 11:08 AlanSwift

Our implementation of copy doesn't support the multi-token copy. I think you should customize it. A straightforward way is to learn a hierarchical copy: I mean first copy the node, and then copy the specific token in the node.

AlanSwift avatar Aug 06 '22 11:08 AlanSwift