首页 > 解决方案 > 添加属性时超出 GC 开销限制

问题描述

我刚刚开始使用用于 java 的 StanfordCoreNlp 库,并且在添加 coref 或 dcoref 注释属性时不断收到 GC 开销限制错误。知道如何解决这个问题吗?

出于测试目的,我逐渐将 JVM maxHeap 内存更改为 8GB 内存,这绝对不是问题。我尝试从属性中删除几个标签,这是唯一一个似乎解决开销错误的标签,它也只给出了StanfordCoreNlp 上的错误,simpleCore api 可以正常工作,但没有那么有效。代码片段与斯坦福官方文档中提供的示例相同。

public static void main(String[] args) {

            // run all Annotators on this text
            Properties props = new Properties();
            props.setProperty("annotators", "tokenize, ssplit, pos, lemma,ner, parse, coref");
            StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

// read some text in the text variable
            String text = "who is here?"; // Add your text here!
            Annotation document = new Annotation(text);

// run all Annotators on this text
            pipeline.annotate(document);

这是确切的错误消息:

Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
    at java.util.Arrays.copyOfRange(Arrays.java:3664)
    at java.lang.String.<init>(String.java:207)
    at edu.stanford.nlp.util.StringUtils.splitOnChar(StringUtils.java:537)
    at edu.stanford.nlp.coref.data.Dictionaries.loadGenderNumber(Dictionaries.java:406)
    at edu.stanford.nlp.coref.data.Dictionaries.<init>(Dictionaries.java:676)
    at edu.stanford.nlp.coref.data.Dictionaries.<init>(Dictionaries.java:576)
    at edu.stanford.nlp.coref.CorefSystem.<init>(CorefSystem.java:32)
    at edu.stanford.nlp.pipeline.CorefAnnotator.<init>(CorefAnnotator.java:67)
    at edu.stanford.nlp.pipeline.AnnotatorImplementations.coref(AnnotatorImplementations.java:196)
    at edu.stanford.nlp.pipeline.StanfordCoreNLP.lambda$getNamedAnnotators$14(StanfordCoreNLP.java:532)
    at edu.stanford.nlp.pipeline.StanfordCoreNLP$$Lambda$25/2137589296.apply(Unknown Source)
    at edu.stanford.nlp.pipeline.StanfordCoreNLP.lambda$null$30(StanfordCoreNLP.java:602)
    at edu.stanford.nlp.pipeline.StanfordCoreNLP$$Lambda$38/1798286609.get(Unknown Source)
    at edu.stanford.nlp.util.Lazy$3.compute(Lazy.java:126)
    at edu.stanford.nlp.util.Lazy.get(Lazy.java:31)
    at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:149)
    at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:251)
    at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:192)
    at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:188)
    at StanfordCoreNLPtest.main(StanfordCoreNLPtest.java:31)

进程以退出代码 1 结束

标签: stanford-nlp

解决方案


据我所知,这只能是由 Java 内存不足引起的——这里只是加载字典,而不是无限循环。您确定要指定如何正确设置可用内存吗?例如,如果在 Eclipse 下运行,您需要设置应用程序的内存而不是给 Eclipse 的内存。8GB 应该足以使用任何选项运行 CoreNLP(除非文档很大,但文档加载发生在加载 coref 之后)。但是您可以尝试使用 12GB 以防万一看看会发生什么......


推荐阅读