【问题标题】:Stanford CoreNLP - Exception in thread "main" java.lang.OutOfMemoryError: Java heap space斯坦福 CoreNLP - 线程“主”java.lang.OutOfMemoryError 中的异常:Java 堆空间
【发布时间】:2017-12-26 06:15:22
【问题描述】:

我正在尝试运行此网站上提供的简单程序 https://stanfordnlp.github.io/CoreNLP/api.html
我的程序

import java.io.BufferedReader;  
import java.io.BufferedWriter;  
import java.io.FileNotFoundException;  
import java.io.FileReader;  
import java.io.FileWriter;  
import java.io.IOException;  
import java.io.PrintWriter;  
import java.util.List;  
import java.util.Properties;  

import edu.stanford.nlp.ling.CoreAnnotations.NamedEntityTagAnnotation;  
import edu.stanford.nlp.ling.CoreAnnotations.PartOfSpeechAnnotation;  
import edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation;  
import edu.stanford.nlp.ling.CoreAnnotations.TextAnnotation;  
import edu.stanford.nlp.ling.CoreAnnotations.TokensAnnotation;  
import edu.stanford.nlp.ling.CoreLabel;  
import edu.stanford.nlp.pipeline.Annotation;  
import edu.stanford.nlp.pipeline.StanfordCoreNLP;  
import edu.stanford.nlp.util.CoreMap;  

public class StanfordClass {

    public static void main(String[] args) throws Exception {
     Properties props = new Properties();
      props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse");

        StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

        String text = "What is the Weather in Mumbai right now?";
         Annotation document = new Annotation(text);
          pipeline.annotate(document);

        List<CoreMap> sentences = document.get(SentencesAnnotation.class);

       for(CoreMap sentence: sentences) {
          // traversing the words in the current sentence
          // a CoreLabel is a CoreMap with additional token-specific methods
          for (CoreLabel token: sentence.get(TokensAnnotation.class)) {
            // this is the text of the token
            String word = token.get(TextAnnotation.class);
            // this is the POS tag of the token
            String pos = token.get(PartOfSpeechAnnotation.class);
            // this is the NER label of the token
            String ne = token.get(NamedEntityTagAnnotation.class);

            System.out.println(String.format("Print: word: [%s] pos: [%s] ne: [%s]",word, pos, ne));
          }
        }
    }
}  

但是在线程 "main" java.lang.OutOfMemoryError: Java heap space 中出现异常

我尝试了什么
1. 如果我从上面的代码中删除 ner(命名实体识别器)属性,即 props.setProperty("annotators", "tokenize, ssplit, pos, lemma, parse");
然后代码运行良好。
2.但我需要 ner(命名实体识别器),因此我将 eclipse.ini 文件中的堆大小增加到 1g,并确保这个大小对于这个程序来说已经足够了,并且还确保在这种情况下堆大小不是问题。我认为缺少某些东西,但没有得到。

【问题讨论】:

  • 您是否检查了占用更多内存的方法?
  • 我应该如何检查?
  • 这适用于 Java 5,但我使用的是 Java 8,对于这个简单的程序来说,最大 1gb 的堆大小太大了
  • 哦,对不起,我忘了用这个khelekore.org/jmp/tijmp
  • 我用过eclipse内存分析器,内存没有问题

标签: java stanford-nlp eclipse-neon


【解决方案1】:

经过大量搜索在这里得到答案 Using Stanford CoreNLP

使用以下答案:-
1.Windows -> 首选项
2.Java -> 已安装的 JRE
3.选择 JRE 并点击编辑
4. 在默认 VM 参数字段中,输入“-Xmx1024M”。 (或您的内存偏好,对于 1GB 的内存,它是 1024)
5.点击完成或确定。

【讨论】:

  • 我必须将堆空间设置为 4 GB 才能工作。即“-Xmx4096M”但是,它做到了! :) 在任务管理器(Windows 10)中观看 Eclipse,在演示程序完成之前,内存占用高达 5.9 GB。毫不奇怪,自然语言处理需要大量 RAM。
猜你喜欢
  • 2011-01-23
  • 2018-08-13
  • 2023-03-13
  • 1970-01-01
  • 2016-11-24
  • 2020-12-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多