Mustafa Abdulkareem
Mustafa Abdulkareem

Reputation: 3

TypeError: texts_to_matrix() got an unexpected keyword argument 'num_words'

python code

enter image description here

the problem is when uploading a txt file and try to run the code as shown in the picture I'll get the error

TypeError: texts_to_matrix() got an unexpected keyword argument 'num_words'

Upvotes: 0

Views: 337

Answers (2)

Palash Mondal
Palash Mondal

Reputation: 538

An alternative solution if you are reading the model from your directory then follow the steps:

    import pickle
    with open('./outputs/tokenizer'+model_name+'.pickle', 'rb') as handle:
         tokenizer = pickle.load(handle)
 
    tokenizer.num_words = 10000

If you face the dimensions mismatch then you can verify what is the pre-define num_words. Just run -

print(tokenizer.num_words)

Upvotes: 0

Swapnil Pote
Swapnil Pote

Reputation: 136

You passing "num_words" argument at wrong place. Check below code snippet.

from tf.keras.preprocessing.text import Tokenizer

tokenizer = Tokenizer(num_words=10)
tokenizer.texts_to_matrix(texts, mode="binary")

Checkout this official documentation https://www.tensorflow.org/api_docs/python/tf/keras/preprocessing/text/Tokenizer

Upvotes: 1

Related Questions