Well, both tokenizers almost work the same way, to split a given sentence into words. But you can think of TweetTokenizer
as a subset of word_tokenize
. TweetTokenizer
keeps hashtags intact while word_tokenize
doesn't.
I hope the below example will clear all your doubts...
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', '!', '!', '!', '!', '!', '!']
You can see that word_tokenize
has split #dummysmiley
as '#'
and 'dummysmiley'
, while TweetTokenizer didn't, as '#dummysmiley'
. TweetTokenizer
is built mainly for analyzing tweets.
You can learn more about tokenizer from this link