use of edu.illinois.cs.cogcomp.lbjava.learn.SparseAveragedPerceptron.AveragedWeightVector in project cogcomp-nlp by CogComp.
the class NERAnnotator method getL1FeatureWeights.
/**
* Return the features and the weight vectors for each SparseAveragedPerceptron
* in the network learner for the L1 model.
*
* @return the set of string representing the tag values
*/
public HashMap<Feature, double[]> getL1FeatureWeights() {
if (!isInitialized()) {
doInitialize();
}
SparseNetworkLearner l1 = this.params.taggerLevel1;
Map lex = l1.getLexicon().getMap();
OVector ov = l1.getNetwork();
HashMap<Feature, double[]> weightsPerFeature = new HashMap<>();
// for each feature, make a map entry keyed on feature name.
int cnt = 0;
for (Object mapentry : lex.entrySet()) {
// get the feature, and the features weight index within each of
// the network fo learners.
Feature feature = (Feature) ((Entry) mapentry).getKey();
int index = ((Integer) ((Entry) mapentry).getValue()).intValue();
double[] weights = new double[ov.size()];
for (int i = 0; i < ov.size(); i++) {
SparseAveragedPerceptron sap = (SparseAveragedPerceptron) (ov.get(i));
AveragedWeightVector awv = sap.getAveragedWeightVector();
weights[i] = awv.getRawWeights().get(index);
}
weightsPerFeature.put(feature, weights);
}
return weightsPerFeature;
}
use of edu.illinois.cs.cogcomp.lbjava.learn.SparseAveragedPerceptron.AveragedWeightVector in project cogcomp-nlp by CogComp.
the class NERAnnotator method getL2FeatureWeights.
/**
* Return the features and the weight vectors for each SparseAveragedPerceptron
* in the network learner for the L2 model.
*
* @return the set of string representing the tag values
*/
public HashMap<Feature, double[]> getL2FeatureWeights() {
if (!isInitialized()) {
doInitialize();
}
SparseNetworkLearner l2 = this.params.taggerLevel2;
Map lex = l2.getLexicon().getMap();
OVector ov = l2.getNetwork();
HashMap<Feature, double[]> weightsPerFeature = new HashMap<>();
// for each feature, make a map entry keyed on feature name.
for (Object mapentry : lex.entrySet()) {
// get the feature, and the features weight index within each of
// the network fo learners.
Feature feature = (Feature) ((Entry) mapentry).getKey();
int index = ((Integer) ((Entry) mapentry).getValue()).intValue();
double[] weights = new double[ov.size()];
for (int i = 0; i < ov.size(); i++) {
SparseAveragedPerceptron sap = (SparseAveragedPerceptron) (ov.get(i));
AveragedWeightVector awv = sap.getAveragedWeightVector();
weights[i] = awv.getRawWeights().get(index);
}
weightsPerFeature.put(feature, weights);
}
return weightsPerFeature;
}
Aggregations