Search in sources :

Example 1 with SenseInstance

use of edu.illinois.cs.cogcomp.verbsense.jlis.SenseInstance in project cogcomp-nlp by CogComp.

the class FeatureVectorCacheFile method getStructuredProblem.

public StructuredProblem getStructuredProblem(int sizeLimit) {
    int count = 0;
    StructuredProblem problem = new StructuredProblem();
    log.info("Creating structured problem");
    while (hasNext()) {
        Pair<SenseInstance, SenseStructure> pair = next();
        problem.input_list.add(pair.getFirst());
        problem.output_list.add(pair.getSecond());
        count++;
        if (sizeLimit >= 0 && count >= sizeLimit)
            break;
        if (count % 10000 == 0) {
            log.info("{} examples loaded", count);
        }
    }
    log.info("{} examples loaded. Finished creating structured problem", count);
    return problem;
}
Also used : SenseStructure(edu.illinois.cs.cogcomp.verbsense.jlis.SenseStructure) StructuredProblem(edu.illinois.cs.cogcomp.sl.core.StructuredProblem) SenseInstance(edu.illinois.cs.cogcomp.verbsense.jlis.SenseInstance)

Example 2 with SenseInstance

use of edu.illinois.cs.cogcomp.verbsense.jlis.SenseInstance in project cogcomp-nlp by CogComp.

the class PruningPreExtractor method consume.

@Override
protected void consume(Pair<SenseInstance, SenseStructure> input) {
    SenseInstance x = input.getFirst();
    SenseStructure y = input.getSecond();
    FeatureVector features = x.getCachedFeatureVector();
    ModelInfo modelInfo = manager.getModelInfo();
    Lexicon lexicon = modelInfo.getLexicon();
    int threshold = manager.getPruneSize();
    Pair<int[], float[]> pair = lexicon.pruneFeaturesByCount(features.getIdx(), features.getValue(), threshold);
    features = new FeatureVector(pair.getFirst(), pair.getSecond());
    synchronized (buffer) {
        buffer.add(new PreExtractRecord(x.getPredicateLemma(), y.getLabel(), features));
    }
    if (buffer.size() > 10000) {
        synchronized (buffer) {
            if (buffer.size() > 10000) {
                for (PreExtractRecord r : buffer) {
                    try {
                        cache.put(r.lemma, r.label, r.features);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
                buffer.clear();
            }
        }
    }
    counter.incrementAndGet();
}
Also used : FeatureVector(edu.illinois.cs.cogcomp.sl.util.FeatureVector) SenseStructure(edu.illinois.cs.cogcomp.verbsense.jlis.SenseStructure) ModelInfo(edu.illinois.cs.cogcomp.verbsense.core.ModelInfo) SenseInstance(edu.illinois.cs.cogcomp.verbsense.jlis.SenseInstance) Lexicon(edu.illinois.cs.cogcomp.core.datastructures.Lexicon)

Example 3 with SenseInstance

use of edu.illinois.cs.cogcomp.verbsense.jlis.SenseInstance in project cogcomp-nlp by CogComp.

the class SenseExampleGenerator method getExamples.

public Pair<SentenceInstance, SentenceStructure> getExamples(TextAnnotation ta) throws Exception {
    List<SenseInstance> predicates = new ArrayList<>();
    List<SenseStructure> structures = new ArrayList<>();
    if (ta.hasView(SenseManager.getGoldViewName()))
        getTreebankExamples(ta, predicates, structures);
    else
        getExamples(ta, predicates);
    SentenceInstance sx = new SentenceInstance(predicates);
    SentenceStructure sy = new SentenceStructure(sx, structures);
    return new Pair<>(sx, sy);
}
Also used : SenseStructure(edu.illinois.cs.cogcomp.verbsense.jlis.SenseStructure) SentenceInstance(edu.illinois.cs.cogcomp.verbsense.jlis.SentenceInstance) SenseInstance(edu.illinois.cs.cogcomp.verbsense.jlis.SenseInstance) SentenceStructure(edu.illinois.cs.cogcomp.verbsense.jlis.SentenceStructure) ArrayList(java.util.ArrayList) Pair(edu.illinois.cs.cogcomp.core.datastructures.Pair)

Example 4 with SenseInstance

use of edu.illinois.cs.cogcomp.verbsense.jlis.SenseInstance in project cogcomp-nlp by CogComp.

the class SenseExampleGenerator method getExamples.

/**
     * Generates SRL examples using the predicate detector to identify predicates
     */
private void getExamples(TextAnnotation ta, List<SenseInstance> predicates) throws Exception {
    PredicateDetector predicateDetector = manager.getPredicateDetector();
    for (Constituent predicate : predicateDetector.getPredicates(ta)) {
        if (!predicate.hasAttribute(PredicateArgumentView.LemmaIdentifier)) {
            System.out.println(ta);
            System.out.println(predicate + " has no lemma!");
            assert false;
        }
        SenseInstance x = new SenseInstance(predicate, manager);
        predicates.add(x);
    }
}
Also used : SenseInstance(edu.illinois.cs.cogcomp.verbsense.jlis.SenseInstance) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Example 5 with SenseInstance

use of edu.illinois.cs.cogcomp.verbsense.jlis.SenseInstance in project cogcomp-nlp by CogComp.

the class ILPInference method addVariables.

@Override
protected void addVariables(ILPSolver xmp, InferenceVariableLexManager variableManager) {
    assert xmp != null;
    for (int predicateId = 0; predicateId < numPredicates; predicateId++) {
        SenseInstance senseX = instance.predicates.get(predicateId);
        String lemma = senseX.getPredicateLemma();
        assert lemma != null;
        log.debug("Adding variables for " + lemma);
        double[] senseScores = manager.getScores(senseX, true);
        Set<Integer> set = new HashSet<>();
        for (int senseId = 0; senseId < senseScores.length; senseId++) {
            if (!manager.isValidSense(lemma, senseId))
                continue;
            String label = manager.getSense(senseId);
            double score = senseScores[senseId];
            String variableIdentifier = getSenseVariableIdentifier(viewName, predicateId, label);
            int var = xmp.addBooleanVariable(score);
            variableManager.addVariable(variableIdentifier, var);
            set.add(var);
            log.debug("Sense variable: " + score + " " + variableIdentifier + " " + var + " " + label);
        }
        log.debug("Adding unique sense label constraint");
        addUniqueLabelConstraint(xmp, set);
    }
    assert variableManager.size() > 0 : "No varaibles added for " + this.ta;
}
Also used : SenseInstance(edu.illinois.cs.cogcomp.verbsense.jlis.SenseInstance) HashSet(java.util.HashSet)

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