Search in sources :

Example 1 with SparseNetworkLearner

use of edu.illinois.cs.cogcomp.lbjava.learn.SparseNetworkLearner 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;
}
Also used : HashMap(java.util.HashMap) OVector(edu.illinois.cs.cogcomp.core.datastructures.vectors.OVector) SparseNetworkLearner(edu.illinois.cs.cogcomp.lbjava.learn.SparseNetworkLearner) HashMap(java.util.HashMap) Map(java.util.Map) Feature(edu.illinois.cs.cogcomp.lbjava.classify.Feature) SparseAveragedPerceptron(edu.illinois.cs.cogcomp.lbjava.learn.SparseAveragedPerceptron) AveragedWeightVector(edu.illinois.cs.cogcomp.lbjava.learn.SparseAveragedPerceptron.AveragedWeightVector)

Example 2 with SparseNetworkLearner

use of edu.illinois.cs.cogcomp.lbjava.learn.SparseNetworkLearner 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;
}
Also used : HashMap(java.util.HashMap) OVector(edu.illinois.cs.cogcomp.core.datastructures.vectors.OVector) SparseNetworkLearner(edu.illinois.cs.cogcomp.lbjava.learn.SparseNetworkLearner) HashMap(java.util.HashMap) Map(java.util.Map) Feature(edu.illinois.cs.cogcomp.lbjava.classify.Feature) SparseAveragedPerceptron(edu.illinois.cs.cogcomp.lbjava.learn.SparseAveragedPerceptron) AveragedWeightVector(edu.illinois.cs.cogcomp.lbjava.learn.SparseAveragedPerceptron.AveragedWeightVector)

Aggregations

OVector (edu.illinois.cs.cogcomp.core.datastructures.vectors.OVector)2 Feature (edu.illinois.cs.cogcomp.lbjava.classify.Feature)2 SparseAveragedPerceptron (edu.illinois.cs.cogcomp.lbjava.learn.SparseAveragedPerceptron)2 AveragedWeightVector (edu.illinois.cs.cogcomp.lbjava.learn.SparseAveragedPerceptron.AveragedWeightVector)2 SparseNetworkLearner (edu.illinois.cs.cogcomp.lbjava.learn.SparseNetworkLearner)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2