Пример #1
0
        private void applyUnigramWeight()
        {
            float num    = this.logMath.linearToLog((double)this.unigramWeight);
            float num2   = this.logMath.linearToLog((double)(1f - this.unigramWeight));
            float num3   = this.logMath.linearToLog((double)(1f / (float)this.numberNGrams[0]));
            float num4   = this.logMath.linearToLog(this.wip);
            float logVal = num3 + num2;

            for (int i = 0; i < this.numberNGrams[0]; i++)
            {
                UnigramProbability unigramProbability = this.unigrams[i];
                float num5 = unigramProbability.getLogProbability();
                if (i != this.startWordID)
                {
                    num5 += num;
                    num5  = this.logMath.addAsLinear(num5, logVal);
                }
                if (this.applyLanguageWeightAndWip)
                {
                    num5 = num5 * this.languageWeight + num4;
                    unigramProbability.setLogBackoff(unigramProbability.getLogBackoff() * this.languageWeight);
                }
                unigramProbability.setLogProbability(num5);
            }
        }
Пример #2
0
        protected internal virtual void loadModelLayout(InputStream inputStream)
        {
            DataInputStream dataInputStream = new DataInputStream(new BufferedInputStream(inputStream));

            this.readHeader(dataInputStream);
            this.unigrams = this.readUnigrams(dataInputStream, this.numberNGrams[0] + 1, this.bigEndian);
            this.skipNGrams(dataInputStream);
            int i;

            for (i = 1; i < this.maxNGram; i++)
            {
                if (this.numberNGrams[i] > 0)
                {
                    if (i == 1)
                    {
                        this.NGramProbTable[i] = this.readFloatTable(dataInputStream, this.bigEndian);
                    }
                    else
                    {
                        this.NGramBackoffTable[i] = this.readFloatTable(dataInputStream, this.bigEndian);
                        this.NGramProbTable[i]    = this.readFloatTable(dataInputStream, this.bigEndian);
                        int j    = 1 << this.logNGramSegmentSize;
                        int num  = this.numberNGrams[i - 1] + 1;
                        int num2 = j;
                        int num3 = ((num2 != -1) ? (num / num2) : (-num)) + 1;
                        this.NGramSegmentTable[i] = this.readIntTable(dataInputStream, this.bigEndian, num3);
                    }
                }
            }
            i = this.readInt(dataInputStream, this.bigEndian);
            if (i <= 0)
            {
                string text = new StringBuilder().append("Bad word string size: ").append(i).toString();

                throw new Error(text);
            }
            this.words = this.readWords(dataInputStream, i, this.numberNGrams[0]);
            if (this.startWordID > -1)
            {
                UnigramProbability unigramProbability = this.unigrams[this.startWordID];
                unigramProbability.setLogProbability(-99f);
            }
            if (this.endWordID > -1)
            {
                UnigramProbability unigramProbability = this.unigrams[this.endWordID];
                unigramProbability.setLogBackoff(-99f);
            }
            this.applyUnigramWeight();
            if (this.applyLanguageWeightAndWip)
            {
                for (int j = 0; j <= this.maxNGram; j++)
                {
                    this.applyLanguageWeight(this.NGramProbTable[j], this.languageWeight);
                    this.applyWip(this.NGramProbTable[j], this.wip);
                    if (j > 1)
                    {
                        this.applyLanguageWeight(this.NGramBackoffTable[j], this.languageWeight);
                    }
                }
            }
            dataInputStream.close();
        }