@CommandDescription(description = "<DESCRIPTION>\n" + "\tThis procedure is used to extract the weight vector from a saved model \n" + "<INPUT>\n" + "\tIt receives 2 different arguments. \n" + "\t1) model_file (a string), the file name of a trained model \n" + "\t2) output_file (a string), the file name that will be used to put the contain of the weight vector. \n" + "<OUTPUT>\n" + "\tThe weight vector will be output in the ${output_file}.") public static void outputWeightVector(String model_name, String output_file) throws IOException, ClassNotFoundException { JLISModelIOManager io = new JLISModelIOManager(); RerankerModel model = (RerankerModel) io.loadModel(model_name); ArrayList<String> out = new ArrayList<String>(); double[] w = model.wv.getInternalArray(); for (int i = 0; i < w.length; i++) out.add(i + ":" + w[i]); LineIO.write(output_file, out); System.out.println("Finish putting the weight vector at " + output_file); } }
@CommandDescription(description = "<DESCRIPTION>\n" + "\tThis procedure is used to extract the weight vector from a saved model \n" + "<INPUT>\n" + "\tIt receives 2 different arguments. \n" + "\t1) model_file (a string), the file name of a trained model \n" + "\t2) output_file (a string), the file name that will be used to put the contain of the weight vector. \n" + "<OUTPUT>\n" + "\tThe weight vector will be output in the ${output_file}.") public static void outputWeightVector(String model_name, String output_file) throws IOException, ClassNotFoundException { JLISModelIOManager io = new JLISModelIOManager(); MulticlassModel model = (MulticlassModel) io.loadModel(model_name); String[] reverse = model.getReverseMapping(); ArrayList<String> out = new ArrayList<String>(); int start = 0; double[] w = model.wv.getInternalArray(); for (int i = 0; i < reverse.length; i++) { out.add("Label:" + reverse[i]); for (int t = 0; t < model.n_base_feature_in_train; t++) { if (t == model.n_base_feature_in_train - 1) out.add(t + ":" + w[start + t] + " (bias)"); else out.add(t + ":" + w[start + t]); } start += model.n_base_feature_in_train; } LineIO.write(output_file, out); System.out.println("Finish putting the weight vector at " + output_file); }