use of edu.stanford.nlp.parser.dvparser.DVModel in project CoreNLP by stanfordnlp.
the class ConvertModels method readParser.
public static LexicalizedParser readParser(ObjectInputStream in) throws IOException, ClassNotFoundException {
LexicalizedParser model = ErasureUtils.uncheckedCast(in.readObject());
Function<List<List<Double>>, SimpleMatrix> f = (x) -> toMatrix(x);
TwoDimensionalMap<String, String, List<List<Double>>> map2dSM = ErasureUtils.uncheckedCast(in.readObject());
TwoDimensionalMap<String, String, SimpleMatrix> binaryTransform = transform2DMap(map2dSM, f);
Map<String, List<List<Double>>> map = ErasureUtils.uncheckedCast(in.readObject());
Map<String, SimpleMatrix> unaryTransform = transformMap(map, f);
map2dSM = ErasureUtils.uncheckedCast(in.readObject());
TwoDimensionalMap<String, String, SimpleMatrix> binaryScore = transform2DMap(map2dSM, f);
map = ErasureUtils.uncheckedCast(in.readObject());
Map<String, SimpleMatrix> unaryScore = transformMap(map, f);
map = ErasureUtils.uncheckedCast(in.readObject());
Map<String, SimpleMatrix> wordVectors = transformMap(map, f);
DVModel dvModel = new DVModel(binaryTransform, unaryTransform, binaryScore, unaryScore, wordVectors, model.getOp());
DVModelReranker reranker = new DVModelReranker(dvModel);
model.reranker = reranker;
return model;
}
use of edu.stanford.nlp.parser.dvparser.DVModel in project CoreNLP by stanfordnlp.
the class ConvertModels method writeParser.
public static void writeParser(LexicalizedParser model, DVModelReranker reranker, ObjectOutputStream out) throws IOException {
out.writeObject(model);
Function<SimpleMatrix, List<List<Double>>> f = (SimpleMatrix x) -> fromMatrix(x);
DVModel dvmodel = reranker.getModel();
out.writeObject(transform2DMap(dvmodel.binaryTransform, f));
out.writeObject(transformMap(dvmodel.unaryTransform, f));
out.writeObject(transform2DMap(dvmodel.binaryScore, f));
out.writeObject(transformMap(dvmodel.unaryScore, f));
out.writeObject(transformMap(dvmodel.wordVectors, f));
}
Aggregations