이끼의 생각

파이썬 gensim 에러/오류 DeprecationWarning 본문

인공지능(머신러닝 &딥러닝 )구현/Google Word2Vec

파이썬 gensim 에러/오류 DeprecationWarning

IKKIson 2019. 4. 19. 17:13

구글의 Word2Vec를 사용하여 자연어 학습 신경망을 구현하는 경우 가장 많이 사용되는 모듈이다.

gensim의 기능들을 사용하면서 가끔 gensim.models.KeyedVectors.load_word2vec_format으로 로드하면서 DeprecationWarning 오류를 발견할 수 있다.

 

상황에 따라 이를 대체할 수 있는 방법은 다음과 같다.

 

<Before>

import gensim

# Load Google's pre-trained Word2Vec model.
model = gensim.models.Word2Vec.load_word2vec_format('./model/GoogleNews-vectors-negative300.bin', binary=True)  

<After>

import gensim.models.keyedvectors as word2vec

mymodel = word2vec.KeyedVectors.load_word2vec_format(path_to_word2vec, binary=True)

 

이 방법은 임시 방책일 뿐, 규모가 있거나 복잡한 구조에서 즉각적인 대응이 안되므로 올바른 Gensim 사용법을 찾아가면서 수정하는것이 현명할 것이다.

Comments