Skip to content

Instantly share code, notes, and snippets.

@fsndzomga
Created September 7, 2023 22:59
Show Gist options
  • Save fsndzomga/9d5f36dad94ded3eccda752a0132af2c to your computer and use it in GitHub Desktop.
Save fsndzomga/9d5f36dad94ded3eccda752a0132af2c to your computer and use it in GitHub Desktop.
n grams
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