public void loadModelFile(String modelFile) {
loadModelFile(modelFile, true);
}
private void loadModelFile(String modelFile, boolean verbose) {
Timing t = new Timing();
try {
// System.err.println(Config.SEPARATOR);
System.err.println("Loading depparse model file: " + modelFile + " ... ");
String s;
BufferedReader input = IOUtils.readerFromString(modelFile);
int nDict, nPOS, nLabel;
int eSize, hSize, nTokens, nPreComputed;
nDict = nPOS = nLabel = eSize = hSize = nTokens = nPreComputed = 0;
for (int k = 0; k < 7; ++k) {
s = input.readLine();
if (verbose) {
System.err.println(s);
}
int number = Integer.parseInt(s.substring(s.indexOf('=') + 1));
switch (k) {
case 0:
nDict = number;
break;
case 1:
nPOS = number;
break;
case 2:
nLabel = number;
break;
case 3:
eSize = number;
break;
case 4:
hSize = number;
break;
case 5:
nTokens = number;
break;
case 6:
nPreComputed = number;
break;
default:
break;
}
}
knownWords = new ArrayList<String>();
knownPos = new ArrayList<String>();
knownLabels = new ArrayList<String>();
double[][] E = new double[nDict + nPOS + nLabel][eSize];
String[] splits;
int index = 0;
for (int k = 0; k < nDict; ++k) {
s = input.readLine();
splits = s.split(" ");
knownWords.add(splits[0]);
for (int i = 0; i < eSize; ++i)
E[index][i] = Double.parseDouble(splits[i + 1]);
index = index + 1;
}
for (int k = 0; k < nPOS; ++k) {
s = input.readLine();
splits = s.split(" ");
knownPos.add(splits[0]);
for (int i = 0; i < eSize; ++i)
E[index][i] = Double.parseDouble(splits[i + 1]);
index = index + 1;
}
for (int k = 0; k < nLabel; ++k) {
s = input.readLine();
splits = s.split(" ");
knownLabels.add(splits[0]);
for (int i = 0; i < eSize; ++i)
E[index][i] = Double.parseDouble(splits[i + 1]);
index = index + 1;
}
generateIDs();
double[][] W1 = new double[hSize][eSize * nTokens];
for (int j = 0; j < W1[0].length; ++j) {
s = input.readLine();
splits = s.split(" ");
for (int i = 0; i < W1.length; ++i)
W1[i][j] = Double.parseDouble(splits[i]);
}
double[] b1 = new double[hSize];
s = input.readLine();
splits = s.split(" ");
for (int i = 0; i < b1.length; ++i)
b1[i] = Double.parseDouble(splits[i]);
double[][] W2 = new double[nLabel * 2 - 1][hSize];
for (int j = 0; j < W2[0].length; ++j) {
s = input.readLine();
splits = s.split(" ");
for (int i = 0; i < W2.length; ++i)
W2[i][j] = Double.parseDouble(splits[i]);
}
preComputed = new ArrayList<Integer>();
while (preComputed.size() < nPreComputed) {
s = input.readLine();
splits = s.split(" ");
for (String split : splits) {
preComputed.add(Integer.parseInt(split));
}
}
input.close();
classifier = new Classifier(config, E, W1, b1, W2, preComputed);
} catch (IOException e) {
throw new RuntimeIOException(e);
}
// initialize the loaded parser
initialize(verbose);
t.done("Initializing dependency parser");
}