Package edu.umd.hooka

Examples of edu.umd.hooka.AlignmentPosteriorGrid


   
    PerplexityReporter cr = new PerplexityReporter();
    Alignment a = hmm.viterbiAlign(pp, cr);
    assertEquals(a.getELength(), e.size());
    assertEquals(a.getFLength(), f.size());
    AlignmentPosteriorGrid pg = hmm.computeAlignmentPosteriors(pp);
    System.out.println(a.toStringVisual() + "\nPG:\n"+pg + "\n"+cr + "\n");
    System.out.println(hmm.emission);
    System.out.println(hmm.transition);
    System.out.println("Done NULL");
  }
View Full Code Here


      reporter.progress();
    }
  }
 
  public AlignmentPosteriorGrid computeAlignmentPosteriors(PhrasePair pp) {
    AlignmentPosteriorGrid res = new AlignmentPosteriorGrid(pp);
    int fw[] = pp.getF().getWords();
    int ew[] = pp.getE().getWords();
    if (totals == null) {
      totals = new float[maxF];
    } else {
      Arrays.fill(totals, 0.0f);
    }
    if (_includeEnglishNullWord) {
      // handle NULL
      for (int fj:fw) {  
        totals[fj] += tmodel.get(0, fj);
      }
    }
    // handle normal e_i's
    for (int ei:ew) {
      for (int fj:fw) {  
        totals[fj] += tmodel.get(ei, fj);
      }
    }
   
    float totalLogProb = 0.0f;
    for (int j=0; j<fw.length; j++) {
      int fj = fw[j];
      float totalProb = totals[fj];
      totalLogProb += Math.log(totalProb);
      int start = 1;
      if (_includeEnglishNullWord)
        start = 0;
      for (int i=start; i<=ew.length; i++) {
        int ei = (i > 0) ? ew[i-1] : 0;
        float post = tmodel.get(ei, fj) / totalProb;
        res.setAlignmentPointPosterior(j, i, post);
      }
    }
    return res;
  }
View Full Code Here

  public Alignment viterbiAlign(PhrasePair sentence, PerplexityReporter viterbiPerp) {
    int[] es = sentence.getE().getWords();
    int[] fs = sentence.getF().getWords();
    float threshold = 0.27f;
    Alignment res = new Alignment(fs.length, es.length);
    AlignmentPosteriorGrid g = computeAlignmentPosteriors(sentence);
    for (int j=0; j<fs.length; j++) {
      for (int i=1; i<es.length; i++) {
        float post = g.getAlignmentPointPosterior(j, i);
        if (post > threshold) { res.align(j, i-1); }
      }
    }
    return res;
  }
View Full Code Here

//    System.out.println(alphas + "\n" + betas);
  }

  @Override
  public AlignmentPosteriorGrid computeAlignmentPosteriors(PhrasePair pp) {
    AlignmentPosteriorGrid res = new AlignmentPosteriorGrid(pp);
    buildHMMTables(pp);
    baumWelch(pp, res);
    return res;
  }
View Full Code Here

        init();
        trainer.addAlignmentListener(new AEListener(reporter));
      }
      if (usePServer && ttable != null)
        ((PServerClient)ttable).query(value, useNullWord);
      AlignmentPosteriorGrid model1g= null;
      if (value.hasAlignmentPosteriors())
        model1g = value.getAlignmentPosteriorGrid();
      if (trainer instanceof HMM) {
        ((HMM)trainer).setModel1Posteriors(model1g);
      }
View Full Code Here

        first = false;
        trainer.addAlignmentListener(new AEListener(reporter));
      }
      PerplexityReporter pr = new PerplexityReporter();

      AlignmentPosteriorGrid model1g= null;
      if (value.hasAlignmentPosteriors())
        model1g = value.getAlignmentPosteriorGrid();
      if (trainer instanceof HMM && model1g != null) {
        ((HMM)trainer).setModel1Posteriors(model1g);
      }

      Alignment a = trainer.viterbiAlign(value, pr);
      ReferenceAlignment ref = (ReferenceAlignment)value.getAlignment();
      AlignmentPosteriorGrid ghmm = null;
      AlignmentPosteriorGrid gmodel1 = null;

      if (generatePosteriors) {
        if (value.hasAlignmentPosteriors())
          model1g = value.getAlignmentPosteriorGrid();
        if (trainer instanceof HMM)
          ((HMM)trainer).setModel1Posteriors(model1g);
        AlignmentPosteriorGrid g = trainer.computeAlignmentPosteriors(value);
        if (value.hasAlignmentPosteriors()) {
          //System.err.println(key + ": already has posteriors!");
          model1g = value.getAlignmentPosteriorGrid();
          //model1g.penalizeGarbageCollectors(2, 0.27f, 0.20f);
          Alignment model1a = model1g.alignPosteriorThreshold(0.5f);
View Full Code Here

TOP

Related Classes of edu.umd.hooka.AlignmentPosteriorGrid

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.