Currently I implement joint loss model and I can’t find out how to add constrain to nn.Parameters.
self.text_scoreweight = nn.Parameter(torch.FloatTensor([1]))
self.graph_scoreweight = nn.Parameter(torch.FloatTensor([1]))
...
score = self.text_scoreweight * textscore + self.graph_scoreweight * graphscore
I’d like to add constrains of
0 < self.text_scoreweight, self.graph_scoreweight < 1
self.text_scoreweight + self.graph_scoreweight = 1
Could you know how to solve it?
P.S.
I’ll now try this but if there would be a better approach and you could give me an advice, I’d appreciate it.
param1 = nn.Parameter(torch.FloatTensor([1]))
param2 = 1 - param1
Parameterlist.append(param1) #(for L2regularize parameter)