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