pytorch-sentiment-neuron
pytorch-sentiment-neuron copied to clipboard
RuntimeError: can't assign a str to a scalar value of type int
When I sample the model with command:
python visualize.py -seq_length 1000 -cuda -load_model mlstm_ns.pt -temperature 0.4 -neuron 2388 -init "I couldn't figure out"
and the process returned an error:
does the code can't run on python-2.7 or other problem?
thanks a lot.
The code was written in python 3.5 and I suspect the problem comes from the differences in string handling between python 2.7 and 3.5
@Damonhaus To use in Python 2, change the batchify function for this:
def batchify(data, bsz):
ids = torch.LongTensor([ord(char) for char in data.encode()])
nbatch = ids.size(0) // bsz
ids = ids.narrow(0, 0, nbatch * bsz)
ids = ids.view(bsz, -1).t().contiguous()
return ids