How to import WordEmbeddingSimilarityIndex function from gensim module? - python-3.x

When i try to import WordEmbeddingSimilarityIndex, it's giving me the following error:
>> from gensim.models import WordEmbeddingSimilarityIndex
ImportError: cannot import name 'WordEmbeddingSimilarityIndex
The same issue occurs for SparseTermSimilarityMatrix function:
>> from gensim.similarities import SparseTermSimilarityMatrix
ImportError: cannot import name 'SparseTermSimilarityMatrix
Note: I have installed and imported gensim, gensim.models and gensim.similarities. But still it's giving me the ImportError while importing the above mentioned functions.
Can you tell me what I am doing wrong, please?

Fix is change "models" to "similarities"
from gensim.similarities import WordEmbeddingSimilarityIndex
it works in gensim 4.0.1

Try to check the version of gensim that you are using. Usually, the older versions of gensim cause this issue.
from gensim.models import WordEmbeddingSimilarityIndex
print(gensim.__version__)
if the gensim version is 3.6.x or older update it to 3.7.x or latest version by running the below command. Once you update gensim version should get rid of this issue.
pip install --upgrade gensim

Related

Cannot import sparkdl into databricks notebook

As I said in the title, I cannot import sparkdl module into databricks.
I followed step by step this official tutorial sparkdl tutorial but when I simply put some code like:
from sparkdl import readImages
I get an error that says I cannot import readImages from sparkdl, the same for other classes such DeepImageFeaturizer.
I checked and It seems there is some sort of problem with the versions of keras,tensorflow,sparkdl,h5py and the maven library spark-deep-learning so I'm looking for a stable combination beetween them.
Taking into account that from Databricks I can only install tensorflow from 2.5.0 up to newer version.
With the following versions:
tensorflow v 2.5.0, keras 2.2.4, 1.4.0-spark-deep-learning,h5py v 3.7.0
I Got the following error while importing DeepImageFeaturizer
from sparkdl import DeepImageFeaturizer ImportError: cannot import name 'resnet50' from 'keras.applications' (/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/keras/applications/__init__.py)
Any help or suggestion will be really appreciated

Pytorch/Ktrain import name BartForConditionalGeneration from transformers error?

I am trying to use the package ktrain's text function
text.TransformerSummarizer()
However, when I try to use it I get the error that
TransformerSummarizer() requires PyTorch to be installed.
I installed PyTorch using different variations of conda and pip, as well as the command given on the pytorch website. After it installs and I try to use it I get:
from ktrain import text
import torch
from transformers import BartForConditionalGeneration
ts = text.TransformerSummarizer()
ImportError: cannot import name 'BartForConditionalGeneration' from 'transformers' (C:\Users\user\AppData\Roaming\Python\Python37\site-packages\transformers\__init__.py)
Any suggestions of how to fix this? Thank you!

ImportError: cannot import name '_print_elapsed_time'

Hi so I'm trying to use the make_pipeline module in sklearn. But when I try to import it with:
from sklearn.pipeline import make_pipeline
I get this error:
ImportError: cannot import name '_print_elapsed_time'
I've googled it but there seems to be no other posts about this. I tried reinstalling scikitlearn but I still get the same error :/ Anyone have any ideas?
It looks like this was a bug introduced into one of the newer versions of scikit-learn (I got this same issue in version 0.21.2).
I was able to fix this by downgrading to scikit-learn version 0.20.0
>> pip install scikit-learn==0.20.0

Cannot import Sklearn from sklearn.externals.joblib

I am a beginner and I just started with machine learning. I am trying to import classes like imputer from sklearn but i am unable to do it.
from sklearn.preprocessing import Imputer,LabelEncoder,OneHotEncoder,StandardScaler
ImportError: cannot import name 'version' from
'sklearn.externals.joblib'
(C:\ProgramData\Anaconda3\lib\site-packages\sklearn\externals\joblib__init__.py)
I had the same problem.
I have replaced
from sklearn.externals import joblib
with
import joblib
and it works fine in Python 3.7.2
I believe there was an update on Scikit-learn that render that import unusable.
I had my local installation to be version 0.20.3 and this import is pefectly working. But on my server I have installation 0.23.1 and this error pop up. Something must be chaging in the new version.
For my case, use import joblib fix the problem. In your case it seems more complicated. This sounds very much likeky to be caused if you have more than one Scikit-learn version installed on your system. You need to uninstall all of them and do a clean install of sklearn.
The problem sometimes happens due to the version. This may help:
If you has written like this
from sklearn.externals import joblib
Modify it as this:
import joblib
Try
python -m pip install sklearn --upgrade
and
python -m pip install joblib --upgrade
and then, use this :
import joblib
Good luck.
import joblib
This works for me. Actually I was having that kinda challenge

Can't import GMM function from sckits.learn

I'm getting error ImportError: No module named gmm when I'm using from scikits.learn.gmm import GMM..
I installed scikits using windows installer and no error..
How I can fix it?
That link is very old, the module name was renamed to sklearn as you have installed version 0.16.1 you should be using
from sklearn.mixture import GMM
as per the docs

Resources