Created
January 25, 2017 11:25
-
-
Save wannaphong/a12a021eecf4649fa8d247165918ecd7 to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
import logging | |
import os.path | |
import sys | |
import multiprocessing | |
from gensim.corpora import WikiCorpus | |
from gensim.models import Word2Vec | |
from gensim.models.word2vec import LineSentence | |
if __name__ == '__main__': | |
program = os.path.basename(sys.argv[0]) | |
logger = logging.getLogger(program) | |
logging.basicConfig(format='%(asctime)s: %(levelname)s: %(message)s') | |
logging.root.setLevel(level=logging.INFO) | |
logger.info("running %s" % ' '.join(sys.argv)) | |
# check and process input arguments | |
if len(sys.argv) < 4: | |
print(globals()['__doc__'] % locals()) | |
sys.exit(1) | |
inp, outp1, outp2 = sys.argv[1:4] | |
model = Word2Vec(LineSentence(inp), size=400, window=5, min_count=5, | |
workers=multiprocessing.cpu_count()) | |
# trim unneeded model memory = use(much) less RAM | |
#model.init_sims(replace=True) | |
model.save(outp1) | |
model.save_word2vec_format(outp2, binary=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment