Class InMemoryLookupTable<T extends SequenceElement>

    • Field Detail

      • syn0

        protected org.nd4j.linalg.api.ndarray.INDArray syn0
      • syn1

        protected org.nd4j.linalg.api.ndarray.INDArray syn1
      • vectorLength

        protected int vectorLength
      • rng

        protected transient org.nd4j.linalg.api.rng.Random rng
      • lr

        protected org.nd4j.shade.guava.util.concurrent.AtomicDouble lr
      • expTable

        protected double[] expTable
      • MAX_EXP

        protected static double MAX_EXP
      • seed

        protected long seed
      • table

        protected org.nd4j.linalg.api.ndarray.INDArray table
      • syn1Neg

        protected org.nd4j.linalg.api.ndarray.INDArray syn1Neg
      • useAdaGrad

        protected boolean useAdaGrad
      • negative

        protected double negative
      • useHS

        protected boolean useHS
      • codes

        protected Map<Integer,​org.nd4j.linalg.api.ndarray.INDArray> codes
      • adaGrad

        protected org.nd4j.linalg.learning.legacy.AdaGrad adaGrad
      • tableId

        protected Long tableId
    • Constructor Detail

      • InMemoryLookupTable

        public InMemoryLookupTable()
      • InMemoryLookupTable

        public InMemoryLookupTable​(VocabCache<T> vocab,
                                   int vectorLength,
                                   boolean useAdaGrad,
                                   double lr,
                                   org.nd4j.linalg.api.rng.Random gen,
                                   double negative,
                                   boolean useHS)
      • InMemoryLookupTable

        public InMemoryLookupTable​(VocabCache<T> vocab,
                                   int vectorLength,
                                   boolean useAdaGrad,
                                   double lr,
                                   org.nd4j.linalg.api.rng.Random gen,
                                   double negative)
    • Method Detail

      • initAdaGrad

        protected void initAdaGrad()
      • getExpTable

        public double[] getExpTable()
      • setExpTable

        public void setExpTable​(double[] expTable)
      • putCode

        public void putCode​(int codeIndex,
                            org.nd4j.linalg.api.ndarray.INDArray code)
        Specified by:
        putCode in interface WeightLookupTable<T extends SequenceElement>
        Parameters:
        codeIndex -
        code -
      • loadCodes

        public org.nd4j.linalg.api.ndarray.INDArray loadCodes​(int[] codes)
        Loads the co-occurrences for the given codes
        Specified by:
        loadCodes in interface WeightLookupTable<T extends SequenceElement>
        Parameters:
        codes - the codes to load
        Returns:
        an ndarray of code.length by layerSize
      • initNegative

        public void initNegative()
      • initExpTable

        protected void initExpTable()
      • iterateSample

        @Deprecated
        public void iterateSample​(T w1,
                                  T w2,
                                  AtomicLong nextRandom,
                                  double alpha)
        Deprecated.
        Iterate on the given 2 vocab words
        Specified by:
        iterateSample in interface WeightLookupTable<T extends SequenceElement>
        Parameters:
        w1 - the first word to iterate on
        w2 - the second word to iterate on
        nextRandom - next random for sampling
        alpha - the alpha to use for learning
      • isUseAdaGrad

        public boolean isUseAdaGrad()
      • setUseAdaGrad

        public void setUseAdaGrad​(boolean useAdaGrad)
      • getNegative

        public double getNegative()
      • setUseHS

        public void setUseHS​(boolean useHS)
      • setNegative

        public void setNegative​(double negative)
      • iterate

        @Deprecated
        public void iterate​(T w1,
                            T w2)
        Deprecated.
        Iterate on the given 2 vocab words
        Specified by:
        iterate in interface WeightLookupTable<T extends SequenceElement>
        Parameters:
        w1 - the first word to iterate on
        w2 - the second word to iterate on
      • makeTable

        protected void makeTable​(int tableSize,
                                 double power)
      • putVector

        public void putVector​(String word,
                              org.nd4j.linalg.api.ndarray.INDArray vector)
        Inserts a word vector
        Specified by:
        putVector in interface WeightLookupTable<T extends SequenceElement>
        Parameters:
        word - the word to insert
        vector - the vector to insert
      • getTable

        public org.nd4j.linalg.api.ndarray.INDArray getTable()
      • setTable

        public void setTable​(org.nd4j.linalg.api.ndarray.INDArray table)
      • getSyn1Neg

        public org.nd4j.linalg.api.ndarray.INDArray getSyn1Neg()
      • setSyn1Neg

        public void setSyn1Neg​(org.nd4j.linalg.api.ndarray.INDArray syn1Neg)
      • getSyn0

        public org.nd4j.linalg.api.ndarray.INDArray getSyn0()
      • setSyn0

        public void setSyn0​(@NonNull
                            @NonNull org.nd4j.linalg.api.ndarray.INDArray syn0)
      • getSyn1

        public org.nd4j.linalg.api.ndarray.INDArray getSyn1()
      • setSyn1

        public void setSyn1​(@NonNull
                            @NonNull org.nd4j.linalg.api.ndarray.INDArray syn1)
      • setVectorLength

        public void setVectorLength​(int vectorLength)
      • getLr

        @Deprecated
        public org.nd4j.shade.guava.util.concurrent.AtomicDouble getLr()
        Deprecated.
        This method is deprecated, since all logic was pulled out from this class and is not used anymore. However this method will be around for a while, due to backward compatibility issues.
        Returns:
        initial learning rate
      • setLr

        public void setLr​(org.nd4j.shade.guava.util.concurrent.AtomicDouble lr)
      • setVocab

        public void setVocab​(VocabCache vocab)
      • getCodes

        public Map<Integer,​org.nd4j.linalg.api.ndarray.INDArray> getCodes()
      • setCodes

        public void setCodes​(Map<Integer,​org.nd4j.linalg.api.ndarray.INDArray> codes)
      • consume

        public void consume​(InMemoryLookupTable<T> srcTable)
        This method consumes weights of a given InMemoryLookupTable PLEASE NOTE: this method explicitly resets current weights
        Parameters:
        srcTable -