美文网首页
开发和评估分块器

开发和评估分块器

作者: 青椒rose炒饭 | 来源:发表于2019-07-10 16:54 被阅读0次

IOB格式和CoNLL2000语料库

语料库中的块类型貌似只有NP,VP和PP。

#从nltk中导入语料
from nltk.corpus import conll2000 as conll
import nltk
#字符串,单行,每行:单词 词性 在块中的IOB标记
text = '''
he PRP B-NP
accepted VBD B-VP
the DT B-NP
position NN I-NP
'''
print("字符串转块树",nltk.chunk.conllstr2tree(text))

#使用nltkCoNLL2000语料库中的句子
print("句子的树结构:")
print(conll.chunked_sents()[99])
print("只保存句子的NP块")
print(conll.chunked_sents('train.txt',chunk_types=['NP'])[99])
运行结果

简单评估和基准

使用

from nltk.corpus import conll2000
import nltk

cp = nltk.RegexpParser("")
test_sents = conll2000.chunked_sents('test.txt',chunk_types=['NP'])
print(cp.evaluate(test_sents))

#尝试一个初级的正则表达式分类器
#正则表达式将词性是以C,D,J,N,P开头的块都识别为NP块
grammar = r"NP:{<[CDJNP].*>+}"
cp = nltk.RegexpParser(grammar)
print(cp.evaluate(test_sents))

相关文章

网友评论

      本文标题:开发和评估分块器

      本文链接:https://www.haomeiwen.com/subject/rglhkctx.html