I am stuck on this code for last two days and I don’t know where it went wrong. This is exactly the same function as I created in last week assignment. However, only addition is the truncating
. The above all code is OK. I am getting this error:
# The Error
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-14-06057380c3e1> in <module>
1 # Test your function
2 train_pad_trunc_seq = seq_pad_and_trunc(train_sentences, tokenizer, PADDING, TRUNCATING, MAXLEN)
----> 3 val_pad_trunc_seq = seq_pad_and_trunc(val_sentences, tokenizer, PADDING, TRUNCATING, MAXLEN)
4
5 print(f"Padded and truncated training sequences have shape: {train_pad_trunc_seq.shape}\n")
<ipython-input-13-77ef511bb7c0> in seq_pad_and_trunc(sentences, tokenizer, padding, truncating, maxlen)
16
17 # Convert sentences to sequences
---> 18 sequences = tokenizer.texts_to_sequences(sentences)
19
20 # Pad the sequences using the correct padding, truncating and maxlen
/opt/conda/lib/python3.8/site-packages/keras_preprocessing/text.py in texts_to_sequences(self, texts)
279 A list of sequences.
280 """
--> 281 return list(self.texts_to_sequences_generator(texts))
282
283 def texts_to_sequences_generator(self, texts):
/opt/conda/lib/python3.8/site-packages/keras_preprocessing/text.py in texts_to_sequences_generator(self, texts)
307 seq = text
308 else:
--> 309 seq = text_to_word_sequence(text,
310 self.filters,
311 self.lower,
/opt/conda/lib/python3.8/site-packages/keras_preprocessing/text.py in text_to_word_sequence(text, filters, lower, split)
41 """
42 if lower:
---> 43 text = text.lower()
44
45 if sys.version_info < (3,):
AttributeError: 'int' object has no attribute 'lower'
Expected Output:
Padded and truncated training sequences have shape: (144000, 16)
Padded and truncated validation sequences have shape: (16000, 16)
Can someone please help me out? So I can submit the assignment. I am already late for submission.