Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for those who meet cannot import name 'Mapping' from 'collections' #28

Open
tae0y opened this issue Aug 19, 2023 · 0 comments
Open

for those who meet cannot import name 'Mapping' from 'collections' #28

tae0y opened this issue Aug 19, 2023 · 0 comments

Comments

@tae0y
Copy link

tae0y commented Aug 19, 2023

some modules in collections has changed its position.
please follow the source where the error occurred,
and correct package name like below.

  • gensim/corpora/dictionary.py
#old: from collectionsimport Mapping
from collections.abc import Mapping
  • gensim/models/doc2vec.py
#old: from collections import Iterable
from collections.abc import Iterable
  • gensim/models/fasttext.py
#old: from collections import Iterable
from collections.abc import Iterable

my environments

  • osx with m1, python 3.10.10, venv virtual environment
  • packages
gensim==3.8.1
numpy==1.25.2
scipy==1.11.2
six==1.16.0
smart-open==6.3.0

my code

from gensim.models import Word2Vec

ko_model = Word2Vec.load('./ko/ko.bin')

while True:
    query = input('Query: ')
    if query == "exit":
        break
    try:
        answer = ko_model.wv.most_similar(query)
        print(f'Answer: {answer}')
    except Exception as error:
        print(f'Error: {error}')

when running my code

Query: 강아지
/Users/bachtaeyeong/PROJECTS/pythonProjects/word2vec/main.py:14: DeprecationWarning: Call to deprecated `most_similar` (Method will be removed in 4.0.0, use self.wv.most_similar() instead).
  answer = ko_model.most_similar(query)
Answer:  [('고양이', 0.7290452718734741), ('거위', 0.7185635566711426), ('토끼', 0.7056223750114441), ('멧돼지', 0.6950401067733765), ('엄마', 0.693433403968811), ('난쟁이', 0.6806551218032837), ('한마리', 0.6770296096801758), ('아가씨', 0.6750353574752808), ('아빠', 0.6729634404182434), ('목걸이', 0.6512461304664612)]

Query: 시장
Answer:  [('도매', 0.6068975925445557), ('점유율', 0.5579971671104431), ('증시', 0.5483343005180359), ('내수', 0.54777592420578), ('농수산물', 0.5392422080039978), ('대기업', 0.5372408628463745), ('기업', 0.5371351838111877), ('미두', 0.5245275497436523), ('코스닥', 0.5162377953529358), ('중소기업', 0.5123578310012817)]   

🤓 thanks for reading! If you know any other solution, please share yours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant