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