斯坦福NLP:OutOfMemoryError
我正在注释和分析一系列文本文件 pipeline.annotate方法每次读取文件时都会变得越来越慢。最终,我得到了一个OutOfMemory错误 管道初始化一次:斯坦福NLP:OutOfMemoryError,nlp,stanford-nlp,Nlp,Stanford Nlp,我正在注释和分析一系列文本文件 pipeline.annotate方法每次读取文件时都会变得越来越慢。最终,我得到了一个OutOfMemory错误 管道初始化一次: protected void initializeNlp() { Log.getLogger().debug("Starting Stanford NLP"); // creates a StanfordCoreNLP object, with POS tagging, lemmatization, //
protected void initializeNlp()
{
Log.getLogger().debug("Starting Stanford NLP");
// creates a StanfordCoreNLP object, with POS tagging, lemmatization,
// NER, parsing, and
Properties props = new Properties();
props.put("annotators", "tokenize, ssplit, pos, lemma, ner, regexner, depparse, natlog, openie");
props.put("regexner.mapping", namedEntityPropertiesPath);
pipeline = new StanfordCoreNLP(props);
Log.getLogger().debug("\n\n\nStarted Stanford NLP Successfully\n\n\n");
}
然后,我使用相同的管道实例处理每个文件(如SO上其他地方和斯坦福大学推荐的)
说清楚一点,我想问题出在我的配置上。但是,我确信暂停和内存问题发生在pipeline.annotate(file)方法中
在处理每个文件后,我会处理除管道(例如CoreLabel)之外的所有对Stanford NLP对象的引用。也就是说,在我的代码中,除了方法级别之外,我不保留对任何Stanford对象的引用
任何提示或指导都将不胜感激好的,问题的最后一句话让我仔细检查了一下。答案是我在自己的一个类中保留了对CoreMap的引用。换句话说,我在记忆中保留了语料库中每个句子的所有树、标记和其他分析 简而言之,为给定数量的句子保留StanfordNLP CoreMaps,然后进行处置
(我希望一位核心计算语言学家会说,一旦分析了CoreMap,就很少需要保留它,但我必须在这里声明我的新手身份)好的,问题的最后一句话让我仔细检查了一下。答案是我在自己的一个类中保留了对CoreMap的引用。换句话说,我在记忆中保留了语料库中每个句子的所有树、标记和其他分析 简而言之,为给定数量的句子保留StanfordNLP CoreMaps,然后进行处置 (我希望一位核心计算语言学家会说,一旦分析了CoreMap,就很少需要保留它,但我必须在此声明我的新手身份)
public void processFile(Path file)
{
try
{
Instant start = Instant.now();
Annotation document = new Annotation(cleanString);
Log.getLogger().info("ANNOTATE");
pipeline.annotate(document);
Long millis= Duration.between(start, Instant.now()).toMillis();
Log.getLogger().info("Annotation Duration in millis: "+millis);
AnalyzedFile af = AnalyzedFileFactory.getAnalyzedFile(AnalyzedFileFactory.GENERIC_JOB_POST, file);
processSentences(af, document);
Log.getLogger().info("\n\n\nFile Processing Complete\n\n\n\n\n");
Long millis1= Duration.between(start, Instant.now()).toMillis();
Log.getLogger().info("Total Duration in millis: "+millis1);
allFiles.put(file.toUri().toString(), af);
}
catch (Exception e)
{
Log.getLogger().debug(e.getMessage(), e);
}
}