RaleLee / DialogueGCN

A preprocessing and training code for DialogueGCN on Dailydialogue and Mastodon dataset. Use Bert base to preprocess the sentences. Based on https://github.com/declare-lab/conv-emotion/tree/master/DialogueGCN
27 stars 3 forks source link

TypeError: forward() takes from 3 to 4 positional arguments but 5 were given #1

Closed lhzd closed 2 years ago

lhzd commented 3 years ago

您好,我在运行DialDialogGCN模型时,遇到以下问题: TypeError Traceback (most recent call last) /mnt/external/alfredcao/CauseGCN/DialogueGCN-master/train_IEMOCAP.py in 331 332 if args.graph_model: --> 333 train_loss, trainacc, , _, trainfscore, , , , , = train_or_eval_graph_model(model, loss_function, train_loader, e, cuda, optimizer, True) 334 valid_loss, validacc, , _, validfscore, , , , , = train_or_eval_graph_model(model, loss_function, valid_loader, e, cuda) 335 test_loss, test_acc, test_label, test_pred, testfscore, , , , , = train_or_eval_graph_model(model, loss_function, test_loader, e, cuda)

/mnt/external/alfredcao/CauseGCN/DialogueGCN-master/train_IEMOCAP.py in train_or_eval_graph_model(model, loss_function, dataloader, epoch, cuda, optimizer, train) 140 lengths = [(umask[j] == 1).nonzero().tolist()[-1][0] + 1 for j in range(len(umask))] 141 --> 142 log_prob, e_i, e_n, e_t, e_l = model(textf, qmask, umask, lengths) 143 label = torch.cat([label[j][:lengths[j]] for j in range(len(label))]) 144 loss = loss_function(log_prob, label)

/opt/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, kwargs) 725 result = self._slow_forward(*input, *kwargs) 726 else: --> 727 result = self.forward(input, kwargs) 728 for hook in itertools.chain( 729 _global_forward_hooks.values(),

/mnt/external/alfredcao/CauseGCN/DialogueGCN-master/model.py in forward(self, U, qmask, umask, seq_lengths) 1062 1063 features, edge_index, edge_norm, edge_type, edge_index_lengths = batch_graphify(emotions, qmask, seq_lengths, self.window_past, self.window_future, self.edge_type_mapping, self.att_model, self.no_cuda) -> 1064 log_prob = self.graph_net(features, edge_index, edge_norm, edge_type, seq_lengths, umask, self.nodal_attention, self.avec) 1065 1066 return log_prob, edge_index, edge_norm, edge_type, edge_index_lengths

/opt/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, kwargs) 725 result = self._slow_forward(*input, *kwargs) 726 else: --> 727 result = self.forward(input, kwargs) 728 for hook in itertools.chain( 729 _global_forward_hooks.values(),

/mnt/external/alfredcao/CauseGCN/DialogueGCN-master/model.py in forward(self, x, edge_index, edge_norm, edge_type, seq_lengths, umask, nodal_attn, avec) 804 def forward(self, x, edge_index, edge_norm, edge_type, seq_lengths, umask, nodal_attn, avec): 805 --> 806 out = self.conv1(x, edge_index, edge_type, edge_norm) 807 out = self.conv2(out, edge_index) 808 emotions = torch.cat([x, out], dim=-1)

/opt/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, kwargs) 725 result = self._slow_forward(*input, *kwargs) 726 else: --> 727 result = self.forward(input, kwargs) 728 for hook in itertools.chain( 729 _global_forward_hooks.values(),

TypeError: forward() takes from 3 to 4 positional arguments but 5 were given

RaleLee commented 3 years ago

It seems like this code caused some misunderstandings. train_IEMOCAP.py is forked from the original repo. And it is a useless code in this repo. You can see preprocess_dailydialog2.py and train_daily_feature.py for more details. I'll remove this code (train_IEMOCAP.py) in next version.

enastarawneh commented 2 years ago

So I found the problem with this...

out = self.conv1(x, edge_index, edge_norm)#, edge_type) line 806 in model.py sends too many arguments based on torch geometric version that goes with pytorch 1.8.1 and cuda 10.2

I ran it once without edge.norm ( give 60.58 F1 score) and once without edge.type (gives 61.73 F1 score) How can I pass both these arguments (create a dict of them ) or rewrite the forward of the RGCN implementation on geometric?

still trying to get dailydialogue to run

RaleLee commented 2 years ago

The code is out = self.conv1(x, edge_index, edge_type, edge_norm) at line 806 in model.py of this repo. It seems that you can pass in two parameters at the same time.

DailogueGCN is based on PyTorch 1.0 and PyTorch Geometric 1.3. Try to use this version.

See PyTorch Geometric 1.3 Docs of RGCNConv, you can pass 4 arguments into the forward() func. forward(x, edge_index, edge_type, edge_norm=None) However, you can only pass 3 arguments into the the forward() func in latest version of RGCNConv. forward(x: Union[torch.Tensor, None, Tuple[Optional[torch.Tensor], torch.Tensor]], edge_index: Union[torch.Tensor, torch_sparse.tensor.SparseTensor], edge_type: Optional[torch.Tensor] = None)

enastarawneh commented 2 years ago

yes I figured that the older version changed Thanks , I may do that. Just started with the code yesterday,

or I may do I little rewrite on the code to have it work on the latest version...

RaleLee commented 2 years ago

Okay, you can try both methods.