Class SkipGram<T extends SequenceElement>
- java.lang.Object
-
- org.deeplearning4j.models.embeddings.learning.impl.elements.SkipGram<T>
-
- All Implemented Interfaces:
ElementsLearningAlgorithm<T>
public class SkipGram<T extends SequenceElement> extends Object implements ElementsLearningAlgorithm<T>
-
-
Field Summary
Fields Modifier and Type Field Description protected ThreadLocal<List<org.nd4j.linalg.api.ops.aggregates.Aggregate>>
batches
protected VectorsConfiguration
configuration
protected org.nd4j.linalg.util.DeviceLocalNDArray
expTable
protected WeightLookupTable<T>
lookupTable
protected double
negative
protected double
sampling
protected org.nd4j.linalg.util.DeviceLocalNDArray
syn0
protected org.nd4j.linalg.util.DeviceLocalNDArray
syn1
protected org.nd4j.linalg.util.DeviceLocalNDArray
syn1Neg
protected org.nd4j.linalg.util.DeviceLocalNDArray
table
protected boolean
useAdaGrad
protected int[]
variableWindows
protected int
vectorLength
protected VocabCache<T>
vocabCache
protected int
window
protected int
workers
-
Constructor Summary
Constructors Constructor Description SkipGram()
Dummy construction is required for reflection
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Sequence<T>
applySubsampling(@NonNull Sequence<T> sequence, @NonNull AtomicLong nextRandom)
void
configure(@NonNull VocabCache<T> vocabCache, @NonNull WeightLookupTable<T> lookupTable, @NonNull VectorsConfiguration configuration)
SkipGram initialization over given vocabulary and WeightLookupTablevoid
finish()
List<org.nd4j.linalg.api.ops.aggregates.Aggregate>
getBatch()
String
getCodeName()
Returns implementation code nameint
getWorkers()
boolean
isEarlyTerminationHit()
SkipGram has no reasons for early termination ever.double
iterateSample(List<BatchItem<T>> items)
double
iterateSample(T w1, T lastWord, AtomicLong nextRandom, double alpha, boolean isInference, org.nd4j.linalg.api.ndarray.INDArray inferenceVector)
double
learnSequence(@NonNull Sequence<T> sequence, @NonNull AtomicLong nextRandom, double learningRate)
Learns sequence using SkipGram algorithmdouble
learnSequence(@NonNull Sequence<T> sequence, @NonNull AtomicLong nextRandom, double learningRate, BatchSequences<T> batchSequences)
void
pretrain(SequenceIterator<T> iterator)
SkipGram doesn't involves any pretrainingvoid
setWorkers(int workers)
-
-
-
Field Detail
-
vocabCache
protected VocabCache<T extends SequenceElement> vocabCache
-
lookupTable
protected WeightLookupTable<T extends SequenceElement> lookupTable
-
configuration
protected VectorsConfiguration configuration
-
window
protected int window
-
useAdaGrad
protected boolean useAdaGrad
-
negative
protected double negative
-
sampling
protected double sampling
-
variableWindows
protected int[] variableWindows
-
vectorLength
protected int vectorLength
-
workers
protected int workers
-
syn0
protected org.nd4j.linalg.util.DeviceLocalNDArray syn0
-
syn1
protected org.nd4j.linalg.util.DeviceLocalNDArray syn1
-
syn1Neg
protected org.nd4j.linalg.util.DeviceLocalNDArray syn1Neg
-
table
protected org.nd4j.linalg.util.DeviceLocalNDArray table
-
expTable
protected org.nd4j.linalg.util.DeviceLocalNDArray expTable
-
batches
protected ThreadLocal<List<org.nd4j.linalg.api.ops.aggregates.Aggregate>> batches
-
-
Method Detail
-
getWorkers
public int getWorkers()
-
setWorkers
public void setWorkers(int workers)
-
getBatch
public List<org.nd4j.linalg.api.ops.aggregates.Aggregate> getBatch()
-
getCodeName
public String getCodeName()
Returns implementation code name- Specified by:
getCodeName
in interfaceElementsLearningAlgorithm<T extends SequenceElement>
- Returns:
-
configure
public void configure(@NonNull @NonNull VocabCache<T> vocabCache, @NonNull @NonNull WeightLookupTable<T> lookupTable, @NonNull @NonNull VectorsConfiguration configuration)
SkipGram initialization over given vocabulary and WeightLookupTable- Specified by:
configure
in interfaceElementsLearningAlgorithm<T extends SequenceElement>
- Parameters:
vocabCache
-lookupTable
-configuration
-
-
pretrain
public void pretrain(SequenceIterator<T> iterator)
SkipGram doesn't involves any pretraining- Specified by:
pretrain
in interfaceElementsLearningAlgorithm<T extends SequenceElement>
- Parameters:
iterator
-
-
applySubsampling
public Sequence<T> applySubsampling(@NonNull @NonNull Sequence<T> sequence, @NonNull @NonNull AtomicLong nextRandom)
-
learnSequence
public double learnSequence(@NonNull @NonNull Sequence<T> sequence, @NonNull @NonNull AtomicLong nextRandom, double learningRate, BatchSequences<T> batchSequences)
- Specified by:
learnSequence
in interfaceElementsLearningAlgorithm<T extends SequenceElement>
-
learnSequence
public double learnSequence(@NonNull @NonNull Sequence<T> sequence, @NonNull @NonNull AtomicLong nextRandom, double learningRate)
Learns sequence using SkipGram algorithm- Specified by:
learnSequence
in interfaceElementsLearningAlgorithm<T extends SequenceElement>
- Parameters:
sequence
-nextRandom
-learningRate
-- Returns:
- average score for this sequence
-
finish
public void finish()
- Specified by:
finish
in interfaceElementsLearningAlgorithm<T extends SequenceElement>
-
isEarlyTerminationHit
public boolean isEarlyTerminationHit()
SkipGram has no reasons for early termination ever.- Specified by:
isEarlyTerminationHit
in interfaceElementsLearningAlgorithm<T extends SequenceElement>
- Returns:
-
iterateSample
public double iterateSample(T w1, T lastWord, AtomicLong nextRandom, double alpha, boolean isInference, org.nd4j.linalg.api.ndarray.INDArray inferenceVector)
-
-