Natural Language Processing in TensorFlow: Week 3: Exploring Overfitting in NLP

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.

1 Like

Hi @huzaifa_arshad,

Is this query from NLP C3 W3’s assignment ? I haven’t been able to find the function def seq_pad_and_trunc in there.

If you could let me know which assignment this is from, I’ll be better able to help you out.

Also, posting the solution code publicly is against the honour code of our community, hence I’m removing it.

Best,
Mubsi

Hi. Thanks for reply. This ‘NLP in TensorFlow’ is a course in DeepLearning.AI TensorFlow Developer Professional Certificate. This graded assignment is “Week 3: Exploring Overfitting in NLP”. I am stuck and don’t know why I am getting the error.

Hi @huzaifa_arshad,

As you mentioned, this is from the Tensorflow Specialisation, but you have posted this in the Natural Language Processing specialisation category, which a completely different specialisation.

I’m moving this to the TF specialisation so that the mentors there can help you out. In the future, please be sure where you post your queries so that the appropriate people can help you out timely,

Cheers,
Mubsi

Thanks. I am new and dont know how to use this site

Hi @tf1_mentors,

Can anyone of you help here ?

Thanks,
Mubsi

1 Like

Hi @huzaifa_arshad,

We have this user guide which you can go through to better understand how to navigate our community.

Best,
Mubsi

1 Like

can you DM me your code as notebook?

@huzaifa_arshad I think you have made some mistake in parse_data_from_file function please check that again.

2 Likes

Okay let me check it