chars2vec icon indicating copy to clipboard operation
chars2vec copied to clipboard

Using vectorize_words leads to AttributeError

Open gabecano4308 opened this issue 3 years ago • 3 comments

Hello,

I am using keras ==2.9.0 and tensorflow ==2.9.1. I'm using pretrained eng_50 model like so --

c2v_model = chars2vec.load_model('eng_50')

However, when I use the vectorize_words method on my list of strings, I get the following AttributeError:

c2v_model.vectorize_words(std_job_list)


AttributeError Traceback (most recent call last) in ----> 1 c2v_model.vectorize_words(std_job_list)

~/anaconda3/envs/JupyterSystemEnv/lib/python3.7/site-packages/chars2vec/model.py in vectorize_words(self, words, maxlen_padseq) 150 list_of_embeddings.append(np.array(current_embedding)) 151 --> 152 embeddings_pad_seq = keras.preprocessing.sequence.pad_sequences(list_of_embeddings, maxlen=maxlen_padseq) 153 new_words_vectors = self.embedding_model.predict([embeddings_pad_seq]) 154

AttributeError: module 'keras.preprocessing.sequence' has no attribute 'pad_sequences'

I'm not sure if there's a specific version I need to be using for keras/tensorflow. or if I'm missing something separate Any advice on this would be appreciated! Thanks

gabecano4308 avatar Aug 26 '22 17:08 gabecano4308

I am in the same situation and have the Attribute Error: module 'keras' has no attribute 'preprocessing'

Is it perhaps a versioning issue? What version of Keras was used in this project?

theloni-monk avatar Dec 29 '22 19:12 theloni-monk

I got it to work with tensorflow==2.8.4, keras==2.8.0

helenkimber avatar Jan 05 '23 11:01 helenkimber

I fixed it by replacing Keras with tf.compat.v1.keras in all instances

theloni-monk avatar Jan 05 '23 20:01 theloni-monk