最近我一直在努力训练n-gram实体 斯坦福 </跨度> 核心 NLP </跨度> 。我已经按照以下教程 - http://nlp.stanford.edu/software/crf-faq.shtml#b
有了这个,我能够指导我,以防我误解了 斯坦福 </跨度> 教程和相同的教程可用于n-gram训练。
我坚持的是以下属性
这是一个漫长的等待回答。我无法找到使用Stanford Core完成任务的方法。但任务完成了。我使用了LingPipe NLP库。只是在这里引用答案,因为我认为其他人可以从中受益。
请查看 Lingpipe牌 如果您是开发人员或研究人员或者曾经做过什么,那么在深入了解实施之前。
Lingpipe提供各种NER方法。
1)基于字典的NER
2)统计NER(基于HMM)
3)基于规则的NER等
我使用了字典以及统计方法。
第一个是直接查找方法,第二个是基于培训。
可以找到基于字典的NER的示例 这里
历史方法需要培训文件。我使用了以下格式的文件 -
<root> <s> data line with the <ENAMEX TYPE="myentity">entity1</ENAMEX> to be trained</s> ... <s> with the <ENAMEX TYPE="myentity">entity2</ENAMEX> annotated </s> </root>
然后我使用以下代码来训练实体。
import java.io.File; import java.io.IOException; import com.aliasi.chunk.CharLmHmmChunker; import com.aliasi.corpus.parsers.Muc6ChunkParser; import com.aliasi.hmm.HmmCharLmEstimator; import com.aliasi.tokenizer.IndoEuropeanTokenizerFactory; import com.aliasi.tokenizer.TokenizerFactory; import com.aliasi.util.AbstractExternalizable; @SuppressWarnings("deprecation") public class TrainEntities { static final int MAX_N_GRAM = 50; static final int NUM_CHARS = 300; static final double LM_INTERPOLATION = MAX_N_GRAM; // default behavior public static void main(String[] args) throws IOException { File corpusFile = new File("inputfile.txt");// my annotated file File modelFile = new File("outputmodelfile.model"); System.out.println("Setting up Chunker Estimator"); TokenizerFactory factory = IndoEuropeanTokenizerFactory.INSTANCE; HmmCharLmEstimator hmmEstimator = new HmmCharLmEstimator(MAX_N_GRAM,NUM_CHARS,LM_INTERPOLATION); CharLmHmmChunker chunkerEstimator = new CharLmHmmChunker(factory,hmmEstimator); System.out.println("Setting up Data Parser"); Muc6ChunkParser parser = new Muc6ChunkParser(); parser.setHandler( chunkerEstimator); System.out.println("Training with Data from File=" + corpusFile); parser.parse(corpusFile); System.out.println("Compiling and Writing Model to File=" + modelFile); AbstractExternalizable.compileTo(chunkerEstimator,modelFile); } }
为了测试NER,我使用了以下课程
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.util.ArrayList; import java.util.Set; import com.aliasi.chunk.Chunk; import com.aliasi.chunk.Chunker; import com.aliasi.chunk.Chunking; import com.aliasi.util.AbstractExternalizable; public class Recognition { public static void main(String[] args) throws Exception { File modelFile = new File("outputmodelfile.model"); Chunker chunker = (Chunker) AbstractExternalizable .readObject(modelFile); String testString="my test string"; Chunking chunking = chunker.chunk(testString); Set<Chunk> test = chunking.chunkSet(); for (Chunk c : test) { System.out.println(testString + " : " + testString.substring(c.start(), c.end()) + " >> " + c.type()); } } }
代码礼貌:谷歌:)
答案基本上在你引用的例子中给出,其中“Emma Woodhouse”是一个单一的名字。我们提供的默认模型使用IO编码,并假设同一类的相邻令牌是同一实体的一部分。在许多情况下,这几乎总是正确的,并使模型更简单。但是,如果您不想这样做,您可以使用其他标签编码训练NER模型,例如常用的IOB编码,您可以在其中标记事物:
Emma B-PERSON Woodhouse I-PERSON
然后,可以表示相同类别但不是相同实体的相邻令牌。
我面临着为自动化域标记ngram短语的同样挑战。我正在寻找一种有效的关键字映射,可用于在稍后阶段创建培训文件。我最终在NLP管道中使用了regexNER,提供了一个带有正则表达式(ngram组件术语)的映射文件及其相应的标签。请注意,在这种情况下没有实现NER机器学习。希望这些信息有助于某人!