/// <summary>calculateProbs puts log probs of taggings in the probabilities array.</summary> /// <param name="probabilities">Array with indices sent size, k best size, numTags</param> protected internal virtual void CalculateProbs(double[][][] probabilities) { ArrayUtils.Fill(probabilities, double.NegativeInfinity); for (int hyp = 0; hyp < kBestSize; hyp++) { // put the whole thing in pairs, give its beginning and end pairs.SetSize(size); for (int i = 0; i < size; i++) { pairs.SetWord(i, sent[i]); pairs.SetTag(i, finalTags[i]); } //pairs.add(new WordTag(sent.get(i),finalTags[i])); // TODO: if kBestSize > 1, use KBestSequenceFinder and save // k-best hypotheses into finalTags: //pairs.setTag(i,finalTags[i]); int start = endSizePairs; int end = endSizePairs + size - 1; endSizePairs = endSizePairs + size; // iterate over the sentence for (int current = 0; current < size; current++) { History h = new History(start, end, current + start, pairs, maxentTagger.extractors); string[] tags = StringTagsAt(h.current - h.start + LeftWindow()); double[] probs = GetHistories(tags, h); ArrayMath.LogNormalize(probs); // log.info("word: " + pairs.getWord(current)); // log.info("tags: " + Arrays.asList(tags)); // log.info("probs: " + ArrayMath.toString(probs)); for (int j = 0; j < tags.Length; j++) { // score the j-th tag string tag = tags[j]; bool approximate = maxentTagger.HasApproximateScoring(); int tagindex = approximate ? maxentTagger.tags.GetIndex(tag) : j; // log.info("Mapped from j="+ j + " " + tag + " to " + tagindex); probabilities[current][hyp][tagindex] = probs[j]; } } } // for current // for hyp // clean up the stuff in PairsHolder (added by cdm in Aug 2008) Revert(0); }
protected internal virtual void SetTag(int pos, string tag) { pairs.SetTag(pos + start, tag); }