使用 spaCy 进行词义消歧
WSD(词义消歧)是一个经典问题,用于判断一个词在句子中的具体含义。在搜索引擎、机器翻译和问答系统中,正确确定词义非常关键。在本练习中,您将练习使用词性标注(POS tagging)来进行词义消歧。
这里有两个包含单词 jam 的句子,但其含义不同。您的任务是找出能帮助确定该词在给定句子中含义的词性标注。
两个句子已在 texts 列表中提供。en_core_web_sm 模型已加载为 nlp 可直接使用。
本练习是课程的一部分
使用 spaCy 的自然语言处理
交互式实操练习
通过完成这段示例代码来试试这个练习。
texts = ["This device is used to jam the signal.",
"I am stuck in a traffic jam"]
# Create a list of Doc containers in the texts list
documents = [____ for t in texts]
# Print a token's text and POS tag if the word jam is in the token's text
for i, doc in enumerate(documents):
print(f"Sentence {i+1}: ", [(____, ____) for token in doc if "jam" in token.text], "\n")