marekrei / sequence-labeler

Neural network sequence labeling model
252 stars 74 forks source link

a problem about slicing the tensor #3

Closed Moonet closed 6 years ago

Moonet commented 7 years ago

Hi,

I don't know why this bug happened, it seems like tensor cannot be sliced by M[:, slice_num*l:(slice_num+1)*l]

File "/Users/Xin/Documents/17_Spring/sequence-labeler-master/sequence_labeling_experiment.py", line 300, in run_experiment sequencelabeler = SequenceLabeler(config) File "/Users/Xin/Documents/17_Spring/sequence-labeler-master/sequence_labeler.py", line 42, in init char_output_tensor = recurrence.create_birnn(char_input_tensor, config["char_embedding_size"], char_mask_reshaped, config["char_recurrent_size"], return_combined=True, fn_create_parameter_matrix=self.create_parameter_matrix, name="char_birnn") File "/Users/Xin/Documents/17_Spring/sequence-labeler-master/recurrence.py", line 12, in create_birnn recurrent_size, only_return_final=return_combined, go_backwards=False, fn_create_parameter_matrix=fn_create_parameter_matrix, name=name + "_forward") File "/Users/Xin/Documents/17_Spring/sequence-labeler-master/recurrence.py", line 74, in create_lstm go_backwards=go_backwards) File "/Users/Xin/anaconda/lib/python3.5/site-packages/theano/scan_module/scan.py", line 773, in scan condition, outputs, updates = scan_utils.get_updates_and_outputs(fn(args)) File "/Users/Xin/Documents/17_Spring/sequence-labeler-master/recurrence.py", line 34, in lstm_mask_step h_new, c_new = lstm_step(x, h_prev, c_prev, W_x, W_h, b, W_ci, W_cf, W_co) File "/Users/Xin/Documents/17_Spring/sequence-labeler-master/recurrence.py", line 26, in lstm_step i = tensor.nnet.sigmoid(_slice(m_xhb, 0, 4) + c_prev W_ci) File "/Users/Xin/Documents/17_Spring/sequence-labeler-master/recurrence.py", line 47, in _slice return M[:, slice_numl:(slice_num+1)l] File "/Users/Xin/anaconda/lib/python3.5/site-packages/theano/tensor/var.py", line 519, in getitem theano.tensor.subtensor.Subtensor.convert(arg) File "/Users/Xin/anaconda/lib/python3.5/site-packages/theano/tensor/subtensor.py", line 370, in convert slice_a = Subtensor.convert(a, False) File "/Users/Xin/anaconda/lib/python3.5/site-packages/theano/tensor/subtensor.py", line 349, in convert raise TypeError("Expected an integer") TypeError: Expected an integer

marekrei commented 7 years ago

In your error message it says "slice_numl" instead of "slice_num*l". Have you edited the code?

Moonet commented 7 years ago

Well, sorry about that, because markdown style omits the , actually, my code has the

marekrei commented 7 years ago

Not sure what might be causing this then. Works fine on my machines. It even crashes at constructing the computation graph, before processing any data. Perhaps you're using an old version of Theano?

Moonet commented 7 years ago

I am using Theano 0.9.0. m_xhb's type I checked under debug mode is TensorType(float64,scalar) belonging to invalid_tensor_types in subtensor.py. I don't know why this happened

marekrei commented 7 years ago

Right. Seems that I'm the one using the old Theano. When I was developing this code, 0.8.2 was still the default version. I just tried with Theano 0.9 and it actually failed already on importing Lasagne. Apparently the stable version of Lasagne (0.1) doesn't support the latest stable version of Theano (0.9). That's unfortunate. I will find some time to update the code to work with Theano 0.9, possibly looking into options for removing the Lasagne dependency. Until then, using Theano 0.8.* is probably the best bet.

Moonet commented 7 years ago

Yes, thank you, and it seems like "lasagne 0.2.dev1" is compatible with Theano 0.9. Maybe you can try updating the development version and find out whether there is a bug like mine.

Moonet commented 7 years ago

I have tried running my codes under Theano 0.8.2 and Lasagne (0.1) and same bugs happened. Maybe it is my laptop's problem and I will try the code on another laptop. Anyway, thanks for your help.

Moonet commented 7 years ago

The code ran on my friend's laptop also has this bug, now I don't quite understand why.

marekrei commented 7 years ago

What version of the code are you using? Your error message says it comes from line 47 in recurrence.py, but that line is different from the version that's online. Can you try a clean unmodified version of the code, with Theano 0.8.2 and Lasagne 0.1? Preferably on a Linux/Ubuntu machine.

Moonet commented 7 years ago

I use the newest version and the difference happened is because I add two lines to print out some variable which I think it doesn't matter. Actually, I tried a clean version of the code on Mac OS system using python 3.5 and it didn't work.

marekrei commented 7 years ago

I haven't tested it with python3 really. Can you try if it works with python 2.7?

chrisjbryant commented 6 years ago

Been doing some testing of my own with Python3 and came across the same error. It seems the bug was caused by a difference in division operators between python2 and python3. Changing all / to // in the _slice function in recurrence.py seemed to solve the problem. See https://docs.scipy.org/doc/numpy/reference/generated/numpy.true_divide.html

marekrei commented 6 years ago

This should be solved now - the code can run in python3.