ImportError: cannot import name 'deprecated' when import gensim - python-3.x

everyone!
I'm trying to import gensim on jupyter but I got the following error:
ImportError: cannot import name 'deprecated'
What can I do?
PS: I tried in gensim version 3.8.1 and 3.8.3

Related

Ordinal Logistic Regression in python and Google Colab

I have been trying to import statmodels (https://www.statsmodels.org/devel/examples/notebooks/generated/ordinal_regression.html#Probit-ordinal-regression:) to google colab without success.
I tried pip install statmodels which worked but then when I tried to import the ordinal model following the code from the above website:
import numpy as np
import pandas as pd
import scipy.stats as stats
from statsmodels.miscmodels.ordinal_model import OrderedModel
The following error message came up:
ModuleNotFoundError: No module named 'statsmodels.miscmodels.ordinal_model'
I have tried to follow the instruction from https://www.statsmodels.org/devel/install.html but I am not sure what went wrong, please help, thank you so much
The module location has changed to from statsmodels.discrete.discrete_model import OrderedModel

ImportError: cannot import name 'maybe_sync' from 'fsspec.asyn'

I am getting the following error while using simpletransformer library on Saturn cloud.
from simpletransformers.classification import ClassificationModel
ImportError: cannot import name 'maybe_sync' from 'fsspec.asyn' (/srv/conda/envs/saturn/lib/python3.7/site-packages/fsspec/asyn.py)
I am not getting this error while using Google Colab.
I tried to install older versions of s3fs==0.5.1 and fsspec==0.8.4 but it's not working.

ImportError: cannot import name 'cluster_resolver'

I get this error when trying to setup Unity3d ml-agents
ImportError: cannot import name 'cluster_resolver'
Following https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Installation.md tutorial
from tensorflow.contrib import cluster_resolver
Error happens when I try to run mlagents-learn --help
I am on MacOS with Python 3.6
Fixed by using Tensorflow 1.7.0 instead of 1.7.1 as in the tutorial.

How to import WordEmbeddingSimilarityIndex function from gensim module?

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

ImportError: cannot import name '_obtain_input_shape' from keras

In Keras,
I'm trying to import _obtain_input_shape as follows:
from keras.applications.imagenet_utils import _obtain_input_shape
However, I get the following error:
ImportError: cannot import name '_obtain_input_shape'
The reason I'm trying to import _obtain_input_shape is so that I can determine the input shape(so as to load VGG-Face as follows :
I'm using it to determine the correct input shape of the input tensor as follow:
input_shape = _obtain_input_shape(input_shape,
default_size=224,
min_size=48,
data_format=K.image_data_format(),
require_flatten=include_top)`
Please assist?
Thanks in advance.
You don't have to downgrade Keras 2.2.2.
In Keras 2.2.2 there is no _obtain_input_shape method in the keras.applications.imagenet_utils module. You can find it under keras-applications with the modul name keras_applications (underscore).
So you don't have to downgrade your Keras to 2.2.0 just change:
from keras.applications.imagenet_utils import _obtain_input_shape
to
from keras_applications.imagenet_utils import _obtain_input_shape
I have found a method that works well. You just use
from keras_applications.imagenet_utils import _obtain_input_shape
Notice: It is keras_applications instead of keras.application.
This issue occured because of the version of keras.
In my case, I was downgrade keras 2.2.2 to 2.2.0, and the problem was solved.
In Colab I solved it by importing Keras and installing :
import keras
!pip install keras_applications
from keras_applications.imagenet_utils import _obtain_input_shape
keras_applications.imagenet_utils is deprecated
Traceback (most recent call last):
File "inception_v3.py", line 36, in
from keras_applications.imagenet_utils import _obtain_input_shape
ModuleNotFoundError: No module named 'keras_application
from keras.applications.imagenet_utils import obtain_input_shape
Not _obtain_input_shape. This works fine with keras==2.5.0rc0 (pip install keras==2.5.0rc0)
for keras 2.2.4:
Change the line like below to make it work.
from keras_applications.imagenet_utils import _obtain_input_shape
Note: It is importing from keras_applications and does not from keras.applications as before.

Resources