Class StaticWord2Vec
- java.lang.Object
-
- org.deeplearning4j.models.word2vec.StaticWord2Vec
-
- All Implemented Interfaces:
Serializable,WordVectors,org.deeplearning4j.nn.weights.embeddings.EmbeddingInitializer
public class StaticWord2Vec extends Object implements WordVectors
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStaticWord2Vec.Builder
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 PLEASE NOTE: This method is not available in this implementation.StringgetUNK()double[]getWordVector(String word)Get the word vector for a given matrixorg.nd4j.linalg.api.ndarray.INDArraygetWordVectorMatrix(String word)Get the word vector for a given matrixorg.nd4j.linalg.api.ndarray.INDArraygetWordVectorMatrixNormalized(String word)Returns the word vector divided by the norm2 of the arrayorg.nd4j.linalg.api.ndarray.INDArraygetWordVectors(Collection<String> labels)This method returns 2D array, where each row represents corresponding word/labelorg.nd4j.linalg.api.ndarray.INDArraygetWordVectorsMean(Collection<String> labels)This method returns mean vector, built from words/labels passed inbooleanhasWord(String word)Returns true if the model has this word in the vocabintindexOf(String word)protected voidinit()Init method validates configuration defined usingbooleanjsonSerializable()voidloadWeightsInto(org.nd4j.linalg.api.ndarray.INDArray array)WeightLookupTablelookupTable()Lookup table for the vectors PLEASE NOTE: This method is not available in this implementation.booleanoutOfVocabularySupported()Does implementation vectorize words absent in vocabularyvoidsetModelUtils(ModelUtils utils)Specifies ModelUtils to be used to access model PLEASE NOTE: This method has no effect in this implementation.voidsetUNK(String newUNK)doublesimilarity(String label1, String label2)Returns the similarity of 2 wordsList<String>similarWordsInVocabTo(String word, double accuracy)Find all words with a similar characters in the vocab PLEASE NOTE: This method is not available in this implementation.intvectorSize()VocabCachevocab()Vocab for the vectorslongvocabSize()Collection<String>wordsNearest(String word, int n)Get the top n words most similar to the given word PLEASE NOTE: This method is not available in this implementation.Collection<String>wordsNearest(Collection<String> positive, Collection<String> negative, int top)Words nearest based on positive and negative words PLEASE NOTE: This method is not available in this implementation.Collection<String>wordsNearest(org.nd4j.linalg.api.ndarray.INDArray words, int top)Collection<String>wordsNearestSum(String word, int n)Get the top n words most similar to the given word PLEASE NOTE: This method is not available in this implementation.Collection<String>wordsNearestSum(Collection<String> positive, Collection<String> negative, int top)Words nearest based on positive and negative words PLEASE NOTE: This method is not available in this implementation.Collection<String>wordsNearestSum(org.nd4j.linalg.api.ndarray.INDArray words, int top)
-
-
-
Method Detail
-
getUNK
public String getUNK()
- Specified by:
getUNKin interfaceWordVectors
-
setUNK
public void setUNK(String newUNK)
- Specified by:
setUNKin interfaceWordVectors
-
init
protected void init()
Init method validates configuration defined using
-
hasWord
public boolean hasWord(String word)
Returns true if the model has this word in the vocab- Specified by:
hasWordin interfaceWordVectors- Parameters:
word- the word to test for- Returns:
- true if the model has the word in the vocab
-
wordsNearest
public Collection<String> wordsNearest(org.nd4j.linalg.api.ndarray.INDArray words, int top)
- Specified by:
wordsNearestin interfaceWordVectors
-
wordsNearestSum
public Collection<String> wordsNearestSum(org.nd4j.linalg.api.ndarray.INDArray words, int top)
- Specified by:
wordsNearestSumin interfaceWordVectors
-
wordsNearestSum
public Collection<String> wordsNearestSum(String word, int n)
Get the top n words most similar to the given word PLEASE NOTE: This method is not available in this implementation.- Specified by:
wordsNearestSumin interfaceWordVectors- Parameters:
word- the word to comparen- the n to get- Returns:
- the top n words
-
wordsNearestSum
public Collection<String> wordsNearestSum(Collection<String> positive, Collection<String> negative, int top)
Words nearest based on positive and negative words PLEASE NOTE: This method is not available in this implementation.- Specified by:
wordsNearestSumin interfaceWordVectors- Parameters:
positive- the positive wordsnegative- the negative wordstop- the top n words- Returns:
- the words nearest the mean of the words
-
accuracy
public 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 PLEASE NOTE: This method is not available in this implementation.- Specified by:
accuracyin interfaceWordVectors- Parameters:
questions- the questions to ask- Returns:
- the accuracy based on these questions
-
indexOf
public int indexOf(String word)
- Specified by:
indexOfin interfaceWordVectors
-
similarWordsInVocabTo
public List<String> similarWordsInVocabTo(String word, double accuracy)
Find all words with a similar characters in the vocab PLEASE NOTE: This method is not available in this implementation.- Specified by:
similarWordsInVocabToin interfaceWordVectors- Parameters:
word- the word to compareaccuracy- the accuracy: 0 to 1- Returns:
- the list of words that are similar in the vocab
-
getWordVector
public double[] getWordVector(String word)
Get the word vector for a given matrix- Specified by:
getWordVectorin interfaceWordVectors- Parameters:
word- the word to get the matrix for- Returns:
- the ndarray for this word
-
getWordVectorMatrixNormalized
public org.nd4j.linalg.api.ndarray.INDArray getWordVectorMatrixNormalized(String word)
Returns the word vector divided by the norm2 of the array- Specified by:
getWordVectorMatrixNormalizedin interfaceWordVectors- Parameters:
word- the word to get the matrix for- Returns:
- the looked up matrix
-
getWordVectorMatrix
public org.nd4j.linalg.api.ndarray.INDArray getWordVectorMatrix(String word)
Get the word vector for a given matrix- Specified by:
getWordVectorMatrixin interfaceWordVectors- Parameters:
word- the word to get the matrix for- Returns:
- the ndarray for this word
-
getWordVectors
public org.nd4j.linalg.api.ndarray.INDArray getWordVectors(Collection<String> labels)
This method returns 2D array, where each row represents corresponding word/label- Specified by:
getWordVectorsin interfaceWordVectors- Parameters:
labels-- Returns:
-
getWordVectorsMean
public org.nd4j.linalg.api.ndarray.INDArray getWordVectorsMean(Collection<String> labels)
This method returns mean vector, built from words/labels passed in- Specified by:
getWordVectorsMeanin interfaceWordVectors- Parameters:
labels-- Returns:
-
wordsNearest
public Collection<String> wordsNearest(Collection<String> positive, Collection<String> negative, int top)
Words nearest based on positive and negative words PLEASE NOTE: This method is not available in this implementation.- Specified by:
wordsNearestin interfaceWordVectors- Parameters:
positive- the positive wordsnegative- the negative wordstop- the top n words- Returns:
- the words nearest the mean of the words
-
wordsNearest
public Collection<String> wordsNearest(String word, int n)
Get the top n words most similar to the given word PLEASE NOTE: This method is not available in this implementation.- Specified by:
wordsNearestin interfaceWordVectors- Parameters:
word- the word to comparen- the n to get- Returns:
- the top n words
-
similarity
public double similarity(String label1, String label2)
Returns the similarity of 2 words- Specified by:
similarityin interfaceWordVectors- Parameters:
label1- the first wordlabel2- the second word- Returns:
- a normalized similarity (cosine similarity)
-
vocab
public VocabCache vocab()
Vocab for the vectors- Specified by:
vocabin interfaceWordVectors- Returns:
-
lookupTable
public WeightLookupTable lookupTable()
Lookup table for the vectors PLEASE NOTE: This method is not available in this implementation.- Specified by:
lookupTablein interfaceWordVectors- Returns:
-
setModelUtils
public void setModelUtils(ModelUtils utils)
Specifies ModelUtils to be used to access model PLEASE NOTE: This method has no effect in this implementation.- Specified by:
setModelUtilsin interfaceWordVectors- Parameters:
utils-
-
loadWeightsInto
public void loadWeightsInto(org.nd4j.linalg.api.ndarray.INDArray array)
- Specified by:
loadWeightsIntoin interfaceorg.deeplearning4j.nn.weights.embeddings.EmbeddingInitializer
-
vocabSize
public long vocabSize()
- Specified by:
vocabSizein interfaceorg.deeplearning4j.nn.weights.embeddings.EmbeddingInitializer
-
vectorSize
public int vectorSize()
- Specified by:
vectorSizein interfaceorg.deeplearning4j.nn.weights.embeddings.EmbeddingInitializer
-
jsonSerializable
public boolean jsonSerializable()
- Specified by:
jsonSerializablein interfaceorg.deeplearning4j.nn.weights.embeddings.EmbeddingInitializer
-
outOfVocabularySupported
public boolean outOfVocabularySupported()
Description copied from interface:WordVectorsDoes implementation vectorize words absent in vocabulary- Specified by:
outOfVocabularySupportedin interfaceWordVectors- Returns:
- boolean
-
-