上海交通大学计算机科学与工程系(CSE)



Word2vec for windows 10 64bitInstall pythonDownload python install package from python with default settingsModify environment此电脑-属性-高级系统设置-环境变量Choose Path and add a new item ‘C:\python27’Test installation of pythonOpen cmd.exeinput `python`, if the windows output like this means the installation is successfulInstall AnacondaDownload anaconda for windows 64bit from `All Users`New a virtual environmentOpen anaconda promptInput `conda create --name word2vec` to new a virtual environmentChange the current environment to the virtual environmentInput `activate word2vec`Install genismInput `conda install gensim`Training word vectorsSave the code as train.pyPS: Change the corpus directory path 1-billion-word-language-modeling-benchmark-r13output/toycontains several tokenized txt filesclass?gensim.models.word2vec.Word2Vec(sentences=None,?size=100,?alpha=0.025,?window=5,?min_count=5,?max_vocab_size=None,?sample=0.001,?seed=1,?workers=3,?min_alpha=0.0001,?sg=0,?hs=0,?negative=5,?cbow_mean=1,?hashfxn=<built-in function hash>,?iter=5,?null_word=0,?trim_rule=None,?sorted_vocab=1,?batch_words=10000,?compute_loss=False)input `python train.py` and the program will save the word vectors as `wv.txt`Check the word vectorsInput `python` and enter the interactive mode of pythonInput following code to load the word vectors in the `wv.txt`import genismmodel=genism.models.Word2Vec(‘wv.txt’)input `model.most_similar(positive=[‘good’],topn=10)` to output the 10 most similar words of `good` in the word vector space.input model.wv[‘good’] to retrieve the vector of `good`Analogyv(king)-v(man)=v(queen)-v(woman)input model.most_similar(positive=['king','woman'],negative=['man'])More information for Ubuntu 16.04 64bitInstall virtualenvOpen terminal and input `sudo apt-get install virtualenv`New a virtual environmentInput `mkdir env` and input `virtualenv env`Install genismInput `sudo apt-get install python-dev`Input `pip install genism`Training word vectorsSave the train.py code like the part for windowsInput `python train.py` to run the codeCheck the word vectorsSame with the part for windows ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download