use of edu.illinois.cs.cogcomp.verbsense.utilities.VerbSenseConfigurator in project cogcomp-nlp by CogComp.
the class VerbSenseClassifierMain method preExtract.
@CommandDescription(description = "Pre-extracts the features for the verb-sense model. Run this before training.", usage = "preExtract")
public static void preExtract() throws Exception {
SenseManager manager = getManager(true);
ResourceManager conf = new VerbSenseConfigurator().getDefaultConfig();
// If models directory doesn't exist create it
if (!IOUtils.isDirectory(conf.getString(conf.getString(VerbSenseConfigurator.MODELS_DIRECTORY))))
IOUtils.mkdir(conf.getString(conf.getString(VerbSenseConfigurator.MODELS_DIRECTORY)));
int numConsumers = Runtime.getRuntime().availableProcessors();
Dataset dataset = Dataset.PTBTrainDev;
log.info("Pre-extracting features");
ModelInfo modelInfo = manager.getModelInfo();
String featureSet = "" + modelInfo.featureManifest.getIncludedFeatures().hashCode();
String allDataCacheFile = VerbSenseConfigurator.getFeatureCacheFile(featureSet, dataset, rm);
FeatureVectorCacheFile featureCache = preExtract(numConsumers, manager, dataset, allDataCacheFile);
pruneFeatures(numConsumers, manager, featureCache, VerbSenseConfigurator.getPrunedFeatureCacheFile(featureSet, rm));
Lexicon lexicon = modelInfo.getLexicon().getPrunedLexicon(manager.getPruneSize());
log.info("Saving lexicon with {} features to {}", lexicon.size(), manager.getLexiconFileName());
log.info(lexicon.size() + " features in the lexicon");
lexicon.save(manager.getLexiconFileName());
}
use of edu.illinois.cs.cogcomp.verbsense.utilities.VerbSenseConfigurator in project cogcomp-nlp by CogComp.
the class VerbSenseClassifierMain method main.
@CommandIgnore
public static void main(String[] arguments) throws Exception {
InteractiveShell<VerbSenseClassifierMain> shell = new InteractiveShell<>(VerbSenseClassifierMain.class);
if (arguments.length == 0) {
System.err.println("Usage: <config-file> command");
System.err.println("Required parameter config-file missing.");
shell.showDocumentation();
} else if (arguments.length == 1) {
System.err.println("Usage: <config-file> command");
shell.showDocumentation();
} else {
long start_time = System.currentTimeMillis();
try {
rm = new VerbSenseConfigurator().getDefaultConfig();
String[] args = new String[arguments.length - 1];
System.arraycopy(arguments, 1, args, 0, args.length);
shell.runCommand(args);
long runTime = (System.currentTimeMillis() - start_time) / 1000;
System.out.println("This experiment took " + runTime + " secs");
} catch (AssertionError e) {
e.printStackTrace();
System.exit(-1);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Aggregations