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>>batchesprotected VectorsConfigurationconfigurationprotected org.nd4j.linalg.util.DeviceLocalNDArrayexpTableprotected WeightLookupTable<T>lookupTableprotected doublenegativeprotected doublesamplingprotected org.nd4j.linalg.util.DeviceLocalNDArraysyn0protected org.nd4j.linalg.util.DeviceLocalNDArraysyn1protected org.nd4j.linalg.util.DeviceLocalNDArraysyn1Negprotected org.nd4j.linalg.util.DeviceLocalNDArraytableprotected booleanuseAdaGradprotected int[]variableWindowsprotected intvectorLengthprotected VocabCache<T>vocabCacheprotected intwindowprotected intworkers
-
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)voidconfigure(@NonNull VocabCache<T> vocabCache, @NonNull WeightLookupTable<T> lookupTable, @NonNull VectorsConfiguration configuration)SkipGram initialization over given vocabulary and WeightLookupTablevoidfinish()List<org.nd4j.linalg.api.ops.aggregates.Aggregate>getBatch()StringgetCodeName()Returns implementation code nameintgetWorkers()booleanisEarlyTerminationHit()SkipGram has no reasons for early termination ever.doubleiterateSample(List<BatchItem<T>> items)doubleiterateSample(T w1, T lastWord, AtomicLong nextRandom, double alpha, boolean isInference, org.nd4j.linalg.api.ndarray.INDArray inferenceVector)doublelearnSequence(@NonNull Sequence<T> sequence, @NonNull AtomicLong nextRandom, double learningRate)Learns sequence using SkipGram algorithmdoublelearnSequence(@NonNull Sequence<T> sequence, @NonNull AtomicLong nextRandom, double learningRate, BatchSequences<T> batchSequences)voidpretrain(SequenceIterator<T> iterator)SkipGram doesn't involves any pretrainingvoidsetWorkers(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:
getCodeNamein 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:
configurein interfaceElementsLearningAlgorithm<T extends SequenceElement>- Parameters:
vocabCache-lookupTable-configuration-
-
pretrain
public void pretrain(SequenceIterator<T> iterator)
SkipGram doesn't involves any pretraining- Specified by:
pretrainin 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:
learnSequencein 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:
learnSequencein interfaceElementsLearningAlgorithm<T extends SequenceElement>- Parameters:
sequence-nextRandom-learningRate-- Returns:
- average score for this sequence
-
finish
public void finish()
- Specified by:
finishin interfaceElementsLearningAlgorithm<T extends SequenceElement>
-
isEarlyTerminationHit
public boolean isEarlyTerminationHit()
SkipGram has no reasons for early termination ever.- Specified by:
isEarlyTerminationHitin 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)
-
-