Package opennlp.ccg.parse.tagger

Examples of opennlp.ccg.parse.tagger.ProbIndexPair


        // is the key which allows us to retrieve the outcome from the model).
        double[] ocs = mo.eval(context);
        // Sort in descending order of probability.
        ProbIndexPair[] sortedOutcomes = new ProbIndexPair[ocs.length];
        for (int i = 0; i < ocs.length; i++) {
            sortedOutcomes[i] = new ProbIndexPair(new Double(ocs[i]), new Integer(i));
        }
        Arrays.sort(sortedOutcomes);
        String tempOutcome = "";
        String word = thisWord.getForm();
        String pos = thisWord.getPOS();
        ArrayList<Pair<Double, String>> retVal = new ArrayList<Pair<Double, String>>(30);

        // Find the best outcomes seen with the word in training that
        // meet the `beta' constraint.
        // *******************************************************************************************
        double bestOutcomeProb, currentOutcomeProb;
        bestOutcomeProb = 0;
        // mww: changed to not always include front of list, as it may not meet dict constraints
        ProbIndexPair temp;
        // Now loop to see how many make the cut.
        // (But make sure to be sensitive to the dictionary, if necessary.)
        // See whether the word has a freq of this.K in the training corpus.
        Collection<String> wordPermittedOutcomes = (wd != null) ? this.wd.getEntry(word, this.K) : null;
        if (wordPermittedOutcomes != null && useWordDict) {
View Full Code Here


                        bestHist = getBestHist(u - 1, z, order - 1);
                        bestHist.add(currTag);
                        seqScore = lmScore(bestHist);
                        double fs = fbScores.getCoord(u - 1, z) + seqScore;
                        fs += obsScore;                        
                        bestPrevScores[z] = new ProbIndexPair(
                                Double.valueOf(fs),
                                Integer.valueOf(z));

                    }

                    // sort descending based on score.
                    Arrays.sort(bestPrevScores);

                    // add up the prob's of all sequences leading to this node.
                    double fsum = 0.0;
                    for (int q = 0; q < bestPrevScores.length; q++) {
                        fsum += Math.exp(bestPrevScores[q].a);
                    }
                    normTot += fsum;
                    //fbScores.setCoord(u, v, bestPrevScores[0].a.doubleValue());
                    fbScores.setCoord(u, v, Math.log(fsum));

                    // add n-best backpointers.
                    List<Integer> bks = new ArrayList<Integer>(bestPrevScores.length);
                    for (int q = 0; q < bestPrevScores.length; q++) {
                        bks.add(bestPrevScores[q].b);
                    }
                    backPointers.setCoord(u, v, new Backpointer(bks));
                }
            }

            // normalise.           
            for (int v = 0; v < tw.size(); v++) {
                fbScores.setCoord(u, v, Math.log(Math.exp(fbScores.getCoord(u, v)) / normTot));
            }
        }

        // backward loop.
        int size = observationSequence.size();
        if (alg == Constants.TaggingAlgorithm.FORWARDBACKWARD) {
            // for each word...
            for (int u = size - 1; u >= 0; u--) {
                List<Pair<Double, String>> tw = observationSequence.get(u);
                double normTot = 0.0;
                // for each of its tags...
                for (int v = 0; v < tw.size(); v++) {
                    List<Word> bestHist = null;
                   
                    Double obsScore = initScores.getCoord(u, v);
                   
                    if (u == (size - 1)) { // right-hand end of sequence.

                        bestHist = getBestHist(u, v, order - 1);
                        bestHist.add(words.intern(Word.createWord("</s>", null, null, null, null, null, null)));
                        double bsc = fbScores.getCoord(u, v) + obsScore;
                        normTot += Math.exp(bsc);
                        fbScores.setCoord(u, v, bsc);
                    } else {
                        // use dynamic programming-computed scores to progress backwards.
                        bestHist = getBestHist(u, v, order - 1);
                        List<Pair<Double, String>> followingTaggedWd = observationSequence.get(u + 1);
                        double backwardSum = 0.0;
                        for (int z = 0; z < followingTaggedWd.size(); z++) {
                            Word followingTag = words.intern(Word.createWord(followingTaggedWd.get(z).b.intern(), null, null, null, null, null, null));
                            if (z > 0) {
                                bestHist.remove(bestHist.size() - 1);
                            }
                            bestHist.add(followingTag);
                            backwardSum += Math.exp(lmScore(bestHist) + fbScores.getCoord(u + 1, z));
                        }
                        double newSc = Math.log(backwardSum) + obsScore;
                        normTot += Math.exp(newSc);
                        fbScores.setCoord(u, v, newSc);
                    }
                }
                // normalise.
                for (int v = 0; v < tw.size(); v++) {
                    fbScores.setCoord(u, v, Math.log(Math.exp(fbScores.getCoord(u, v)) / normTot));
                }
            }
        }

        // re-sort based on re-estimated scores.       
        for (int i = 0; i < observationSequence.size(); i++) {
            ProbIndexPair[] fwdScrs = new ProbIndexPair[observationSequence.get(i).size()];
            List<Pair<Double, String>> tagging = observationSequence.get(i);

            for (int j = 0; j < tagging.size(); j++) {
                double probP = Math.exp(fbScores.getCoord(i, j).doubleValue());
                fwdScrs[j] = new ProbIndexPair(probP, new Integer(j));
            }
            Arrays.sort(fwdScrs);

            List<Pair<Double, String>> newTagging = new ArrayList<Pair<Double, String>>(fwdScrs.length);
            for (int z = 0; z < fwdScrs.length; z++) {
View Full Code Here

            // add the probability of this tag under the prior model to the distro array.
            double sc = score(attrVals);
            stagDistro[cnt] = sc;
            // add this probability with a pointer back to where it came from in the vocab.
            // (so that we can sort by probability, but then retrieve the supertag string).
            stagPointers[cnt] = new ProbIndexPair(sc, cnt);
            cnt++;

        }
        // sort descending by probability (achieved by the comparator implementation of ProbIndexPair).
View Full Code Here

TOP

Related Classes of opennlp.ccg.parse.tagger.ProbIndexPair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.