I'm trying to use the finetuned model to predict relations in a new sentence, but I cannot find the instructions. Following the OpenNRE, I have tried to add the following code:
_framework.model.infer({"token": ["he", "has", "combined", "intelligent", "history", "with", "moving", "prose", ",", "creating", "an", "informative", ",", "inspiring", "narrative", "telling", "the", "history", "of", "a", "great", "people", "."], "h": {"pos": [14, 15]}, "t": {"pos": [17, 18]}})
But the program raised an error:
Traceback (most recent call last):
File "E:/Project/REDN-master/redn_trainer.py", line 195, in
train(**args_list[0])
File "E:/Project/REDN-master/redn_trainer.py", line 143, in train
_framework.model.infer({"token": ["he", "has", "combined", "intelligent", "history", "with", "moving", "prose", ",", "creating", "an", "informative", ",", "inspiring", "narrative", "telling", "the", "history", "of", "a", "great", "people", "."], "h": {"pos": [14, 15]}, "t": {"pos": [17, 18]}})
File "E:\Project\REDN-master\opennre\model\para.py", line 46, in infer
logits = self.forward(*item)
TypeError: forward() takes 3 positional arguments but 4 were given
Then I found the 45 line of "REDN-master\opennre\model\para.py" called the self.sentence_encoder.tokenize
method and return indexed_tokens, att_mask, new_index
, but the self.forward
seems to need tokens, att_mask
only, so I changed the line 46 to logits = self.forward(item[0], item[1])
, the program still raise the error:
Traceback (most recent call last):
File "E:/Project/REDN-master/redn_trainer.py", line 195, in
train(**args_list[0])
File "E:/Project/REDN-master/redn_trainer.py", line 143, in train
_framework.model.infer({"token": ["he", "has", "combined", "intelligent", "history", "with", "moving", "prose", ",", "creating", "an", "informative", ",", "inspiring", "narrative", "telling", "the", "history", "of", "a", "great", "people", "."], "h": {"pos": [14, 15]}, "t": {"pos": [17, 18]}})
File "E:\Project\REDN-master\opennre\model\para.py", line 48, in infer
logits = self.softmax(logits)
File "C:\Users\HUI\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 550, in call
result = self.forward(*input, **kwargs)
File "C:\Users\HUI\Anaconda3\lib\site-packages\torch\nn\modules\activation.py", line 1044, in forward
return F.softmax(input, self.dim, _stacklevel=5)
File "C:\Users\HUI\Anaconda3\lib\site-packages\torch\nn\functional.py", line 1442, in softmax
ret = input.softmax(dim)
AttributeError: 'tuple' object has no attribute 'softmax'
I am very grateful if anyone can help me to fix this.
Moreover, I use the _framework.model.infer instead of _framework.parallel_model.infer, but the original code train the model using _framework.parallel_model.load_state_dict, as _framework.parallel_model.infer is not implemented. Is that right?