use of edu.illinois.cs.cogcomp.sl.inference.AbstractInferenceSolver 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());
}
use of edu.illinois.cs.cogcomp.sl.inference.AbstractInferenceSolver in project cogcomp-nlp by CogComp.
the class CrossValidationHelper method splitInference.
private static AbstractInferenceSolver[][] splitInference(AbstractInferenceSolver[] inference, int nFolds) {
@SuppressWarnings("unchecked") List<AbstractInferenceSolver>[] list = new List[nFolds];
for (int i = 0; i < nFolds; i++) {
list[i] = new ArrayList<>();
}
int foldId = 0;
for (AbstractInferenceSolver anInference : inference) {
list[foldId].add(anInference);
foldId++;
if (foldId == nFolds)
foldId = 0;
}
AbstractInferenceSolver[][] foldInference = new AbstractInferenceSolver[nFolds][];
for (int i = 0; i < nFolds; i++) {
List<AbstractInferenceSolver> l = list[i];
foldInference[i] = l.toArray(new AbstractInferenceSolver[l.size()]);
assert foldInference[i] != null;
}
return foldInference;
}
Aggregations