带有mapreduce的stanfordcorenlp(错误:超出gc开销限制)

z5btuh9x  于 2021-06-02  发布在  Hadoop
关注(0)|答案(0)|浏览(282)

我有一个文本文件,其中包含一组文档ID和文档内容,以“:”分隔。下面是一个例子

  1. 139::This is a sentence in document 139. This is another sentence.
  2. 140::This is a sentence in document 140. This is another sentence.

我想用stanfordcorenlp对这些句子进行命名实体识别。这在传统的java程序中工作得很好。现在我想用mapreduce做同样的事情。我尝试在Map器的setup()方法中加载stanfordcorenlp分类器,map()方法执行命名实体标记,如下所示:

  1. public class NerMapper extends Mapper<LongWritable, Text, Text, Text>{
  2. StanfordCoreNLP pipeline;
  3. @Override
  4. protected void setup(Mapper<LongWritable, Text, Text, Text>.Context context)
  5. throws IOException, InterruptedException {
  6. // TODO Auto-generated method stub
  7. super.setup(context);
  8. Properties props = new Properties();
  9. props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref, relation");
  10. pipeline = new StanfordCoreNLP(props);
  11. }
  12. @Override
  13. protected void map(LongWritable key, Text value,
  14. Mapper<LongWritable, Text, Text, Text>.Context context) throws IOException,
  15. InterruptedException {
  16. // TODO Auto-generated method stub
  17. String[] input = value.toString().split("::");
  18. List<DataTuple> dataTuples = new ArrayList<DataTuple>();
  19. Annotation annotation = new Annotation(input[1]);
  20. pipeline.annotate(annotation);
  21. List<CoreMap> sentences = annotation.get(SentencesAnnotation.class);
  22. for(CoreMap sentence : sentences){
  23. //extract named entities
  24. //write <documentID>::<the named entity itself>::<the named entity tag>
  25. }
  26. }
  27. }

在运行作业时,它失败,错误为“超出gc开销限制”。我尝试了不同的堆大小 export HADOOP_OPTS="-Xmx892m" 在运行作业之前,我使用 -libjars 选择 hadoop jar 命令。输入文档通常只包含4-5个正常大小的句子。我知道问题出在setup()方法中分类器的初始化上,但我还没有弄清楚到底哪里出了问题。我真的很感激这里的任何帮助!
我使用的是hadoop2.6.0、stanford corenlp3.4.1和java1.7。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题