I have reviewed threads for this particular subject, but none of the solutions are applicable to my situation and I need help with this, please. I am trying to prep my data for training using neural language model. My data has already been pre-processed and stored in text file. The sample data is as follows: ["restaurant", "paris", "district", "gunman", "held", "hostage"...] and the array shape is (10848135,), as per array shape attribute. However I get an index error message when I try to slice the data with statement X, y = sequences[:,:-1], sequences[:,-1]
The code is as follows:
def encode_words(self, dataset):
data = dataset.split('\n')
tokenizer = Tokenizer()
tokenizer.fit_on_texts(dataset)
sequences = tokenizer.texts_to_sequences(dataset)
vocab_size = len(tokenizer.word_index) + 1
sequences = array(sequences)
X, y = sequences[:,:-1], sequences[:,-1]
y = to_categorical(y, num_classes=vocab_size)
seq_length = X.shape[1]
return X, y, vocab_size, seq_length, tokenizer
I understand what the error is, but don't know how to fix this. Please I need assistance to get the code working. Below is the full error message:
Traceback (most recent call last):
File "/home/asifa/anaconda3/deep_learning_project/processor.py", line 15, in <module>
X,y,vocab_size,seq_length,tokenizer = emb.encode_words(seq_data)
File "/home/asifa/anaconda3/deep_learning_project/WordEmbedding.py", line 67, in encode_words
X, y = sequences[:,:-1], sequences[:,-1]
IndexError: too many indices for array
sequencesonly has a single axis. You'll need to reshape it to have two axes. - David Hoffmandtypeofsequences? - hpauljsequencesin more detail. 1d object dtype is probably an array of lists or arrays - and those lists vary in size. Until you understand the exact nature of that array, you can't reshape or slice in a meaningful way. - hpauljFile "/home/asifa/anaconda3/envs/researchProject/lib/python3.6/site-packages/keras/utils/np_utils.py", line 25, in to_categorical y = np.array(y, dtype='int') ValueError: setting an array element with a sequence.Pls any idea how I can fix this ? - Eddy