use of edu.stanford.nlp.coref.neural.EmbeddingExtractor in project CoreNLP by stanfordnlp.
the class ConvertModels method readFastCoref.
public static FastNeuralCorefModel readFastCoref(ObjectInputStream in) throws IOException, ClassNotFoundException {
Function<List<List<Double>>, SimpleMatrix> f = (x) -> toMatrix(x);
boolean conll = ErasureUtils.uncheckedCast(in.readObject());
boolean hasStatic = ErasureUtils.uncheckedCast(in.readObject());
Embedding staticEmbedding = (hasStatic) ? readEmbedding(in) : null;
Embedding tunedEmbedding = readEmbedding(in);
String naEmbedding = ErasureUtils.uncheckedCast(in.readObject());
EmbeddingExtractor embedding = new EmbeddingExtractor(conll, staticEmbedding, tunedEmbedding, naEmbedding);
Map<String, Integer> pairFeatures = ErasureUtils.uncheckedCast(in.readObject());
Map<String, Integer> mentionFeatures = ErasureUtils.uncheckedCast(in.readObject());
List<SimpleMatrix> weights = CollectionUtils.transformAsList(ErasureUtils.uncheckedCast(in.readObject()), f);
return new FastNeuralCorefModel(embedding, pairFeatures, mentionFeatures, weights);
}
use of edu.stanford.nlp.coref.neural.EmbeddingExtractor in project CoreNLP by stanfordnlp.
the class ConvertModels method writeFastCoref.
public static void writeFastCoref(FastNeuralCorefModel model, ObjectOutputStream out) throws IOException {
Function<SimpleMatrix, List<List<Double>>> f = (SimpleMatrix x) -> fromMatrix(x);
EmbeddingExtractor embedding = model.getEmbeddingExtractor();
out.writeObject(embedding.isConll());
Embedding staticEmbedding = embedding.getStaticWordEmbeddings();
if (staticEmbedding == null) {
out.writeObject(false);
} else {
out.writeObject(true);
writeEmbedding(staticEmbedding, out);
}
writeEmbedding(embedding.getTunedWordEmbeddings(), out);
out.writeObject(embedding.getNAEmbedding());
out.writeObject(model.getPairFeatureIds());
out.writeObject(model.getMentionFeatureIds());
out.writeObject(CollectionUtils.transformAsList(model.getAllWeights(), f));
}
use of edu.stanford.nlp.coref.neural.EmbeddingExtractor in project CoreNLP by stanfordnlp.
the class FastNeuralCorefModel method loadFromTextFiles.
public static FastNeuralCorefModel loadFromTextFiles(String path) {
List<SimpleMatrix> weights = NeuralUtils.loadTextMatrices(path + "weights.txt");
weights.set(weights.size() - 2, weights.get(weights.size() - 2).transpose());
Embedding embeddings = new Embedding(path + "embeddings.txt");
EmbeddingExtractor extractor = new EmbeddingExtractor(false, null, embeddings, "<missing>");
Map<String, Integer> pairFeatureIds = loadMapFromTextFile(path + "pair_features.txt");
Map<String, Integer> mentionFeatureIds = loadMapFromTextFile(path + "mention_features.txt");
return new FastNeuralCorefModel(extractor, pairFeatureIds, mentionFeatureIds, weights);
}
Aggregations