Commits

Elias Ponvert committed 92a38a3

adding entropy to stats output - fix

  • Participants
  • Parent commits 74001a5
  • Branches dissertation-work

Comments (0)

Files changed (3)

java/upparse/model/CombinedProb.java

           final String label = "P(" + tag + " => " + word + " " + nextTag + ")";
           final double val = prob[t][nextT][w] * backoffHmm.nonLogTrans(t, nextT);
           final double logProb = Math.log(val);
-          sumForEntropy += val * logProb;
+          if (val != 0 && !Double.isNaN(val))
+            sumForEntropy += val * logProb;
           final RankedRecord<String> rec = new RankedRecord<String>(label, val);
           probRec.add(rec);
         }

java/upparse/model/EmissionProbs.java

         final String label = "P(" + word + "|" + tag + ")";
         final double val = emiss[t][w];
         final double probVal = Math.exp(val);
-        sumForEntropy += val * probVal;
+        if (!Double.isNaN(val))
+          sumForEntropy += val * probVal;
         final RankedRecord<String> rec = new RankedRecord<String>(label, probVal);
         emissRec.add(rec);
       }

java/upparse/model/HMM.java

         final String label = "P(" + t2Tag + "|" + t1Tag + ")";
         final double val = trans[t1][t2];
         final double probVal = Math.exp(val);
-        sumForEntropy += val * probVal;
+        if (!Double.isNaN(val))
+          sumForEntropy += val * probVal;
         final double scaleVal = 100.0 * probVal;
         final String templ = "%s = %.1f\n";
         out.format(templ, label, scaleVal);