Search in sources :

Example 6 with SenseInstance

use of edu.illinois.cs.cogcomp.verbsense.jlis.SenseInstance 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);
}
Also used : SenseStructure(edu.illinois.cs.cogcomp.verbsense.jlis.SenseStructure) SenseInstance(edu.illinois.cs.cogcomp.verbsense.jlis.SenseInstance) Pair(edu.illinois.cs.cogcomp.core.datastructures.Pair)

Example 7 with SenseInstance

use of edu.illinois.cs.cogcomp.verbsense.jlis.SenseInstance 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);
    }
}
Also used : SenseStructure(edu.illinois.cs.cogcomp.verbsense.jlis.SenseStructure) SenseInstance(edu.illinois.cs.cogcomp.verbsense.jlis.SenseInstance) Pair(edu.illinois.cs.cogcomp.core.datastructures.Pair)

Example 8 with SenseInstance

use of edu.illinois.cs.cogcomp.verbsense.jlis.SenseInstance 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);
    }
}
Also used : SenseStructure(edu.illinois.cs.cogcomp.verbsense.jlis.SenseStructure) SenseInstance(edu.illinois.cs.cogcomp.verbsense.jlis.SenseInstance) TokenLabelView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TokenLabelView) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Aggregations

SenseInstance (edu.illinois.cs.cogcomp.verbsense.jlis.SenseInstance)8 SenseStructure (edu.illinois.cs.cogcomp.verbsense.jlis.SenseStructure)6 Pair (edu.illinois.cs.cogcomp.core.datastructures.Pair)3 Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)2 Lexicon (edu.illinois.cs.cogcomp.core.datastructures.Lexicon)1 TokenLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TokenLabelView)1 StructuredProblem (edu.illinois.cs.cogcomp.sl.core.StructuredProblem)1 FeatureVector (edu.illinois.cs.cogcomp.sl.util.FeatureVector)1 ModelInfo (edu.illinois.cs.cogcomp.verbsense.core.ModelInfo)1 SentenceInstance (edu.illinois.cs.cogcomp.verbsense.jlis.SentenceInstance)1 SentenceStructure (edu.illinois.cs.cogcomp.verbsense.jlis.SentenceStructure)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1