Skip to content

Fit the Tokenizer on some data before using tfidf mode #4

@bukharilab

Description

@bukharilab

Hi,
I am trying to run your code. However, I am getting the following error. I have fitted the tokenizer as following.

tokenizer.fit_on_texts(train_posts)

print(tokenizer.texts_to_matrix(train_posts, mode='count'))

I am using python 3 with keras 2.2.2 and tensorflow 1.9.0. Can you please help me to fox this issue?

Thanks
----------------- Error -----------------------
Traceback (most recent call last):
File "", line 1, in
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_bundle/pydev_umd.py", line 194, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/Ahmad/mydevelopment/datasciencePractice/textclassificationwithleras.py", line 99, in
x_train = tokenizer.texts_to_matrix(train_posts, mode='tfidf')
File "/Users/Ahmad/anaconda3/envs/datasciencePractice/lib/python3.6/site-packages/keras_preprocessing/text.py", line 376, in texts_to_matrix
return self.sequences_to_matrix(sequences, mode=mode)
File "/Users/Ahmad/anaconda3/envs/datasciencePractice/lib/python3.6/site-packages/keras_preprocessing/text.py", line 403, in sequences_to_matrix
raise ValueError('Fit the Tokenizer on some data '
ValueError: Fit the Tokenizer on some data before using tfidf mode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions