Exemple #1
0
        public double[,] ToVector(List <HuffmanNode> nodes)
        {
            if (nodes == null)
            {
                throw new ArgumentNullException(nameof(nodes));
            }

            var oneHot = new double[1, Vocab.GetLengthLeafs()];

            foreach (var node in nodes)
            {
                var nodeOneHot = MatrixOps.OneHotVector(node.Index, Vocab.GetLengthLeafs());
                for (var j = 0; j < nodeOneHot.CountOfColumns(); j++)
                {
                    oneHot[0, j] += nodeOneHot[0, j];
                }
            }

            //skip-gram output is actually as many '1's as context words
            if (IsCbow)
            {
                oneHot.ApplyToEach(v => v / nodes.Count);
            }

            return(oneHot);
        }
Exemple #2
0
 public double[,] ToVector(HuffmanNode node)
 {
     if (node == null)
     {
         throw new ArgumentNullException(nameof(node));
     }
     return(MatrixOps.OneHotVector(node.Index, Vocab.GetLengthLeafs()));
 }
Exemple #3
0
        protected internal virtual void InitWiWo(int v = 0)
        {
            v = v > 0 ? v : Vocab.GetLengthLeafs();
            var n = Size;

            //https://github.com/ronxin/wevi/blob/master/js/vector_math.js @ function get_random_init_weight(hidden_size)
            //values are always less than 0.1
            double GetInitWeight(double d) => (d - 0.5D) / n;

            WI = MatrixOps.RandomMatrix(v, n, GetInitWeight);
            System.Threading.Thread.Sleep(50);
            WO = MatrixOps.RandomMatrix(n, v, GetInitWeight);
        }
Exemple #4
0
 internal int GetNumberOfTrainWords()
 {
     //TODO is this supposed to be all of them?
     return(Vocab.GetLengthLeafs());
 }