Search in sources :

Example 1 with BarnesHutTsne

use of org.deeplearning4j.plot.BarnesHutTsne in project deeplearning4j by deeplearning4j.

the class ApiTest method testUpdateCoords.

@Test
@Ignore
public void testUpdateCoords() throws Exception {
    Nd4j.ENFORCE_NUMERICAL_STABILITY = true;
    Nd4j.factory().setDType(DataBuffer.Type.DOUBLE);
    Nd4j.getRandom().setSeed(123);
    BarnesHutTsne b = new BarnesHutTsne.Builder().stopLyingIteration(250).theta(0.5).learningRate(500).useAdaGrad(false).numDimension(2).build();
    ClassPathResource resource = new ClassPathResource("/mnist2500_X.txt");
    File f = resource.getFile();
    INDArray data = Nd4j.readNumpy(f.getAbsolutePath(), "   ").get(NDArrayIndex.interval(0, 100), NDArrayIndex.interval(0, 784));
    ClassPathResource labels = new ClassPathResource("mnist2500_labels.txt");
    List<String> labelsList = IOUtils.readLines(labels.getInputStream()).subList(0, 100);
    b.fit(data);
    b.saveAsFile(labelsList, "coords.csv");
    throw new RuntimeException("Not implemented");
}
Also used : BarnesHutTsne(org.deeplearning4j.plot.BarnesHutTsne) INDArray(org.nd4j.linalg.api.ndarray.INDArray) File(java.io.File) ClassPathResource(org.datavec.api.util.ClassPathResource) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with BarnesHutTsne

use of org.deeplearning4j.plot.BarnesHutTsne in project deeplearning4j by deeplearning4j.

the class UITest method testPosting.

@Test
public void testPosting() throws Exception {
    //        File inputFile = new ClassPathResource("/big/raw_sentences.txt").getFile();
    File inputFile = new ClassPathResource("/basic/word2vec_advance.txt").getFile();
    SentenceIterator iter = UimaSentenceIterator.createWithPath(inputFile.getAbsolutePath());
    // Split on white spaces in the line to get words
    TokenizerFactory t = new DefaultTokenizerFactory();
    t.setTokenPreProcessor(new CommonPreprocessor());
    Word2Vec vec = new Word2Vec.Builder().minWordFrequency(1).iterations(1).epochs(1).layerSize(20).stopWords(new ArrayList<String>()).useAdaGrad(false).negativeSample(5).seed(42).windowSize(5).iterate(iter).tokenizerFactory(t).build();
    vec.fit();
    File tempFile = File.createTempFile("temp", "w2v");
    tempFile.deleteOnExit();
    WordVectorSerializer.writeWordVectors(vec, tempFile);
    WordVectors vectors = WordVectorSerializer.loadTxtVectors(tempFile);
    //Initialize
    UIServer.getInstance();
    UiConnectionInfo uiConnectionInfo = new UiConnectionInfo.Builder().setAddress("localhost").setPort(9000).build();
    BarnesHutTsne tsne = new BarnesHutTsne.Builder().normalize(false).setFinalMomentum(0.8f).numDimension(2).setMaxIter(10).build();
    vectors.lookupTable().plotVocab(tsne, vectors.lookupTable().getVocabCache().numWords(), uiConnectionInfo);
    Thread.sleep(100000);
}
Also used : BarnesHutTsne(org.deeplearning4j.plot.BarnesHutTsne) TokenizerFactory(org.deeplearning4j.text.tokenization.tokenizerfactory.TokenizerFactory) DefaultTokenizerFactory(org.deeplearning4j.text.tokenization.tokenizerfactory.DefaultTokenizerFactory) UiConnectionInfo(org.deeplearning4j.ui.UiConnectionInfo) ArrayList(java.util.ArrayList) ClassPathResource(org.deeplearning4j.ui.standalone.ClassPathResource) UimaSentenceIterator(org.deeplearning4j.text.sentenceiterator.UimaSentenceIterator) SentenceIterator(org.deeplearning4j.text.sentenceiterator.SentenceIterator) DefaultTokenizerFactory(org.deeplearning4j.text.tokenization.tokenizerfactory.DefaultTokenizerFactory) CommonPreprocessor(org.deeplearning4j.text.tokenization.tokenizer.preprocessor.CommonPreprocessor) Word2Vec(org.deeplearning4j.models.word2vec.Word2Vec) WordVectors(org.deeplearning4j.models.embeddings.wordvectors.WordVectors) File(java.io.File) Test(org.junit.Test)

Example 3 with BarnesHutTsne

use of org.deeplearning4j.plot.BarnesHutTsne in project deeplearning4j by deeplearning4j.

the class InMemoryLookupTable method plotVocab.

/**
     * Render the words via tsne
     */
@Override
public void plotVocab(int numWords, File file) {
    BarnesHutTsne tsne = new BarnesHutTsne.Builder().normalize(false).setFinalMomentum(0.8f).numDimension(2).setMaxIter(1000).build();
    plotVocab(tsne, numWords, file);
}
Also used : BarnesHutTsne(org.deeplearning4j.plot.BarnesHutTsne)

Example 4 with BarnesHutTsne

use of org.deeplearning4j.plot.BarnesHutTsne in project deeplearning4j by deeplearning4j.

the class InMemoryLookupTable method plotVocab.

/**
     * Render the words via tsne
     */
@Override
public void plotVocab(int numWords, UiConnectionInfo connectionInfo) {
    BarnesHutTsne tsne = new BarnesHutTsne.Builder().normalize(false).setFinalMomentum(0.8f).numDimension(2).setMaxIter(1000).build();
    plotVocab(tsne, numWords, connectionInfo);
}
Also used : BarnesHutTsne(org.deeplearning4j.plot.BarnesHutTsne)

Aggregations

BarnesHutTsne (org.deeplearning4j.plot.BarnesHutTsne)4 File (java.io.File)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 ClassPathResource (org.datavec.api.util.ClassPathResource)1 WordVectors (org.deeplearning4j.models.embeddings.wordvectors.WordVectors)1 Word2Vec (org.deeplearning4j.models.word2vec.Word2Vec)1 SentenceIterator (org.deeplearning4j.text.sentenceiterator.SentenceIterator)1 UimaSentenceIterator (org.deeplearning4j.text.sentenceiterator.UimaSentenceIterator)1 CommonPreprocessor (org.deeplearning4j.text.tokenization.tokenizer.preprocessor.CommonPreprocessor)1 DefaultTokenizerFactory (org.deeplearning4j.text.tokenization.tokenizerfactory.DefaultTokenizerFactory)1 TokenizerFactory (org.deeplearning4j.text.tokenization.tokenizerfactory.TokenizerFactory)1 UiConnectionInfo (org.deeplearning4j.ui.UiConnectionInfo)1 ClassPathResource (org.deeplearning4j.ui.standalone.ClassPathResource)1 Ignore (org.junit.Ignore)1 INDArray (org.nd4j.linalg.api.ndarray.INDArray)1