I am trying to do a Topic modeling project, but when I use
from sklearn.feature_extraction import TfidfVectorizer
I will receive this error, my sckit-learn version installed is 0.24.1. I will be grateful if anyone could help me.
ImportError Traceback (most recent call last)
<ipython-input-2-5ae89ed22b7e> in <module>
----> 1 from sklearn.feature_extraction import TfidfVectorizer
ImportError: cannot import name 'TfidfVectorizer' from 'sklearn.feature_extraction' (C:\Users\mozha\Anaconda3\envs\spyder-env\lib\site-packages\sklearn\feature_extraction\__init__.py)
You have to import vectorizers like TfidfVectorizer from sklearn.feature_extraction.text and not sklearn.feature_extraction.
Related
I keep getting this error code from my Jupyter Notebook and there is little to no explanation.
After inputting:
from nltk import pos_tag, RegexpParser
from tokenize_words import word_sentence_tokenize
from chunk_counters import np_chunk_counter, vp_chunk_counter
I get:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-14-a5041508c9f2> in <module>
1 from nltk import pos_tag, RegexpParser
----> 2 from tokenize_words import word_sentence_tokenize
3 from chunk_counters import np_chunk_counter, vp_chunk_counter
ModuleNotFoundError: No module named 'tokenize_words'
The full lesson allows the student to follow along with Jupyter. I don't know why but all it ever gives me is module not found error codes.
I'm currently having trouble importing some simple packages.
I'm working on pycharm professional in a virtual environment.
just trying to load;
import pandas as pd
import numpy as np
from sklearn.ensemble import IsolationForest
from sklearn.ensemble._iforest import _average_path_length
import shap
importError Traceback (most recent call last)
<ipython-input-1-5b7f1bf909af> in <module>
----> 1 import pandas as pd
2 import numpy as np
3 from sklearn.ensemble import IsolationForest
4 from sklearn.ensemble._iforest import _average_path_length
5 import shap
~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pandas\__init__.py in <module>
14
15 if missing_dependencies:
---> 16 raise ImportError(
17 "Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
18 )
ImportError: Unable to import required dependencies:
numpy: cannot import name 'asanyarray' from 'numpy.core.multiarray' (C:\Users\James\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\numpy\core\multiarray.py
I've never come across this error before so don't know how to fix.
import numpy as np
%matplotlib notebook
import matplotlib.pyplot as plt
plt.style.use ('ggplot')
from sklearn.manifold import TSNE
from sklearn.decomposition import PCA
from gensim.test.utils import datapath, get_tmpfile
from gensim.models import KeyedVectors
from gensim.scripts.glove2word2vec import glove2word2vec
Hello everyone, I hope you all are doing well. I am new in DL and NLP. As I am learning I came across this error. Can anyone help me solve this issue? thank you all.
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-13-8db7eebe6f3e> in <module>
7 from sklearn.decomposition import PCA
8
----> 9 from gensim.test.utils import datapath, get_tmpfile
10 from gensim.models import KeyedVectors
11 from gensim.scripts.glove2word2vec import glove2word2vec
ModuleNotFoundError: No module named 'gensim'
I am not able to import Porter; I am facing
ModuleNotFoundError: No module named 'sklearn.tree.tree' error
Code:
from sklearn_porter import Porter
Error message:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-19-574fff36293e> in <module>
----> 1 from sklearn_porter import Porter
2
3 porter = Porter(clf, language='c')
4 output = porter.export()
5
~/.local/lib/python3.8/site-packages/sklearn_porter/__init__.py in <module>
7 from json import load
8
----> 9 from sklearn_porter.Porter import Porter
10
11
~/.local/lib/python3.8/site-packages/sklearn_porter/Porter.py in <module>
8
9 from sklearn.metrics import accuracy_score
---> 10 from sklearn.tree.tree import DecisionTreeClassifier
11 from sklearn.ensemble.weight_boosting import AdaBoostClassifier
12 from sklearn.ensemble.forest import RandomForestClassifier
ModuleNotFoundError: No module named 'sklearn.tree.tree'
I guess your version of sklearn is recent (0.20 or newer). In this case the import fails. You could downgrade sklearn, but this is not suggested. Or you can edit the imports in sklearn_porter/Porter.py by hand. Here are the lines to change.
There is a related pull request on GitHub to close this issue in the future.
This is literally all the code that I am trying to run:
from transformers import AutoModelWithLMHead, AutoTokenizer
import torch
tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-small")
model = AutoModelWithLMHead.from_pretrained("microsoft/DialoGPT-small")
I am getting this error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-14-aad2e7a08a74> in <module>
----> 1 from transformers import AutoModelWithLMHead, AutoTokenizer
2 import torch
3
4 tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-small")
5 model = AutoModelWithLMHead.from_pretrained("microsoft/DialoGPT-small")
ImportError: cannot import name 'AutoModelWithLMHead' from 'transformers' (c:\python38\lib\site-packages\transformers\__init__.py)
What do I do about it?
I solved it! Apperantly AutoModelWithLMHead is removed on my version.
Now you need to use AutoModelForCausalLM for causal language models, AutoModelForMaskedLM for masked language models and AutoModelForSeq2SeqLM for encoder-decoder models.
So in my case code looks like this:
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-small")
model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-small")