What does w signify? My first idea is similar to yours where you can clamp w to be within [0,1] but perhaps it might get stuck where w is either 0 or 1. I guess one way would be to try this and see if w changes as you train the network. Another idea is perhaps to add a term to the loss function where you punish it for being larger than 1 and similarly if it’s below 0. Another idea I had is to use a sigmoid?