private static Feature[] toFeatures(double[] scores) { //if (scores.length == 1) { //return new Feature[]{new Feature(CANONICAL_ONESCORE_SCORE_TYPES[0], scores[0])}; //} else if (scores.length == 5) { return new Feature[]{new Feature(CANONICAL_FIVESCORE_SCORE_TYPES[0], scores[0]), new Feature(CANONICAL_FIVESCORE_SCORE_TYPES[1], scores[1]), new Feature(CANONICAL_FIVESCORE_SCORE_TYPES[2], scores[2]), new Feature(CANONICAL_FIVESCORE_SCORE_TYPES[3], scores[3]), new Feature(CANONICAL_FIVESCORE_SCORE_TYPES[4], scores[4]),}; } else { throw new RuntimeException("Bad number of weights in phrase table"); } }
private static Feature[] toFeatures(double[] scores) { if(scores.length == 1) { return new Feature[] { new Feature(CANONICAL_ONESCORE_SCORE_TYPES[0],scores[0]) }; } else if(scores.length == 5) { return new Feature[] { new Feature(CANONICAL_FIVESCORE_SCORE_TYPES[0],scores[0]), new Feature(CANONICAL_FIVESCORE_SCORE_TYPES[1],scores[1]), new Feature(CANONICAL_FIVESCORE_SCORE_TYPES[2],scores[2]), new Feature(CANONICAL_FIVESCORE_SCORE_TYPES[3],scores[3]), new Feature(CANONICAL_FIVESCORE_SCORE_TYPES[4],scores[4]), }; } else { throw new RuntimeException("Bad number of weights in phrase table"); } }
@Override protected Feature[] rescore(Feature[] scores, double factor, String rankerName) { final Feature[] newScores = new Feature[scores.length+1]; System.arraycopy(scores, 0, newScores, 0, scores.length); newScores[scores.length] = new Feature(rankerName,factor); return newScores; }
@Override protected Feature[] rescore(Feature[] scores, double factor, String rankerName) { for (int i = 0; i < scores.length; i++) { // Hack... assume negative scores are log probs, positive probs. if (scores[i].score > 0) { if (factor > 0) { scores[i] = new Feature(scores[i].name, scores[i].score * factor); } else { scores[i] = new Feature(scores[i].name, scores[i].score * Math.exp(factor)); } } else { if (factor > 0) { scores[i] = new Feature(scores[i].name, scores[i].score + Math.log(factor)); } else { scores[i] = new Feature(scores[i].name, scores[i].score + factor); } } } return scores; } }
private Feature[] features2array(Collection<String> featureNames, Collection<Feature> features) { final Feature[] feats = new Feature[featureNames.size()]; int k = 0; for (String featureName : featureNames) { for (Feature feature : features) { if (feature.name.equals(featureName)) { if (feats[k] == null) { feats[k] = feature; } else { feats[k] = new Feature(feats[k].name, feats[k].score + feature.score); } } } if (feats[k] == null) { feats[k] = new Feature(featureName, 0.0); } k++; } return feats; }
@Override public Collection<Feature> getFeatures() { ArrayList<Feature> features = new ArrayList<Feature>(translation.features.size()); for (FeatureValue<String> fv : translation.features) { features.add(new Feature(fv.name,fv.value)); } return features; }
private List<Translation> convertTranslations(Solution[] translations, Label srcLabel, Language trgLang, List<String> featureNames) { final ArrayList<Translation> converted = new ArrayList<Translation>(); for (Solution soln : translations) { Feature[] features = new Feature[FidelDecoder.PT + featureNames.size()]; final double[] solnFeatures = soln.features(); features[FidelDecoder.UNK] = new Feature("UnknownWord", solnFeatures[FidelDecoder.UNK]); features[FidelDecoder.DIST] = new Feature("LinearDistortion", solnFeatures[FidelDecoder.DIST]); features[FidelDecoder.LM] = new Feature("LM", solnFeatures[FidelDecoder.LM]); int i = FidelDecoder.PT; for (String featName : featureNames) { features[i] = new Feature(featName.startsWith("TM:") ? featName : ("TM:" + featName), solnFeatures[i]); i++; } if (soln != null) { converted.add(new TranslationImpl(soln, srcLabel, trgLang, invWordMap, srcInvMap, features)); } } return converted; }
throw new IllegalArgumentException("Feature " + featureName + " does not have a default weight!"); featureArray[k++] = new Feature(featureName, weights.get(featureName));