首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >core-nlp中运行时和配置模式的分离

core-nlp中运行时和配置模式的分离
EN

Stack Overflow用户
提问于 2017-05-03 13:49:03
回答 1查看 22关注 0票数 0

我正在使用斯坦福大学的core-nlp管道来执行一些基本任务。下面是本教程中的示例代码副本。

代码语言:javascript
复制
public static void testcoreNLP(String inputText) throws IOException {

  Properties props = new Properties();
  props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
  props.put("coref.md.type", "rule");
  props.put("coref.mode", "statistical");
  props.put("coref.doClustering", "true");
  props.put("ner.model", "edu/stanford/nlp/models/ner/english.all.3class.distsim.crf.ser.gz,edu/stanford/nlp/models/ner/english.muc.7class.distsim.crf.ser.gz,edu/stanford/nlp/models/ner/english.conll.4class.distsim.crf.ser.gz");
  StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

  StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
  Annotation document = new Annotation(inputText);

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

  for(CoreMap sentence: sentences) {
        for (CoreLabel token: sentence.get(TokensAnnotation.class)) {
          String word = token.get(TextAnnotation.class);
          String pos = token.get(PartOfSpeechAnnotation.class);
          String ne = token.get(NamedEntityTagAnnotation.class);      
      System.out.println("word: " + word + " pos: " + pos + " ne:" + ne);
    }  
}

我的方法testcoreNLP (接受字符串inputText)正被其for-loop中的另一个方法(预处理文本的textPreprocessor())调用。

据我所知,每次to testcoreNLP方法加载所有模型文件(某些领域特定的-trained模型文件),每次运行大约消耗3-5秒。

如何将模型加载从运行时中分离出来?

EN

回答 1

Stack Overflow用户

发布于 2017-05-04 11:43:04

您的Java应用程序只需要构建一次管道。你可以把流水线加载代码从方法中去掉,然后只执行一次。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43751997

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档