pavansolapure/opencodez-samples

Fit the Tokenizer on some data before using tfidf mode

Opened this issue · 0 comments

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.