/** * This method returns the number of features. This implementation assumes the * lexicon is populated, but that's not always the case (with SVM for example appears * to not always have a populated lexicon). In these cases, this method may be overriden. * @return the number of featues. */ protected int getNumberFeatures() { return lexicon.size(); }
/** * Returns the value of {@link #pruneCutoff}, or {@link #size()} if {@link #pruneCutoff} is -1. **/ public int getCutoff() { return pruneCutoff == -1 ? size() : pruneCutoff; }
/** * Compute the single weight at the index as the sum of all weights for all classes. * @param index the index of the feature * @return the sum of the absolute value of all weights for the feature. */ private double getWeight(int index) { double sum = 0; for (int i = 0; i < this.numberclasses; i++) { sum += Math.abs(svm.getWeights()[index]); index += (this.lexicon.size() + biasfeatures); } return sum; }
/** * Forces this learner to read in its lexicon representation, but only if the lexicon currently * available in this object is empty and the learner has been scheduled to read its lexicon on * demand with {@link #readLexiconOnDemand(URL)}. * * @see #readLexiconOnDemand * @return The lexicon just read into {@link #lexicon}. **/ public Lexicon demandLexicon() { if (readLexiconOnDemand && (lexicon == null || lexicon.size() == 0)) { readLexicon(lexFilePath); readLexiconOnDemand = false; } return lexicon; }
/** * Writes the algorithm's internal representation as text. In the first line of output, the name * of the classifier is printed, followed by {@link #learningRate} and {@link #bias}. * * @param out The output stream. **/ public void write(PrintStream out) { out.println(name + ": " + learningRate + ", " + bias); if (lexicon.size() == 0) weightVector.write(out); else weightVector.write(out, lexicon); }
/** * Writes the learned function's binary internal represetation including both its model and * lexicons to the specified files. These files are then cached in {@link #lcFilePath} and * {@link #lexFilePath}. * * @param modelFile The name of the file in which to write the model. * @param lexFile The name of the file in which to write the feature lexicon. **/ public void write(String modelFile, String lexFile) { writeModel(modelFile); if (lexicon != null && lexicon.size() > 0) writeLexicon(lexFile); }
public Set<String> getTagValues() { Lexicon labelLexicon = taggerKnown.getLabelLexicon(); Set<String> tagSet = new HashSet(); for (int i =0; i < labelLexicon.size(); ++i) { tagSet.add(labelLexicon.lookupKey(i).getStringValue()); } return tagSet; }
public Set<String> getTagValues() { Lexicon labelLexicon = taggerKnown.getLabelLexicon(); Set<String> tagSet = new HashSet(); for (int i =0; i < labelLexicon.size(); ++i) { tagSet.add(labelLexicon.lookupKey(i).getStringValue()); } return tagSet; }
/** * Writes the binary representation of this learned function if there is a location cached in * {@link #lcFilePath}, and writes the binary representation of the feature lexicon if there is * a location cached in {@link #lexFilePath}. **/ public void save() { if (lcFilePath != null) saveModel(); if (lexFilePath != null && lexicon != null && lexicon.size() > 0) saveLexicon(); }
/** * Writes the algorithm's internal representation as text. In the first line of output, the name * of the classifier is printed, followed by {@link #learningRate}, * {@link LinearThresholdUnit#initialWeight}, {@link LinearThresholdUnit#threshold}, * {@link LinearThresholdUnit#positiveThickness}, {@link LinearThresholdUnit#negativeThickness}, * and finally {@link LinearThresholdUnit#bias}. * * @param out The output stream. **/ public void write(PrintStream out) { out.println(name + ": " + learningRate + ", " + initialWeight + ", " + threshold + ", " + positiveThickness + ", " + negativeThickness + ", " + bias); if (lexicon.size() == 0) weightVector.write(out); else weightVector.write(out, lexicon); }
/** * Writes the algorithm's internal representation as text. In the first line of output, the name * of the classifier is printed, followed by {@link #learningRate}, * {@link LinearThresholdUnit#initialWeight}, {@link LinearThresholdUnit#threshold}, * {@link LinearThresholdUnit#positiveThickness}, {@link LinearThresholdUnit#negativeThickness}, * and finally {@link LinearThresholdUnit#bias}. * * @param out The output stream. **/ public void write(PrintStream out) { out.println(name + ": " + learningRate + ", " + initialWeight + ", " + threshold + ", " + positiveThickness + ", " + negativeThickness + ", " + bias); if (lexicon.size() == 0) weightVector.write(out); else weightVector.write(out, lexicon); }
/** * Writes the algorithm's internal representation as text. In the first line of output, the name * of the classifier is printed, followed by {@link #learningRate}, {@link #beta}, * {@link LinearThresholdUnit#initialWeight}, {@link LinearThresholdUnit#threshold}, * {@link LinearThresholdUnit#positiveThickness}, {@link LinearThresholdUnit#negativeThickness}, * and finally {@link LinearThresholdUnit#bias}. * * @param out The output stream. **/ public void write(PrintStream out) { out.println(name + ": " + learningRate + ", " + beta + ", " + initialWeight + ", " + threshold + ", " + positiveThickness + ", " + negativeThickness + ", " + bias); if (lexicon.size() == 0) weightVector.write(out); else weightVector.write(out, lexicon); }
/** * Returns this learner's feature lexicon after discarding any feature counts it may have been * storing. This method is likely only useful when the lexicon and its counts are currently * stored on disk and {@link #readLexiconOnDemand(String)} or {@link #readLexiconOnDemand(URL)} * has already been called, in which case the lexicon is read from disk without wasting time * loading the counts. **/ public Lexicon getLexiconDiscardCounts() { if (readLexiconOnDemand && (lexicon == null || lexicon.size() == 0)) lexicon = Lexicon.readLexicon(lexFilePath, false); else lexicon.countFeatures(Lexicon.CountPolicy.none); return lexicon; }
/** * Sets the label lexicon. * * @param l A feature lexicon. **/ public void setLabelLexicon(Lexicon l) { labelLexicon = l; if (labelLexicon == null) { predictions = null; return; } int N = labelLexicon.size(); predictions = new FVector(N); for (int i = 0; i < N; ++i) createPrediction(i); }
/** * Return possible tag values that the ChunkerAnnotator can produce. * * @return the set of string representing the tag values */ @Override public Set<String> getTagValues() { if (!isInitialized()) { doInitialize(); } Lexicon labelLexicon = tagger.getLabelLexicon(); Set<String> tagSet = new HashSet(); for (int i =0; i < labelLexicon.size(); ++i) { tagSet.add(labelLexicon.lookupKey(i).getStringValue()); } return tagSet; }
/** * Return possible tag values that the NERAnnotator can produce. * * @return the set of string representing the tag values */ @Override public Set<String> getTagValues() { if (!isInitialized()) { doInitialize(); } Lexicon labelLexicon = this.params.taggerLevel1.getLabelLexicon(); Set<String> tagSet = new HashSet<String>(); for (int i =0; i < labelLexicon.size(); ++i) { tagSet.add(labelLexicon.lookupKey(i).getStringValue()); } return tagSet; } }
/** * Return possible tag values that the ChunkerAnnotator can produce. * * @return the set of string representing the tag values */ @Override public Set<String> getTagValues() { if (!isInitialized()) { doInitialize(); } Lexicon labelLexicon = tagger.getLabelLexicon(); Set<String> tagSet = new HashSet(); for (int i =0; i < labelLexicon.size(); ++i) { tagSet.add(labelLexicon.lookupKey(i).getStringValue()); } return tagSet; }
/** * Returns the size of the lexicon after any pruning that may have taken place or 0 if the * lexicon's location isn't known. **/ public int getPrunedLexiconSize() { if ((lexicon == null || lexicon.size() == 0) && readLexiconOnDemand) { ExceptionlessInputStream in = ExceptionlessInputStream.openCompressedStream(lexFilePath); int result = Lexicon.readPrunedSize(in); in.close(); return result; } return lexicon == null ? 0 : lexicon.getCutoff(); }
@Override public void initialize(ResourceManager resourceManager) { try { classifier = new LocalCommaClassifier(); Datastore ds = new Datastore(new ResourceConfigurator().getDefaultConfig()); File f = ds.getDirectory("org.cogcomp.comma-srl", "comma-srl-models", 2.2, false); String folder = f.toString() + File.separator + "comma-srl-models" + File.separator; classifier.readLexicon(folder + "LocalCommaClassifier.lex"); classifier.readModel(folder + "LocalCommaClassifier.lc"); } catch (Exception e) { e.printStackTrace(); } assert classifier.getPrunedLexiconSize() > 1000; assert classifier.getLabelLexicon().size() > 5; }
@Override public void initialize(ResourceManager resourceManager) { try { classifier = new LocalCommaClassifier(); Datastore ds = new Datastore(new ResourceConfigurator().getDefaultConfig()); File f = ds.getDirectory("org.cogcomp.comma-srl", "comma-srl-models", 2.2, false); String folder = f.toString() + File.separator + "comma-srl-models" + File.separator; classifier.readLexicon(folder + "LocalCommaClassifier.lex"); classifier.readModel(folder + "LocalCommaClassifier.lc"); } catch (Exception e) { e.printStackTrace(); } assert classifier.getPrunedLexiconSize() > 1000; assert classifier.getLabelLexicon().size() > 5; }