Search in sources :

Example 1 with SenseStructure

use of edu.illinois.cs.cogcomp.verbsense.jlis.SenseStructure 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 SenseStructure

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

the class SenseManager method getScores.

/**
     * Scores instance for the different labels allowed for it
     */
public double[] getScores(SenseInstance x, boolean rescoreInvalidLabels) {
    int numLabels = this.getNumLabels();
    double[] scores = new double[numLabels];
    WeightVector w;
    try {
        w = this.getModelInfo().getWeights();
        assert w != null;
    } catch (Exception e) {
        log.error("Unable to load weight vector, exception:\n{}", e);
        throw new RuntimeException(e);
    }
    for (int label = 0; label < numLabels; label++) {
        if (!this.isValidLabel(x, label) && rescoreInvalidLabels) {
            scores[label] = -50;
        } else {
            SenseStructure y = new SenseStructure(x, label, this);
            scores[label] = w.dotProduct(y.getFeatureVector());
        }
    }
    scores = MathUtilities.softmax(scores);
    return scores;
}
Also used : SenseStructure(edu.illinois.cs.cogcomp.verbsense.jlis.SenseStructure) WeightVector(edu.illinois.cs.cogcomp.sl.util.WeightVector) DatastoreException(org.cogcomp.DatastoreException) InvalidEndpointException(io.minio.errors.InvalidEndpointException) FileNotFoundException(java.io.FileNotFoundException) InvalidPortException(io.minio.errors.InvalidPortException)

Example 3 with SenseStructure

use of edu.illinois.cs.cogcomp.verbsense.jlis.SenseStructure 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 4 with SenseStructure

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

the class JLISLearner method evaluateSenseStructure.

public static double evaluateSenseStructure(AbstractInferenceSolver inference, StructuredProblem testSet, WeightVector weights) throws Exception {
    EvaluationRecord evalRecord = new EvaluationRecord();
    for (int i = 0; i < testSet.input_list.size(); i++) {
        IInstance x = testSet.input_list.get(i);
        SenseStructure gold = (SenseStructure) testSet.output_list.get(i);
        SenseStructure bestStructure = (SenseStructure) inference.getBestStructure(weights, x);
        if (gold.getLabel() == bestStructure.getLabel())
            evalRecord.incrementCorrect();
        evalRecord.incrementGold();
        evalRecord.incrementPredicted();
    }
    log.info("Predicted = " + evalRecord.getPredictedCount() + ", Gold = " + evalRecord.getGoldCount() + " Correct = " + evalRecord.getCorrectCount());
    return evalRecord.getF1();
}
Also used : SenseStructure(edu.illinois.cs.cogcomp.verbsense.jlis.SenseStructure) IInstance(edu.illinois.cs.cogcomp.sl.core.IInstance) EvaluationRecord(edu.illinois.cs.cogcomp.core.experiments.EvaluationRecord)

Example 5 with SenseStructure

use of edu.illinois.cs.cogcomp.verbsense.jlis.SenseStructure 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)

Aggregations

SenseStructure (edu.illinois.cs.cogcomp.verbsense.jlis.SenseStructure)8 SenseInstance (edu.illinois.cs.cogcomp.verbsense.jlis.SenseInstance)6 Pair (edu.illinois.cs.cogcomp.core.datastructures.Pair)3 Lexicon (edu.illinois.cs.cogcomp.core.datastructures.Lexicon)1 Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)1 TokenLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TokenLabelView)1 EvaluationRecord (edu.illinois.cs.cogcomp.core.experiments.EvaluationRecord)1 IInstance (edu.illinois.cs.cogcomp.sl.core.IInstance)1 StructuredProblem (edu.illinois.cs.cogcomp.sl.core.StructuredProblem)1 FeatureVector (edu.illinois.cs.cogcomp.sl.util.FeatureVector)1 WeightVector (edu.illinois.cs.cogcomp.sl.util.WeightVector)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 InvalidEndpointException (io.minio.errors.InvalidEndpointException)1 InvalidPortException (io.minio.errors.InvalidPortException)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 DatastoreException (org.cogcomp.DatastoreException)1