home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (ModelUtils.java)

This example Java source code file (ModelUtils.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

collection, list, map, modelutils, sequenceelement, string, util

The ModelUtils.java Java example source code

package org.deeplearning4j.models.embeddings.reader;

import org.deeplearning4j.models.embeddings.WeightLookupTable;
import org.deeplearning4j.models.sequencevectors.sequence.SequenceElement;
import org.deeplearning4j.models.word2vec.wordstore.VocabCache;
import org.nd4j.linalg.api.ndarray.INDArray;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * Instances implementing this interface should be responsible for utility access to SequenceVectors model
 *
 * @author raver119@gmail.com
 */
public interface ModelUtils<T extends SequenceElement> {

    /**
     * This method implementations should accept given lookup table, and use them in further calls to interface methods
     *
     * @param lookupTable
     */
    void init(WeightLookupTable<T> lookupTable);

    /**
     * This method implementations should return distance between two given elements
     *
     * @param label1
     * @param label2
     * @return
     */
    double similarity(String label1, String label2);


    /**
     * Accuracy based on questions which are a space separated list of strings
     * where the first word is the query word, the next 2 words are negative,
     * and the last word is the predicted word to be nearest
     * @param questions the questions to ask
     * @return the accuracy based on these questions
     */
    Map<String,Double> accuracy(List questions);


    /**
     * Find all words with a similar characters
     * in the vocab
     * @param word the word to compare
     * @param accuracy the accuracy: 0 to 1
     * @return the list of words that are similar in the vocab
     */
    List<String> similarWordsInVocabTo(String word,double accuracy);


    /**
     * This method implementations should return N nearest elements labels to given element's label
     *
     * @param label label to return nearest elements for
     * @param n number of nearest words to return
     * @return
     */
    Collection<String> wordsNearest(String label, int n);

    /**
     * Words nearest based on positive and negative words
     *
     * @param positive the positive words
     * @param negative the negative words
     * @param top the top n words
     * @return the words nearest the mean of the words
     */
    Collection<String> wordsNearest(Collection positive, Collection negative, int top);


    /**
     * Words nearest based on positive and negative words
     * * @param top the top n words
     * @return the words nearest the mean of the words
     */
    Collection<String> wordsNearest(INDArray words, int top);


    Collection<String> wordsNearestSum(String word,int n);


    Collection<String> wordsNearestSum(INDArray words,int top);

    Collection<String> wordsNearestSum(Collection positive,Collection negative,int top);
}

Other Java examples (source code examples)

Here is a short list of links related to this Java ModelUtils.java source code file:



my book on functional programming

 

new blog posts

 

Copyright 1998-2019 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.