Skip to content
Related Articles

Related Articles

Python NLTK | nltk.TweetTokenizer()

View Discussion
Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 12 May, 2022
View Discussion
Improve Article
Save Article

With the help of NLTK nltk.TweetTokenizer() method, we are able to convert the stream of words into small  tokens so that we can analyse the audio stream with the help of nltk.TweetTokenizer() method.

Syntax : nltk.TweetTokenizer() Return : Return the stream of token

Example #1 : In this example when we pass audio stream in the form of string it will converted to small tokens from a long string with the help of nltk.TweetTokenizer() method. 

Python3 1=1


# import TweetTokenizer() method from nltk
from nltk.tokenize import TweetTokenizer

# Create a reference variable for Class TweetTokenizer
tk = TweetTokenizer()

# Create a string input
gfg = "Geeks for Geeks"

# Use tokenize method
geek = tk.tokenize(gfg)

print(geek)

Output :

[‘Geeks’, ‘for’, ‘Geeks’]

Example #2 : 

Python3




# import TweetTokenizer() method from nltk
from nltk.tokenize import TweetTokenizer
 
# Create a reference variable for Class TweetTokenizer
tk = TweetTokenizer()
 
# Create a string input
gfg = ":-) <> () {} [] :-p"
 
# Use tokenize method
geek = tk.tokenize(gfg)
 
print(geek)

Output :

[‘:-)’, ”, ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘, ‘]’, ‘:-p’]

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!