@@ -0,0 +1,2472 @@
+package org.deeplearning4j.word2vec;%0A%0Aimport org.deeplearning4j.models.word2vec.Word2Vec;%0Aimport org.deeplearning4j.models.word2vec.wordstore.VocabCache;%0Aimport org.deeplearning4j.models.word2vec.wordstore.inmemory.InMemoryLookupCache;%0Aimport org.deeplearning4j.text.corpora.breaker.FileCorpusBreaker;%0Aimport org.deeplearning4j.text.documentiterator.DocumentIterator;%0Aimport org.deeplearning4j.text.documentiterator.FileDocumentIterator;%0Aimport org.deeplearning4j.text.sentenceiterator.SentenceIterator;%0Aimport org.deeplearning4j.text.sentenceiterator.UimaSentenceIterator;%0Aimport org.deeplearning4j.text.tokenization.tokenizerfactory.DefaultTokenizerFactory;%0Aimport org.deeplearning4j.text.tokenization.tokenizerfactory.TokenizerFactory;%0Aimport org.deeplearning4j.text.tokenization.tokenizerfactory.UimaTokenizerFactory;%0Aimport org.deeplearning4j.text.uima.UimaResource;%0Aimport org.deeplearning4j.util.SerializationUtils;%0A%0Aimport java.io.BufferedReader;%0Aimport java.io.File;%0Aimport java.io.InputStreamReader;%0A%0A/**%0A * Created by agibsonccc on 9/20/14.%0A */%0Apublic class Word2VecExample %7B%0A%09private DocumentIterator iter;%0A%09private TokenizerFactory tokenizer;%0A%09private Word2Vec vec;%0A%0A%09public Word2VecExample(String path) throws Exception %7B%0A%09%09this.iter = new FileDocumentIterator(path);%0A%09%09tokenizer =  new DefaultTokenizerFactory();%0A%09%7D%0A%0A%09public static void main(String%5B%5D args) throws Exception %7B%0A%09%09new Word2VecExample(args%5B0%5D).train();%0A%09%7D%0A%0A%0A%09public void train() throws Exception %7B%0A%09%09VocabCache cache;%0A%09%09if(vec == null && !new File(%22vec.ser%22).exists()) %7B%0A%09%09%09cache = new InMemoryLookupCache(100,true);%0A%0A%09%09%09vec = new Word2Vec.Builder().minWordFrequency(1).vocabCache(cache)%0A%09%09%09%09%09.windowSize(5)%0A%09%09%09%09%09.layerSize(100).iterate(iter).tokenizerFactory(tokenizer)%0A%09%09%09%09%09.build();%0A%09%09%09vec.setCache(cache);%0A%09%09%09vec.fit();%0A%0A%0A%09%09%09SerializationUtils.saveObject(vec, new File(%22vec.ser%22));%0A%09%09%09SerializationUtils.saveObject(cache,new File(%22cache.ser%22));%0A%0A%09%09%7D%0A%0A%0A%09%09else %7B%0A%09%09%09vec = SerializationUtils.readObject(new File(%22vec.ser%22));%0A%09%09%09cache = SerializationUtils.readObject(new File(%22cache.ser%22));%0A%09%09%09vec.setCache(cache);%0A%09%09%09for(String s : cache.words()) %7B%0A%09%09%09%09System.out.println(s);%0A%09%09%09%7D%0A%0A%09%09%09BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));%0A%09%09%09String line;%0A%09%09%09System.out.println(%22Print similarity%22);%0A%09%09%09while((line = reader.readLine()) != null) %7B%0A%0A%09%09%09%09String%5B%5D split = line.split(%22,%22);%0A%09%09%09%09System.out.println(vec.similarity(split%5B0%5D,split%5B1%5D));%0A%09%09%09%7D%0A%0A%0A%0A%0A%09%09%7D%0A%0A%0A%0A%0A%0A%0A%09%7D%0A%0A%0A%7D%0A

add word2vec example