Meh*_*pta 5 python nlp artificial-intelligence tokenize nltk
我无法理解两者之间的区别。不过,我开始知道 word_tokenize 使用 Penn-Treebank 进行标记化。但 TweetTokenizer 上没有任何内容可用。对于哪种数据,我应该使用 TweetTokenizer 而不是 word_tokenize?
Dar*_*ght 10
好吧,两个分词器的工作方式几乎相同,将给定的句子拆分为单词。但是您可以将其TweetTokenizer视为word_tokenize. TweetTokenizer保持主题标签完好无损word_tokenize。
我希望下面的例子能解决你所有的疑虑......
from nltk.tokenize import TweetTokenizer
from nltk.tokenize import word_tokenize
tt = TweetTokenizer()
tweet = "This is a cooool #dummysmiley: :-) :-P <3 and some arrows < > -> <-- @remy: This is waaaaayyyy too much for you!!!!!!"
print(tt.tokenize(tweet))
print(word_tokenize(tweet))
# output
# ['This', 'is', 'a', 'cooool', '#dummysmiley', ':', ':-)', ':-P', '<3', 'and', 'some', 'arrows', '<', '>', '->', '<--', '@remy', ':', 'This', 'is', 'waaaaayyyy', 'too', 'much', 'for', 'you', '!', '!', '!']
# ['This', 'is', 'a', 'cooool', '#', 'dummysmiley', ':', ':', '-', ')', ':', '-P', '<', '3', 'and', 'some', 'arrows', '<', '>', '-', '>', '<', '--', '@', 'remy', ':', 'This', 'is', 'waaaaayyyy', 'too', 'much', 'for', 'you', '!', '!', '!', '!', '!', '!']
Run Code Online (Sandbox Code Playgroud)
您可以看到它word_tokenize已拆分#dummysmiley为'#'and 'dummysmiley',而 TweetTokenizer 没有拆分为'#dummysmiley'。 TweetTokenizer主要用于分析推文。您可以从此链接了解有关分词器的更多信息
| 归档时间: |
|
| 查看次数: |
3826 次 |
| 最近记录: |