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;
}
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;
}
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();
}
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();
}
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);
}
Aggregations