Learn practical skills, build real-world projects, and advance your career
!pip install jovian --upgrade --quiet

N-Gram

!pip install nltk
Requirement already satisfied: nltk in /opt/conda/lib/python3.8/site-packages (3.5) Requirement already satisfied: regex in /opt/conda/lib/python3.8/site-packages (from nltk) (2020.11.13) Requirement already satisfied: tqdm in /opt/conda/lib/python3.8/site-packages (from nltk) (4.50.2) Requirement already satisfied: joblib in /opt/conda/lib/python3.8/site-packages (from nltk) (0.17.0) Requirement already satisfied: click in /opt/conda/lib/python3.8/site-packages (from nltk) (7.1.2)
from nltk import ngrams

sentence = "This is an example of N-Gram from NLTK package"
# denotes the number of the N value
N = 6
sixgrams = ngrams(sentence.split(), N)

for grams in sixgrams:
  print (grams)
('This', 'is', 'an', 'example', 'of', 'N-Gram') ('is', 'an', 'example', 'of', 'N-Gram', 'from') ('an', 'example', 'of', 'N-Gram', 'from', 'NLTK') ('example', 'of', 'N-Gram', 'from', 'NLTK', 'package')

BELU score