nlp - 使用命名实体训练模型

标签 nlp stanford-nlp sentiment-analysis named-entity-recognition pos-tagger

我正在使用命名实体识别器查看standford corenlp。我有不同类型的输入文本,我需要将其标记到我自己的实体中。所以我开始训练我自己的模型,但它似乎不起作用。

例如:我的输入文本字符串是“Book of 49 Magazine Articles on Toyota Land Cruiser 1956-1987 Gold Portfolio http://t.co/EqxmY1VmLg http://t.co/F0Vefuoj9Q

我通过示例来训练我自己的模型,并仅寻找一些我感兴趣的单词。

我的 jane-austen-emma-ch1.tsv 看起来像这样

Toyota  PERS
Land Cruiser    PERS

从上面的输入文本中我只对这两个词感兴趣。其一是 丰田,另一个词是陆地巡洋舰。

austin.prop 看起来像这样

trainFile = jane-austen-emma-ch1.tsv
serializeTo = ner-model.ser.gz
map = word=0,answer=1
useClassFeature=true
useWord=true
useNGrams=true
noMidNGrams=true
useDisjunctive=true
maxNGramLeng=6
usePrev=true
useNext=true
useSequences=true
usePrevSequences=true
maxLeft=1
useTypeSeqs=true
useTypeSeqs2=true
useTypeySequences=true
wordShape=chris2useLC

运行以下命令生成ner-model.ser.gz文件

java -cp stanford-corenlp-3.4.1.jar edu.stanford.nlp.ie.crf.CRFClassifier -prop austen.prop

public static void main(String[] args) {
        String serializedClassifier = "edu/stanford/nlp/models/ner/english.muc.7class.distsim.crf.ser.gz";
        String serializedClassifier2 = "C:/standford-ner/ner-model.ser.gz";
        try {
            NERClassifierCombiner classifier = new NERClassifierCombiner(false, false, 
                    serializedClassifier2,serializedClassifier);
            String ss = "Book of 49 Magazine Articles on Toyota Land Cruiser 1956-1987 Gold Portfolio http://t.co/EqxmY1VmLg http://t.co/F0Vefuoj9Q";
            System.out.println("---");
            List<List<CoreLabel>> out = classifier.classify(ss);
            for (List<CoreLabel> sentence : out) {
              for (CoreLabel word : sentence) {
                System.out.print(word.word() + '/' + word.get(AnswerAnnotation.class) + ' ');
              }
              System.out.println();
            }

        } catch (ClassCastException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

这是我得到的输出

Book/PERS of/PERS 49/O Magazine/PERS Articles/PERS on/O Toyota/PERS Land/PERS Cruiser/PERS 1956-1987/PERS Gold/O Portfolio/PERS http://t.co/EqxmY1VmLg/PERS http://t.co/F0Vefuoj9Q/PERS

我认为这是错误的。我正在寻找丰田/PERS 和陆地巡洋舰/PERS(这是一个多值领域。

感谢您的帮助。非常感谢任何帮助。

最佳答案

我相信您还应该将 0 实体的示例放入您的 trainFile 中。正如您所提供的,trainFile对于学习来说太简单了,它需要0PERSON示例 因此它不会将所有内容都注释为 PERSON。你没有教它关于你不感兴趣的实体。说吧,像这样:

Toyota  PERS
of    0
Portfolio    0
49    0

等等。

此外,对于短语级识别,您应该查看regexner,其中您可以使用模式(模式对我们有好处)。我正在使用 API 处理此问题,并且我有以下代码:

Properties props = new Properties();
props.put("annotators", "tokenize, ssplit, pos, lemma, ner, regexner");
props.put("regexner.mapping", customLocationFilename);

具有以下customLocationFileName:

Make Believe Town   figure of speech    ORGANIZATION
( /Hello/ [{ ner:PERSON }]+ )   salut   PERSON
Bachelor of (Arts|Laws|Science|Engineering) DEGREE
( /University/ /of/ [{ ner:LOCATION }] )    SCHOOL

和文本:你好,玛丽·凯勒出生于 7 月 4 日,并获得了理学学士学位。我们于 8 月 15 日从 Make Believe Town 仓库运往伦敦大学的 cargo C27655 的部分发票(100,000 欧元,即大约 40%)。 INV2345 用于余额。客户联系人(Sigourney Weaver)表示他们将按照通常的信用条款(30 天)支付这笔费用。

我得到的输出

Hello Mary Keller is a salut
4th of July is a DATE
Bachelor of Science is a DEGREE
$ 100,000 is a MONEY
40 % is a PERCENT
15th August is a DATE
University of London is a ORGANIZATION
Make Believe Town is a figure of speech
Sigourney Weaver is a PERSON
30 days is a DURATION

有关如何执行此操作的更多信息,您可以查看 example这让我继续前进。

关于nlp - 使用命名实体训练模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29755910/

相关文章:

stanford-nlp - Stanford CoreNLP BasicPipelineExample 不起作用

java - Lingpipe 中使用伯努利分类器进行分类

elasticsearch - 情绪分析-弹性叠加

python - 如何有效地循环此数据帧并使用内置的 numpy 或 pandas 执行函数?

python - 如何让 POS n-gram 更有效?

java - 我正在尝试从文本中提取语义信息

python - 如何从图像中提取信息

python - NLP - 使用哪种技术对段落标签进行分类?

java - 斯坦福 CoreNLP : StreamCorruptedException: invalid stream header: 54686973

stanford-nlp - 为什么 stanford corenlp 性别识别是不确定的?