Created
September 7, 2023 22:59
-
-
Save fsndzomga/9d5f36dad94ded3eccda752a0132af2c to your computer and use it in GitHub Desktop.
n grams
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from nltk.util import ngrams | |
from nltk.tokenize import word_tokenize | |
sentence = "I love coding and learning" | |
tokenized_sentence = word_tokenize(sentence) | |
bigrams = list(ngrams(tokenized_sentence, 2)) | |
print(bigrams) | |
# Output: [('I', 'love'), ('love', 'coding'), ('coding', 'and'), ('and', 'learning')] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment