uwnlp/open_type

slice indices must be integers or None or have an __index__ method

jackxpeng opened this issue · 0 comments

I kept getting "TypeError: slice indices must be integers or None or have an index method" errors. I fixed it by casting floats to integers in models.py:

def sorted_rnn(self, sequences, sequence_lengths, rnn):
    sorted_inputs, sorted_sequence_lengths, restoration_indices = sort_batch_by_length(sequences, sequence_lengths)
    packed_sequence_input = pack_padded_sequence(sorted_inputs,
                                                 [int(_) for _ in sorted_sequence_lengths.data.tolist()],
                                                 batch_first=True)
    packed_sequence_output, _ = rnn(packed_sequence_input, None)
    unpacked_sequence_tensor, _ = pad_packed_sequence(packed_sequence_output, batch_first=True)
    return unpacked_sequence_tensor.index_select(0, restoration_indices)