use of edu.illinois.cs.cogcomp.verbsense.jlis.SenseStructure in project cogcomp-nlp by CogComp.
the class MulticlassInference method getLossAugmentedBestStructure.
@Override
public Pair<IStructure, Double> getLossAugmentedBestStructure(WeightVector weight, IInstance ins, IStructure goldStructure) throws Exception {
SenseInstance x = (SenseInstance) ins;
SenseStructure yGold = null;
if (goldStructure != null)
yGold = (SenseStructure) goldStructure;
int numLabels = manager.getNumLabels();
assert numLabels > 0;
double max = Double.NEGATIVE_INFINITY;
SenseStructure best = null;
double loss = 0;
for (int label = 0; label < numLabels; label++) {
if (!manager.isValidLabel(x, label))
continue;
SenseStructure y = new SenseStructure(x, label, manager);
double score = weight.dotProduct(y.getFeatureVector());
double l = 0;
if (goldStructure != null) {
if (yGold.getLabel() != label)
l++;
}
if (score + l > max + loss) {
max = score;
loss = l;
best = y;
}
}
if (best == null) {
System.out.println(ins);
System.out.println(manager.getLegalSenses(x.getPredicateLemma()));
}
return new Pair<IStructure, Double>(best, loss);
}
use of edu.illinois.cs.cogcomp.verbsense.jlis.SenseStructure in project cogcomp-nlp by CogComp.
the class FeatureVectorCacheFile method next.
public synchronized Pair<SenseInstance, SenseStructure> next() {
try {
assert reader != null;
if (nextLine == null)
hasNext();
String[] parts = nextLine.split("\t");
String lemma = parts[0].trim();
int label = Integer.parseInt(parts[1]);
String features = parts[2];
SenseInstance x = new SenseInstance(lemma, features);
SenseStructure y = new SenseStructure(x, label, manager);
return new Pair<>(x, y);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of edu.illinois.cs.cogcomp.verbsense.jlis.SenseStructure in project cogcomp-nlp by CogComp.
the class SenseExampleGenerator method getTreebankExamples.
private void getTreebankExamples(TextAnnotation ta, List<SenseInstance> predicates, List<SenseStructure> structures) {
TokenLabelView view = (TokenLabelView) ta.getView(SenseManager.getGoldViewName());
for (Constituent predicate : view.getConstituents()) {
if (!predicate.hasAttribute(PredicateArgumentView.LemmaIdentifier)) {
System.out.println(ta);
System.out.println(view);
System.out.println(predicate + " has no lemma!");
assert false;
}
SenseInstance x = new SenseInstance(predicate, manager);
int sense = manager.getSenseId(predicate.getLabel());
SenseStructure y = new SenseStructure(x, sense, manager);
predicates.add(x);
structures.add(y);
}
}
Aggregations