lanyunshi/Multi-hopComplexKBQA

Python: TypeError: unsupported operand type(s) for +=: 'float' and 'list'

Closed this issue · 6 comments

yhshu commented

topic_score += 0. if w not in te else te[w][0] if tokenizer.dataset in ['CQ'] else te[w] # if M2N[w] in batch.raw_question

I'm using Python 3.7.6. There's an error when I'm trying to run:

TypeError: unsupported operand type(s) for +=: 'float' and 'list' 

I guess it should be topic_score = topic_score + 0. if ...

May I know which dataset you are running?

yhshu commented

May I know which dataset you are running?

I'm running it on dataset CQ.

Can you print out ''te[w][0]'' or ''te[w]''?

yhshu commented

Can you print out ''te[w][0]'' or ''te[w]''?

they are [0.003073975978407299, 'anger management'] and 0.003073975978407299 respectively.

I haven't encountered such an issue. I think the problem is that the 'topic_score' is a list in your case, but I have set it as a scalar at the beginning, can you double-check whether 'tokenizer.dataset' is 'CQ' or the 'topic_score' is a scalar?

yhshu commented

I haven't encountered such an issue. I think the problem is that the 'topic_score' is a list in your case, but I have set it as a scalar at the beginning, can you double-check whether 'tokenizer.dataset' is 'CQ' or the 'topic_score' is a scalar?

I found that tokenizer.data is wrong...
Because the data is not a subdirectory of code, so I changed the default program parameter in the .sh and obtained the wrong value.

I've fixed this issue and thanks a lot.