pytorch-sentiment-neuron icon indicating copy to clipboard operation
pytorch-sentiment-neuron copied to clipboard

RuntimeError: can't assign a str to a scalar value of type int

Open Damonhaus opened this issue 7 years ago • 2 comments

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: 7zt h ozf8utywnxs _zqx

does the code can't run on python-2.7 or other problem?

thanks a lot.

Damonhaus avatar May 22 '17 09:05 Damonhaus

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

guillitte avatar May 22 '17 14:05 guillitte

@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

rsteca avatar Aug 15 '17 20:08 rsteca