MITIE 即 MIT 的 NLP 团队发布的一个信息抽取库和工具。它是一款免费且先进的信息抽取工具,目前包含了命名实体抽取、二元关系检测功能,另外也提供了训练自定义抽取器和关系检测器的工具。
MITIE 是核心代码是使用 C++ 写的,建立在高性能的机器学习库 dlib 上。MIT 团队给我们提供了一些已训练好了的模型,这其中包含了英语、西班牙语和德语,这些模型都使用了大量的语料进行训练。我们发现并没有我们要的中文的模型,所以这个还得我们自己训练。
尽管 MITIE 是 C++ 写的,但它也提供了其他语言的调用 API 。在我自己的项目中常常会跟 Java 、 Python 混合用,所以只要编译成动态库再分别用 Java 和 Python 调用就行了,很方便。
看看 MIT 实验室的人怎么说就知道了。
I work at a lab and there are a lot of cool things about my job. In fact, I could go on all day about it, but in this post I want to talk about one thing in particular, which is that we recently got funded by the program to make an open source natural language processing library focused on information extraction.
Why make such a thing when there are already open source libraries out there for this (e.g. OpenNLP, NLTK, Stanford IE, etc.)? Well, if you look around you quickly find out that everything which exists is either expensive, not state-of-the-art, or GPL licensed. If you wanted to use this kind of NLP tool in a non-GPL project then you are either out of luck, have to pay a lot of money, or settle for something of low quality. Well, not anymore! We just released the first version of our MIT Information Extraction library which is built using state-of-the-art statistical machine learning tools.
然后创建一个 test.txt 文件,待测试内容为
最后编写代码如下,
执行结果为,
主要是要训练所有词向量特征,后面的实名实体模型和关系模型都是建立在它的基础上,MITIE 给我们提供了工具完成上述操作,我们可以用 cmake 生成vs项目,但一般我们没有必要改动到代码,直接使用 cmake 构建一下就可直接使用。主要操作有
再一个是需要收集大量的词汇,可以通过维基百科和百度百科收集,类似处理可以参加前面的文章 《如何使用中文维基百科语料》。
接着就可以开始训练了,参数e表示生成所有我们需要的模型,data为语料库的目录。
主要的一步都是要生成共享链接库,同样使用 cmake 可以很方便生成,到 mitielib 目录,
生成需要的链接库。
然后 python 就能轻易完成调用。而对于 Java 也而需要类似的操作,但它的构建过程还需要有 SWIG 。生成如下的链接库和 jar 包,然后 Java就能轻易完成调用。
以下是广告
========广告时间========
<a href="http://blog.csdn.net/wangyangzhizhou/article/details/74080321" target="_blank">为什么写《Tomcat内核设计剖析》</a>
=========================
欢迎关注:
