Skip to content

Instantly share code, notes, and snippets.

@allanj
Created March 21, 2019 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allanj/a4aa3c97cb679af09a9a621693dcd932 to your computer and use it in GitHub Desktop.
Save allanj/a4aa3c97cb679af09a9a621693dcd932 to your computer and use it in GitHub Desktop.
Print the feature string in the StatNLP Java framework (Put to main file)
//main.java
//First of all, after create `GlobalNetworkParam` object.
// run the following code:
GlobalNetworkParam gnp = new GlobalNetworkParam(optimizer, gnnp);
gnp.setStoreFeatureReps();
/************************
After the model has been trained.
model.train(...)
The following code is used to print the features
******************/
GlobalNetworkParam gnp = model.getFeatureManager().getParam_G();
StringIndex strIdx = gnp.getStringIndex();
strIdx.buildReverseIndex();
gnp.setStoreFeatureReps();
for (int i = 0; i < gnp.size(); i++) { //size is the number of all features
int[] fs = gnp.getFeatureRep(i);
String type = strIdx.get(fs[0]);
String output = strIdx.get(fs[1]);
String input = strIdx.get(fs[2]);
System.out.println(type + " " + output + input) ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment