Articles → NLP → Bigram, Trigram, And Ngram In NLP

Bigram, Trigram, And Ngram In NLP






What Is A Bigram?




from nltk import bigrams

sentence = ["I", "love", "NLP"]
bi_grams = list(bigrams(sentence))
print(bi_grams)




Picture showing the output of bigram in nlp



What Is A Trigram?




from nltk import trigrams

sentence = ["I", "love", "natural", "language", "processing"]
tri_grams = list(trigrams(sentence))
print(tri_grams)




Picture showing the output of trigram in nlp



N-Gram




from nltk import ngrams

sentence = ["I", "love", "natural", "language", "processing"]
n = 4  # Change n to generate different n-grams
n_grams = list(ngrams(sentence, n))
print(n_grams)




Picture showing the output of n-gram in nlp



Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, August 20, 2025

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250