Ejemplo n.º 1
0
        internal void GetBestTagSequence(IList <FeatureVector> words, out double[] prob_c_w, out int[] c_w)
        {
            c_w      = new int[words.Count];
            prob_c_w = new double[words.Count];

            double[][] probs_v_c = new double[words.Count][];
            for (int v_i = 0; v_i < words.Count; v_i++)
            {
                double[] details;
                int      sysClass = classifier.Classify(words[v_i], out details);
                probs_v_c[v_i] = details;

                string prevT_name              = v_i - 1 < 0 ? "BOS" : classToClassId[c_w[v_i - 1]];
                string prevT_featureName       = string.Format("prevT={0}", prevT_name);
                string prevTwoTags_name        = v_i - 2 < 0 ? "BOS" : classToClassId[c_w[v_i - 2]];
                string prevTwoTags_featureName = string.Format("prevTwoTags={0}+{1}", prevTwoTags_name, prevT_name);
                var    prevT_f       = featureToFeatureId[prevT_featureName];
                var    prevTwoTags_f = featureToFeatureId[prevTwoTags_featureName];

                for (int c_i = 0; c_i < classToClassId.Count; c_i++)
                {
                    double logProb = Math.Log(probs_v_c[v_i][c_i], Math.E);
                    logProb            += classifier.CalculateLogProb_c_f(c_i, prevT_f);
                    logProb            += classifier.CalculateLogProb_c_f(c_i, prevTwoTags_f);
                    probs_v_c[v_i][c_i] = Math.Pow(Math.E, logProb);
                }
                NormalizationHelper.Normalize(probs_v_c[v_i]);
                int bestClass = StatisticsHelper.ArgMax(probs_v_c[v_i]);
                c_w[v_i]      = bestClass;
                prob_c_w[v_i] = probs_v_c[v_i][bestClass];
            }
        }