>> from nltk import word_tokenize >>> sen-6ren">
gpt4 book ai didi

python - nltk:word_tokenize 更改引号

转载 作者:太空宇宙 更新时间:2023-11-04 03:31:10 24 4
gpt4 key购买 nike

我正在使用 Python 的 nltk,我想标记一个包含引号的句子,但它将 " 变成了 ``'' .

例如:

>>> from nltk import word_tokenize

>>> sentence = 'He said "hey Bill!"'
>>> word_tokenize(sentence)
['He', 'said', '``', 'hey', 'Bill', '!', "''"]

为什么不保留原句中的引号,如何解决?

谢谢

最佳答案

它实际上是为了这样做,而不是偶然的。来自 Penn Treebank Tokenization

double quotes (") are changed to doubled single forward- and backward- quotes (`` and '')

在以前的版本中没有这样做,但是去年更新了。换句话说,如果你想改变你需要编辑 treebank.py

关于python - nltk:word_tokenize 更改引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31074682/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com