CRFSuite功能列表中的BOS和EOS是什么意思,作用是什么?

What's meaning of BOS and EOS in CRFSuite feature list and what is the role of them?

在 python-crf 包网站的 NER(命名实体识别)示例中,我们将此函数视为特征生成器:

def word2features(sent, i):
word = sent[i][0]
postag = sent[i][1]
features = [
    'bias',
    'word.lower=' + word.lower(),
    'word[-3:]=' + word[-3:],
    'word[-2:]=' + word[-2:],
    'word.isupper=%s' % word.isupper(),
    'word.istitle=%s' % word.istitle(),
    'word.isdigit=%s' % word.isdigit(),
    'postag=' + postag,
    'postag[:2]=' + postag[:2],
]
if i > 0:
    word1 = sent[i-1][0]
    postag1 = sent[i-1][1]
    features.extend([
        '-1:word.lower=' + word1.lower(),
        '-1:word.istitle=%s' % word1.istitle(),
        '-1:word.isupper=%s' % word1.isupper(),
        '-1:postag=' + postag1,
        '-1:postag[:2]=' + postag1[:2],
    ])
else:
    features.append('BOS')

if i < len(sent)-1:
    word1 = sent[i+1][0]
    postag1 = sent[i+1][1]
    features.extend([
        '+1:word.lower=' + word1.lower(),
        '+1:word.istitle=%s' % word1.istitle(),
        '+1:word.isupper=%s' % word1.isupper(),
        '+1:postag=' + postag1,
        '+1:postag[:2]=' + postag1[:2],
    ])
else:
    features.append('EOS')

return features

您可以在那里看到完整的教程: python-crfsuite NER example

正如您在添加有意义的特征后看到的那样 - 如 word.lower 和... - 已添加两个特征。

features.append('EOS')

features.append('BOS')

我的问题是"What's meaning of BOS and EOS and what is the role of them?"

这些代表 "Beginning of Sentence" 和 "End of Sentence"。它们用于代替没有 previous/next 个单词的 "previous word" 和 "next word" 特征。