VScode Throws:ModuleNotFoundError: No module named 'keras.preprocessing.text' even though it is installed properly?

40 Views Asked by At

Below is my whole code.

https://github.com/mishraatharva/text_classification

When ever I am trying to run my code I am getting following error:

Error:

[nltk_data] Downloading package stopwords to [nltk_data] C:\Users\Naruto\AppData\Roaming\nltk_data... [nltk_data] Package stopwords is already up-to-date! 2024-03-27 22:35:43.217542: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable TF_ENABLE_ONEDNN_OPTS=0. 2024-03-27 22:35:43.760781: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable TF_ENABLE_ONEDNN_OPTS=0. Traceback (most recent call last): File "C:\Users\Naruto\Desktop\generative_ai\PROJECTS\text_classification\app.py", line 1, in from hate.pipeline.train_pipeline import TrainPipeline File "C:\Users\Naruto\Desktop\generative_ai\PROJECTS\text_classification\hate\pipeline\train_pipeline.py", line 6, in from hate.components.model_trainer import ModelTrainer File "C:\Users\Naruto\Desktop\generative_ai\PROJECTS\text_classification\hate\components\model_trainer.py", line 9, in from keras.preprocessing.text import Tokenizer ModuleNotFoundError: No module named 'keras.preprocessing.text'`

Even though I have imported the required modules clearly.

Import statement

And bellow is my code where I am trying to use Tokenizer.

def tokenizing(self,x_train):
        try:
            logging.info("Applying tokenization on the data")
            tokenizer = Tokenizer(num_words=self.model_trainer_config.MAX_WORDS)
            tokenizer.fit_on_texts(x_train)
            sequences = tokenizer.texts_to_sequences(x_train)
            logging.info(f"converting text to sequences: {sequences}")
            sequences_matrix = pad_sequences(sequences,maxlen=self.model_trainer_config.MAX_LEN)
            logging.info(f" The sequence matrix is: {sequences_matrix}")
            return sequences_matrix,tokenizer
        except Exception as e:
            raise CustomException(e, sys) from e

I found below post of stackoverflow, but did't help.

https://stackoverflow.com/questions/42725140/importerror-no-module-named-keras-preprocessing

Thanks in advence. I hope to hear from you soon.

0

There are 0 best solutions below