Search in sources :

Example 1 with DVModel

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;
}
Also used : DVModelReranker(edu.stanford.nlp.parser.dvparser.DVModelReranker) ErasureUtils(edu.stanford.nlp.util.ErasureUtils) ObjectInputStream(java.io.ObjectInputStream) LexicalizedParser(edu.stanford.nlp.parser.lexparser.LexicalizedParser) Function(java.util.function.Function) ArrayList(java.util.ArrayList) FastNeuralCorefModel(edu.stanford.nlp.coref.fastneural.FastNeuralCorefModel) RNNOptions(edu.stanford.nlp.sentiment.RNNOptions) Locale(java.util.Locale) Map(java.util.Map) ObjectOutputStream(java.io.ObjectOutputStream) SentimentModel(edu.stanford.nlp.sentiment.SentimentModel) CollectionUtils(edu.stanford.nlp.util.CollectionUtils) SimpleMatrix(org.ejml.simple.SimpleMatrix) Properties(java.util.Properties) IOUtils(edu.stanford.nlp.io.IOUtils) FileOutputStream(java.io.FileOutputStream) NeuralCorefModel(edu.stanford.nlp.coref.neural.NeuralCorefModel) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) EmbeddingExtractor(edu.stanford.nlp.coref.neural.EmbeddingExtractor) StringUtils(edu.stanford.nlp.util.StringUtils) DVModel(edu.stanford.nlp.parser.dvparser.DVModel) Generics(edu.stanford.nlp.util.Generics) TwoDimensionalMap(edu.stanford.nlp.util.TwoDimensionalMap) LexicalizedParser(edu.stanford.nlp.parser.lexparser.LexicalizedParser) DVModel(edu.stanford.nlp.parser.dvparser.DVModel) SimpleMatrix(org.ejml.simple.SimpleMatrix) DVModelReranker(edu.stanford.nlp.parser.dvparser.DVModelReranker) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with DVModel

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));
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix) ArrayList(java.util.ArrayList) List(java.util.List) DVModel(edu.stanford.nlp.parser.dvparser.DVModel)

Aggregations

DVModel (edu.stanford.nlp.parser.dvparser.DVModel)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 SimpleMatrix (org.ejml.simple.SimpleMatrix)2 FastNeuralCorefModel (edu.stanford.nlp.coref.fastneural.FastNeuralCorefModel)1 EmbeddingExtractor (edu.stanford.nlp.coref.neural.EmbeddingExtractor)1 NeuralCorefModel (edu.stanford.nlp.coref.neural.NeuralCorefModel)1 IOUtils (edu.stanford.nlp.io.IOUtils)1 DVModelReranker (edu.stanford.nlp.parser.dvparser.DVModelReranker)1 LexicalizedParser (edu.stanford.nlp.parser.lexparser.LexicalizedParser)1 RNNOptions (edu.stanford.nlp.sentiment.RNNOptions)1 SentimentModel (edu.stanford.nlp.sentiment.SentimentModel)1 CollectionUtils (edu.stanford.nlp.util.CollectionUtils)1 ErasureUtils (edu.stanford.nlp.util.ErasureUtils)1 Generics (edu.stanford.nlp.util.Generics)1 StringUtils (edu.stanford.nlp.util.StringUtils)1 TwoDimensionalMap (edu.stanford.nlp.util.TwoDimensionalMap)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1