Search in sources :

Example 1 with VerbSenseConfigurator

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());
}
Also used : ModelInfo(edu.illinois.cs.cogcomp.verbsense.core.ModelInfo) VerbSenseConfigurator(edu.illinois.cs.cogcomp.verbsense.utilities.VerbSenseConfigurator) Dataset(edu.illinois.cs.cogcomp.verbsense.data.Dataset) Lexicon(edu.illinois.cs.cogcomp.core.datastructures.Lexicon) SenseManager(edu.illinois.cs.cogcomp.verbsense.core.SenseManager) ResourceManager(edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager) FeatureVectorCacheFile(edu.illinois.cs.cogcomp.verbsense.caches.FeatureVectorCacheFile) CommandDescription(edu.illinois.cs.cogcomp.core.utilities.commands.CommandDescription)

Example 2 with VerbSenseConfigurator

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();
        }
    }
}
Also used : VerbSenseConfigurator(edu.illinois.cs.cogcomp.verbsense.utilities.VerbSenseConfigurator) InteractiveShell(edu.illinois.cs.cogcomp.core.utilities.commands.InteractiveShell) CommandIgnore(edu.illinois.cs.cogcomp.core.utilities.commands.CommandIgnore)

Aggregations

VerbSenseConfigurator (edu.illinois.cs.cogcomp.verbsense.utilities.VerbSenseConfigurator)2 Lexicon (edu.illinois.cs.cogcomp.core.datastructures.Lexicon)1 CommandDescription (edu.illinois.cs.cogcomp.core.utilities.commands.CommandDescription)1 CommandIgnore (edu.illinois.cs.cogcomp.core.utilities.commands.CommandIgnore)1 InteractiveShell (edu.illinois.cs.cogcomp.core.utilities.commands.InteractiveShell)1 ResourceManager (edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager)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 Dataset (edu.illinois.cs.cogcomp.verbsense.data.Dataset)1