Ejemplo n.º 1
0
        public static IGram InitBackOffNGram(int n, float weightMultiplier)
        {
            Assert.IsTrue(n >= 1);

            IGram gram;

            if (n == 1)
            {
                gram = new UniGram();
            }
            else
            {
                gram = new BackOffNGram(n, weightMultiplier);
            }

            return(gram);
        }
Ejemplo n.º 2
0
        public CompiledBackOffNGram(BackOffNGram gram)
        {
            weightMultiplier = gram.CompiledMemoryUpdate;
            CompiledGrammars = new ICompiledGram[gram.N];
            Weights          = new float[gram.N];
            n = gram.N;

            float weightSum     = 0f;
            float currentWeight = 1f;

            for (int grammarSize = gram.N - 1; grammarSize >= 0; --grammarSize)
            {
                CompiledGrammars[grammarSize] = gram.Grammars[grammarSize].Compile();

                currentWeight       *= weightMultiplier;
                weightSum           += currentWeight;
                Weights[grammarSize] = currentWeight;
            }

            for (int i = 0; i < Weights.Length; ++i)
            {
                Weights[i] /= weightSum;
            }
        }