public static void skipGram ( ) throws IOException , TException , InterruptedException , UnknownWordException { List < String > read = Common . readToList ( new File ( "sents.cleaned.word2vec.txt" ) ) ; List < List < String > > partitioned = Lists . transform ( read , new Function < String , List < String > > ( ) { @ Override public List < String > apply ( String input ) { return Arrays . asList ( input . split ( " " ) ) ; } } ) ; Word2VecModel model = Word2VecModel . trainer ( ) . setMinVocabFrequency ( 100 ) . useNumThreads ( 20 ) . setWindowSize ( 7 ) . type ( NeuralNetworkType . SKIP_GRAM ) . useHierarchicalSoftmax ( ) . setLayerSize ( 300 ) . useNegativeSamples ( 0 ) . setDownSamplingRate ( 1e-3 ) . setNumIterations ( 5 ) . setListener ( new TrainingProgressListener ( ) { @ Override public void update ( Stage stage , double progress ) { System . out . println ( String . format ( "%s is %.2f%% complete" , Format . formatEnum ( stage ) , progress * 100 ) ) ; } } ) . train ( partitioned ) ; try ( ProfilingTimer timer = ProfilingTimer . create ( LOG , "Writing output to file" ) ) { FileUtils . writeStringToFile ( new File ( "300layer.20threads.5iter.model" ) , ThriftUtils . serializeJson ( model . toThrift ( ) ) ) ; } interact ( model . forSearch ( ) ) ; }
Example using Skip - Gram model