Search in sources :

Example 1 with StructuredProblem

use of edu.illinois.cs.cogcomp.sl.core.StructuredProblem 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 StructuredProblem

use of edu.illinois.cs.cogcomp.sl.core.StructuredProblem in project cogcomp-nlp by CogComp.

the class VerbSenseClassifierMain method train.

@CommandDescription(description = "Trains the verb-sense model.", usage = "train")
public static void train() throws Exception {
    SenseManager manager = getManager(true);
    int numThreads = Runtime.getRuntime().availableProcessors();
    ModelInfo modelInfo = manager.getModelInfo();
    String featureSet = "" + modelInfo.featureManifest.getIncludedFeatures().hashCode();
    String cacheFile = VerbSenseConfigurator.getPrunedFeatureCacheFile(featureSet, rm);
    AbstractInferenceSolver[] inference = new AbstractInferenceSolver[numThreads];
    // TODO Can I replace this with ILPInference?
    for (int i = 0; i < inference.length; i++) inference[i] = new MulticlassInference(manager);
    double c;
    FeatureVectorCacheFile cache;
    cache = new FeatureVectorCacheFile(cacheFile, manager);
    StructuredProblem cvProblem = cache.getStructuredProblem(20000);
    cache.close();
    LearnerParameters params = JLISLearner.crossvalStructSVMSense(cvProblem, inference, 4);
    c = params.getcStruct();
    log.info("c = {} after cv", c);
    cache = new FeatureVectorCacheFile(cacheFile, manager);
    StructuredProblem problem = cache.getStructuredProblem();
    cache.close();
    WeightVector w = JLISLearner.trainStructSVM(inference, problem, c);
    JLISLearner.saveWeightVector(w, manager.getModelFileName());
}
Also used : ModelInfo(edu.illinois.cs.cogcomp.verbsense.core.ModelInfo) StructuredProblem(edu.illinois.cs.cogcomp.sl.core.StructuredProblem) WeightVector(edu.illinois.cs.cogcomp.sl.util.WeightVector) SenseManager(edu.illinois.cs.cogcomp.verbsense.core.SenseManager) MulticlassInference(edu.illinois.cs.cogcomp.verbsense.inference.MulticlassInference) AbstractInferenceSolver(edu.illinois.cs.cogcomp.sl.inference.AbstractInferenceSolver) FeatureVectorCacheFile(edu.illinois.cs.cogcomp.verbsense.caches.FeatureVectorCacheFile) LearnerParameters(edu.illinois.cs.cogcomp.verbsense.learn.LearnerParameters) CommandDescription(edu.illinois.cs.cogcomp.core.utilities.commands.CommandDescription)

Example 3 with StructuredProblem

use of edu.illinois.cs.cogcomp.sl.core.StructuredProblem in project cogcomp-nlp by CogComp.

the class RealMeasureAverager method getFoldData.

public Pair<StructuredProblem, StructuredProblem> getFoldData(StructuredProblem problem, int foldId) {
    int testStart = splitIds[foldId];
    int testEnd = splitIds[foldId + 1];
    StructuredProblem train = new StructuredProblem();
    StructuredProblem test = new StructuredProblem();
    train.input_list = new ArrayList<IInstance>();
    test.input_list = new ArrayList<IInstance>();
    train.output_list = new ArrayList<IStructure>();
    test.output_list = new ArrayList<IStructure>();
    for (int i = 0; i < problem.input_list.size(); i++) {
        IInstance x = problem.input_list.get(i);
        IStructure y = problem.output_list.get(i);
        if (i < testStart || i >= testEnd) {
            train.input_list.add(x);
            train.output_list.add(y);
        } else {
            test.input_list.add(x);
            test.output_list.add(y);
        }
    }
    return new Pair<StructuredProblem, StructuredProblem>(train, test);
}
Also used : StructuredProblem(edu.illinois.cs.cogcomp.sl.core.StructuredProblem) IInstance(edu.illinois.cs.cogcomp.sl.core.IInstance) IStructure(edu.illinois.cs.cogcomp.sl.core.IStructure) Pair(edu.illinois.cs.cogcomp.core.datastructures.Pair)

Aggregations

StructuredProblem (edu.illinois.cs.cogcomp.sl.core.StructuredProblem)3 Pair (edu.illinois.cs.cogcomp.core.datastructures.Pair)1 CommandDescription (edu.illinois.cs.cogcomp.core.utilities.commands.CommandDescription)1 IInstance (edu.illinois.cs.cogcomp.sl.core.IInstance)1 IStructure (edu.illinois.cs.cogcomp.sl.core.IStructure)1 AbstractInferenceSolver (edu.illinois.cs.cogcomp.sl.inference.AbstractInferenceSolver)1 WeightVector (edu.illinois.cs.cogcomp.sl.util.WeightVector)1 FeatureVectorCacheFile (edu.illinois.cs.cogcomp.verbsense.caches.FeatureVectorCacheFile)1 ModelInfo (edu.illinois.cs.cogcomp.verbsense.core.ModelInfo)1 SenseManager (edu.illinois.cs.cogcomp.verbsense.core.SenseManager)1 MulticlassInference (edu.illinois.cs.cogcomp.verbsense.inference.MulticlassInference)1 SenseInstance (edu.illinois.cs.cogcomp.verbsense.jlis.SenseInstance)1 SenseStructure (edu.illinois.cs.cogcomp.verbsense.jlis.SenseStructure)1 LearnerParameters (edu.illinois.cs.cogcomp.verbsense.learn.LearnerParameters)1