Search code examples
kerasstringtokenizertxt

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'


Solution

  • 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