public class BasicModelUtils<T extends SequenceElement> extends java.lang.Object implements ModelUtils<T>
| Modifier and Type | Class and Description |
|---|---|
static class |
BasicModelUtils.ArrayComparator |
static class |
BasicModelUtils.SimilarityComparator |
static class |
BasicModelUtils.WordSimilarity |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
CORRECT |
static java.lang.String |
EXISTS |
protected WeightLookupTable<T> |
lookupTable |
protected boolean |
normalized |
protected VocabCache<T> |
vocabCache |
static java.lang.String |
WRONG |
| Constructor and Description |
|---|
BasicModelUtils() |
| Modifier and Type | Method and Description |
|---|---|
java.util.Map<java.lang.String,java.lang.Double> |
accuracy(java.util.List<java.lang.String> questions)
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
|
static java.util.List<java.lang.String> |
getLabels(java.util.List<BasicModelUtils.WordSimilarity> results,
int limit) |
void |
init(WeightLookupTable<T> lookupTable)
This method implementations should accept given lookup table, and use them in further calls to interface methods
|
double |
similarity(java.lang.String label1,
java.lang.String label2)
Returns the similarity of 2 words.
|
java.util.List<java.lang.String> |
similarWordsInVocabTo(java.lang.String word,
double accuracy)
Find all words with a similar characters
in the vocab
|
java.util.Collection<java.lang.String> |
wordsNearest(java.util.Collection<java.lang.String> positive,
java.util.Collection<java.lang.String> negative,
int top)
Words nearest based on positive and negative words
|
java.util.Collection<java.lang.String> |
wordsNearest(org.nd4j.linalg.api.ndarray.INDArray words,
int top)
Words nearest based on positive and negative words
* @param top the top n words
|
java.util.Collection<java.lang.String> |
wordsNearest(java.lang.String label,
int n)
This method implementations should return N nearest elements labels to given element's label
|
java.util.Collection<java.lang.String> |
wordsNearestSum(java.util.Collection<java.lang.String> positive,
java.util.Collection<java.lang.String> negative,
int top)
Words nearest based on positive and negative words
|
java.util.Collection<java.lang.String> |
wordsNearestSum(org.nd4j.linalg.api.ndarray.INDArray words,
int top)
Words nearest based on positive and negative words
* @param top the top n words
|
java.util.Collection<java.lang.String> |
wordsNearestSum(java.lang.String word,
int n)
Get the top n words most similar to the given word
|
public static final java.lang.String EXISTS
public static final java.lang.String CORRECT
public static final java.lang.String WRONG
protected volatile VocabCache<T extends SequenceElement> vocabCache
protected volatile WeightLookupTable<T extends SequenceElement> lookupTable
protected volatile boolean normalized
public void init(@NonNull
WeightLookupTable<T> lookupTable)
ModelUtilsinit in interface ModelUtils<T extends SequenceElement>public double similarity(@NonNull
java.lang.String label1,
@NonNull
java.lang.String label2)
similarity in interface ModelUtils<T extends SequenceElement>label1 - the first wordlabel2 - the second wordpublic java.util.Collection<java.lang.String> wordsNearest(java.lang.String label,
int n)
ModelUtilswordsNearest in interface ModelUtils<T extends SequenceElement>label - label to return nearest elements forn - number of nearest words to returnpublic java.util.Map<java.lang.String,java.lang.Double> accuracy(java.util.List<java.lang.String> questions)
accuracy in interface ModelUtils<T extends SequenceElement>questions - the questions to askpublic java.util.List<java.lang.String> similarWordsInVocabTo(java.lang.String word,
double accuracy)
similarWordsInVocabTo in interface ModelUtils<T extends SequenceElement>word - the word to compareaccuracy - the accuracy: 0 to 1public java.util.Collection<java.lang.String> wordsNearest(@NonNull
java.util.Collection<java.lang.String> positive,
@NonNull
java.util.Collection<java.lang.String> negative,
int top)
ModelUtilswordsNearest in interface ModelUtils<T extends SequenceElement>positive - the positive wordsnegative - the negative wordstop - the top n wordspublic java.util.Collection<java.lang.String> wordsNearestSum(java.lang.String word,
int n)
wordsNearestSum in interface ModelUtils<T extends SequenceElement>word - the word to comparen - the n to getpublic java.util.Collection<java.lang.String> wordsNearest(org.nd4j.linalg.api.ndarray.INDArray words,
int top)
wordsNearest in interface ModelUtils<T extends SequenceElement>public java.util.Collection<java.lang.String> wordsNearestSum(org.nd4j.linalg.api.ndarray.INDArray words,
int top)
wordsNearestSum in interface ModelUtils<T extends SequenceElement>public java.util.Collection<java.lang.String> wordsNearestSum(java.util.Collection<java.lang.String> positive,
java.util.Collection<java.lang.String> negative,
int top)
wordsNearestSum in interface ModelUtils<T extends SequenceElement>positive - the positive wordsnegative - the negative wordstop - the top n wordspublic static java.util.List<java.lang.String> getLabels(java.util.List<BasicModelUtils.WordSimilarity> results, int limit)