Stanford nlp StanfordCoreNLP管道的重新加载CRF-NER模型

Stanford nlp StanfordCoreNLP管道的重新加载CRF-NER模型,stanford-nlp,Stanford Nlp,我正在制作一个web应用程序(GUI),用于构建CRF NER模型,而不是手动创建CSV文件。当用户收集大量培训文件时,他应该能够生成一个新模型并进行尝试。 我遇到的问题是重新加载模型。当我给管道赋值时,比如 pipeline = new StanfordCoreNLP(props) 模型保持不变。我尝试使用清除注释池 StanfordCoreNLP.clearAnnotatorPool() 但一切都没有改变。这是可能的,还是我每次都必须重新启动整个应用程序才能让它正常工作 编辑(澄清):

我正在制作一个web应用程序(GUI),用于构建CRF NER模型,而不是手动创建CSV文件。当用户收集大量培训文件时,他应该能够生成一个新模型并进行尝试。
我遇到的问题是重新加载模型。当我给管道赋值时,比如

pipeline = new StanfordCoreNLP(props)
模型保持不变。我尝试使用清除注释池

StanfordCoreNLP.clearAnnotatorPool()
但一切都没有改变。这是可能的,还是我每次都必须重新启动整个应用程序才能让它正常工作

编辑(澄清):

我在同一个类中有两个方法:
nerString()
train()
。大概是这样的:

class NerService {

  private var pipeline: StanfordCoreNLP = null

  loadPipelines()

  private def loadPipelines(): Unit = {

    val props = new Properties()
    props.setProperty("tokenize.class", "BosnianTokenizer")
    props.setProperty("ner.model", "conf/NER/classifiers/ner-ba-model.ser.gz") // NER CRF model
    props.setProperty("ner.useSUTime", "false")    
    props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner")

    pipeline = new StanfordCoreNLP(propsNER)    
  }

  def nerString(tekst: String): List[TokenNER] = {
    val document = new Annotation(tekst)
    pipeline.annotate(document)
    ...
  }

  /////////////// train new NER model ///////////////////////
  private val trainProps = StringUtils.propFileToProperties("conf/NER/classifiers/ner-ba-training.prop")
  private val serializeTo = "conf/NER/classifiers/ner-ba-model.ser.gz" // save at location...
  private val inputDir = new File("conf/NER/classifiers/input")
  private val fileFilter = new WildcardFileFilter("*.tsv")
  private val dirFilter = TrueFileFilter.TRUE

  def train(): Unit = {
    val allFiles = FileUtils.listFiles(inputDir, fileFilter, dirFilter).asScala
    val trainFileList = allFiles.map(_.getPath).mkString(",")
    trainProps.setProperty("trainFileList", trainFileList)
    val flags = new SeqClassifierFlags(trainProps)

    val crf = new CRFClassifier[CoreLabel](flags)    
    crf.train()    
    crf.serializeClassifier(serializeTo)

    loadPipelines()
  }
}
loadPipelines()
用于在创建新的NER模型时重新分配管道。

我如何知道模型没有更新?我有一个手动包含的文本,可以看到有无文本的区别。

您能澄清一下web应用程序是如何工作的吗?当用户构建新模型时,他们是否指定新模型所在的路径,然后设置props.setProperty(“ner.model”,“new/path/to/model”);在重建管道之前?我添加了额外的解释,感谢您抽出时间:我已经找到了一个解决方案,现在我正在生成一个新的模型,并在其名称后面附加一个时间戳。同时删除旧型号…:D您能否澄清web应用程序的工作原理?当用户构建新模型时,他们是否指定新模型所在的路径,然后设置props.setProperty(“ner.model”,“new/path/to/model”);在重建管道之前?我添加了额外的解释,感谢您抽出时间:我已经找到了一个解决方案,现在我正在生成一个新的模型,并在其名称后面附加一个时间戳。同时删除旧型号…:D