Last active
April 10, 2021 02:51
-
-
Save kanekomasahiro/3c75b219471ae45a3c97e6b31127985f to your computer and use it in GitHub Desktop.
gensimのembeddingをloadする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import linecache | |
from gensim.models import KeyedVectors | |
def load_embedding_with_gensim(embedding_name): | |
''' | |
Load embeddings with gensim. | |
''' | |
if embedding_name.endswith('bin'): | |
binary = True | |
no_header = False | |
else: | |
binary = False | |
if linecache.getline(embedding_name, 1).split() == 2: | |
no_header = False | |
else: | |
no_header = True | |
embedding = KeyedVectors.load_word2vec_format(embedding_name, binary=binary, no_header=no_header) | |
return embedding |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment