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 class
StaticWord2Vec.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.String
getUNK()
double[]
getWordVector(String word)
Get the word vector for a given matrixorg.nd4j.linalg.api.ndarray.INDArray
getWordVectorMatrix(String word)
Get the word vector for a given matrixorg.nd4j.linalg.api.ndarray.INDArray
getWordVectorMatrixNormalized(String word)
Returns the word vector divided by the norm2 of the arrayorg.nd4j.linalg.api.ndarray.INDArray
getWordVectors(Collection<String> labels)
This method returns 2D array, where each row represents corresponding word/labelorg.nd4j.linalg.api.ndarray.INDArray
getWordVectorsMean(Collection<String> labels)
This method returns mean vector, built from words/labels passed inboolean
hasWord(String word)
Returns true if the model has this word in the vocabint
indexOf(String word)
protected void
init()
Init method validates configuration defined usingboolean
jsonSerializable()
void
loadWeightsInto(org.nd4j.linalg.api.ndarray.INDArray array)
WeightLookupTable
lookupTable()
Lookup table for the vectors PLEASE NOTE: This method is not available in this implementation.boolean
outOfVocabularySupported()
Does implementation vectorize words absent in vocabularyvoid
setModelUtils(ModelUtils utils)
Specifies ModelUtils to be used to access model PLEASE NOTE: This method has no effect in this implementation.void
setUNK(String newUNK)
double
similarity(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.int
vectorSize()
VocabCache
vocab()
Vocab for the vectorslong
vocabSize()
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:
getUNK
in interfaceWordVectors
-
setUNK
public void setUNK(String newUNK)
- Specified by:
setUNK
in 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:
hasWord
in 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:
wordsNearest
in interfaceWordVectors
-
wordsNearestSum
public Collection<String> wordsNearestSum(org.nd4j.linalg.api.ndarray.INDArray words, int top)
- Specified by:
wordsNearestSum
in 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:
wordsNearestSum
in 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:
wordsNearestSum
in 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:
accuracy
in interfaceWordVectors
- Parameters:
questions
- the questions to ask- Returns:
- the accuracy based on these questions
-
indexOf
public int indexOf(String word)
- Specified by:
indexOf
in 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:
similarWordsInVocabTo
in 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:
getWordVector
in 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:
getWordVectorMatrixNormalized
in 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:
getWordVectorMatrix
in 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:
getWordVectors
in 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:
getWordVectorsMean
in 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:
wordsNearest
in 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:
wordsNearest
in 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:
similarity
in 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:
vocab
in interfaceWordVectors
- Returns:
-
lookupTable
public WeightLookupTable lookupTable()
Lookup table for the vectors PLEASE NOTE: This method is not available in this implementation.- Specified by:
lookupTable
in 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:
setModelUtils
in interfaceWordVectors
- Parameters:
utils
-
-
loadWeightsInto
public void loadWeightsInto(org.nd4j.linalg.api.ndarray.INDArray array)
- Specified by:
loadWeightsInto
in interfaceorg.deeplearning4j.nn.weights.embeddings.EmbeddingInitializer
-
vocabSize
public long vocabSize()
- Specified by:
vocabSize
in interfaceorg.deeplearning4j.nn.weights.embeddings.EmbeddingInitializer
-
vectorSize
public int vectorSize()
- Specified by:
vectorSize
in interfaceorg.deeplearning4j.nn.weights.embeddings.EmbeddingInitializer
-
jsonSerializable
public boolean jsonSerializable()
- Specified by:
jsonSerializable
in interfaceorg.deeplearning4j.nn.weights.embeddings.EmbeddingInitializer
-
outOfVocabularySupported
public boolean outOfVocabularySupported()
Description copied from interface:WordVectors
Does implementation vectorize words absent in vocabulary- Specified by:
outOfVocabularySupported
in interfaceWordVectors
- Returns:
- boolean
-
-