import numpy as np
import pandas as pd
import tensorflow as tf
import keras
docs= """India's 2011 Cricket World Cup journey:
India's journey to winning the 2011 Cricket World Cup was filled with both triumphs
and challenges, making their victory all the more significant.
The tournament, co-hosted by India, Sri Lanka, and Bangladesh, took place from
February 19 to April 2, 2011.
India began their campaign with a convincing win against Bangladesh, setting the tone
with a massive 87-run victory.
Virender Sehwag's explosive 175 and Virat Kohli's century (100*) ensured India posted
a daunting total of 370/4.
Despite this strong start, India faced tough situations as the tournament progressed.
In their group stage match against England, India set a challenging target of 339
runs, with Sachin Tendulkar scoring 120.
However, England fought back valiantly, led by Andrew Strauss’s 158, and the match
ended in a thrilling tie, with both teams scoring 338 runs.
This result highlighted India's vulnerabilities in bowling under pressure, as they
failed to defend a large total.
India's only loss in the group stage came against South Africa in a closely contested
match.
India batted first and looked set for a massive score, with Tendulkar scoring another
century (111) and India reaching 267/1.
However, a dramatic collapse saw India lose 9 wickets for just 29 runs, being bowled
out for 296.
South Africa chased down the target with 2 balls to spare, winning by 3 wickets in a
nail-biting finish.
This defeat exposed India's middle-order fragility and raised questions about their
ability to handle pressure in crucial moments.
Despite these setbacks, India finished second in Group B, with 4 wins, 1 tie, and 1
loss, advancing to the knockout stages with a net run rate of +0.900.
In the quarterfinals, India faced a formidable challenge against Australia, the
three-time defending champions.
Australia batted first and posted a competitive total of 260/6, with Ricky Ponting
scoring a resilient century (104).
India’s chase was not without challenges, as they lost key wickets at crucial
junctures, but Yuvraj Singh's unbeaten 57 and Suresh Raina's 34* guided them to a 5-
wicket victory with 14 balls remaining.
This win was significant as it ended Australia’s 12-year dominance in World Cups and
boosted India's confidence going into the semifinals.
The semifinal against Pakistan was arguably one of the most intense matches of the
tournament.
India batted first and scored 260/9, with Sachin Tendulkar top-scoring with 85,
albeit benefiting from several dropped catches.
Pakistan, known for their unpredictable nature, kept the chase alive, but India’s
bowlers held their nerve, with Zaheer Khan and Harbhajan Singh taking crucial
wickets.
India won by 29 runs, securing a place in the final, but not without surviving some
anxious moments, particularly when the Pakistani batsmen looked set to take the game
away.
The final against Sri Lanka presented another tough situation for India, as they were
set a challenging target of 275 runs after Sri Lanka scored 274/6, thanks to Mahela
Jayawardene's unbeaten 103.
India's chase began poorly, losing Virender Sehwag for a duck and Sachin Tendulkar
for just 18, leaving them at a precarious 31/2.
At this critical juncture, Gautam Gambhir played a vital innings, scoring 97 runs,
and formed crucial partnerships with Virat Kohli (35) and MS Dhoni.
Dhoni’s decision to promote himself ahead of the in-form Yuvraj Singh was a bold
move, especially given the pressure of the situation.
Dhoni justified his decision with a match-winning unbeaten 91 off 79 balls, guiding
India to victory with 10 balls to spare.
He sealed the win with an iconic six, a moment that has since become etched in
cricketing history.
India won the final by 6 wickets, clinching their second World Cup title after 28
years.
This victory was a testament to India’s resilience, overcoming tough situations and
bouncing back from setbacks throughout the tournament.
Yuvraj Singh was named the Player of the Tournament for his exceptional all-round
performance, scoring 362 runs and taking 15 wickets, often delivering under pressure.
Sachin Tendulkar, who finished the tournament as India’s highest run-scorer with 482
runs at an average of 53.55, finally realized his dream of winning a World Cup in
what was his sixth appearance in the tournament.
Zaheer Khan was India’s leading wicket-taker, with 21 wickets at an average of 18.76,
playing a crucial role in many of India’s victories.
The 2011 World Cup victory is remembered not just for the triumph but for the tough
situations India navigated along the way, showcasing their grit, determination, and
ability to rise to the occasion when it mattered the most.
This win united a nation, with millions celebrating across the country, and it
solidified the legacy of a team that overcame challenges to achieve glory on the
world stage."""
from tensorflow.keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
tokenizer=Tokenizer()
tokenizer.fit_on_texts([docs]) #Now it Considers the docs as list of a string, So,it
will tokenize by words rather than by letters.
#tokenizer.word_index
len(tokenizer.word_index)
386
# We want list of list containg sentences.
for sentence in docs.split('\n'):
print(tokenizer.texts_to_sequences([sentence])) # The sentence is given to
tokenize them by words rather than letters.
for sentence in docs.split('\n'):
tokenized_sequence=tokenizer.texts_to_sequences([sentence])[0]
for i in range(1,len(tokenized_sequence)):
print(tokenized_sequence[:i+1])
input_sequences=[]
for sentence in docs.split('\n'):
tokenized_sequence=tokenizer.texts_to_sequences([sentence])[0]
for i in range(1,len(tokenized_sequence)):
input_sequences.append(tokenized_sequence[:i+1])
input_sequences
array([[ 0, 0, 0, ..., 0, 0, 13],
[ 0, 0, 0, ..., 0, 13, 28],
[ 0, 0, 0, ..., 13, 28, 65],
...,
[ 0, 0, 0, ..., 384, 385, 386],
[ 0, 0, 0, ..., 385, 386, 1],
[ 0, 0, 0, ..., 386, 1, 14]])
len(tokenizer.word_index)
386
max_len = max([len(x) for x in input_sequences]) # To find the length of Longest
sentence
max_len
38
# Applying Padding for Equal Length of the Inputs.
from keras.preprocessing.sequence import pad_sequences
padded_sequences=pad_sequences(input_sequences,maxlen=max_len,padding='pre')
padded_sequences[0]
array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 13, 28])
# Now Slicing the Last token as Output,Which the model will try to Predict.
input_sequences=padded_sequences[:,:-1]
input_sequences[0]
array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 13])
output_sequences=padded_sequences[:,-1]
output_sequences[0]
28
# So, We have Both Inputs and Outputs For Our Model.
# Our Last Layer should be as long as the # of Tokens, We can have softmax as
activation function for output layer.
# So,One-Hot Encoding the outputs using to_categorical
from keras.utils import to_categorical
output_sequences=to_categorical(output_sequences,num_classes=387) # 386 -> no. of
tokens and 1 is added bcz the first token is assigned 1 rather than 0.
output_sequences[0]
array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
Model Architecture
input_sequences.shape
(760, 37)
len(tokenizer.word_index)
386
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Embedding,Dense,LSTM
model=Sequential()
model.add(Embedding(387,100,input_length=37)) # Now Every Token/word is represented
using 100 dimensional Vector.
model.add(LSTM(150,dropout=0.2,return_sequences=True))
model.add(LSTM(150,dropout=0.2))
model.add(Dense(387,activation='softmax'))
model.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['accuracy'])
model.fit(input_sequences,output_sequences,epochs=100)
Epoch 1/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 107ms/step - accuracy: 0.0467 - loss: 5.2041
Epoch 2/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 110ms/step - accuracy: 0.0486 - loss: 5.1637
Epoch 3/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 112ms/step - accuracy: 0.0482 - loss: 5.0215
Epoch 4/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 113ms/step - accuracy: 0.0498 - loss: 4.9524
Epoch 5/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 6s 152ms/step - accuracy: 0.0478 - loss: 4.8966
Epoch 6/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 117ms/step - accuracy: 0.0658 - loss: 4.7581
Epoch 7/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 115ms/step - accuracy: 0.0500 - loss: 4.7360
Epoch 8/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 116ms/step - accuracy: 0.0424 - loss: 4.6662
Epoch 9/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 112ms/step - accuracy: 0.0795 - loss: 4.5918
Epoch 10/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 109ms/step - accuracy: 0.0707 - loss: 4.5047
Epoch 11/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 6s 130ms/step - accuracy: 0.0734 - loss: 4.4317
Epoch 12/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 123ms/step - accuracy: 0.0788 - loss: 4.3380
Epoch 13/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 112ms/step - accuracy: 0.0929 - loss: 4.2255
Epoch 14/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 111ms/step - accuracy: 0.0902 - loss: 4.1653
Epoch 15/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 111ms/step - accuracy: 0.0989 - loss: 4.0345
Epoch 16/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 111ms/step - accuracy: 0.1215 - loss: 3.8464
Epoch 17/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 117ms/step - accuracy: 0.1468 - loss: 3.7341
Epoch 18/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 118ms/step - accuracy: 0.1667 - loss: 3.6708
Epoch 19/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 117ms/step - accuracy: 0.1591 - loss: 3.6114
Epoch 20/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 114ms/step - accuracy: 0.1918 - loss: 3.4618
Epoch 21/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 6s 135ms/step - accuracy: 0.2297 - loss: 3.2933
Epoch 22/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 115ms/step - accuracy: 0.2539 - loss: 3.2124
Epoch 23/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 114ms/step - accuracy: 0.2846 - loss: 3.1526
Epoch 24/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 114ms/step - accuracy: 0.2952 - loss: 3.1016
Epoch 25/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 118ms/step - accuracy: 0.3144 - loss: 2.9603
Epoch 26/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 114ms/step - accuracy: 0.3200 - loss: 2.8818
Epoch 27/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 114ms/step - accuracy: 0.3704 - loss: 2.8184
Epoch 28/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 115ms/step - accuracy: 0.4461 - loss: 2.6223
Epoch 29/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 115ms/step - accuracy: 0.4087 - loss: 2.6326
Epoch 30/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 110ms/step - accuracy: 0.4863 - loss: 2.4955
Epoch 31/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 118ms/step - accuracy: 0.4901 - loss: 2.4477
Epoch 32/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 112ms/step - accuracy: 0.5272 - loss: 2.3862
Epoch 33/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 121ms/step - accuracy: 0.5810 - loss: 2.2915
Epoch 34/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 141ms/step - accuracy: 0.5854 - loss: 2.2165
Epoch 35/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 117ms/step - accuracy: 0.6318 - loss: 2.0953
Epoch 36/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 119ms/step - accuracy: 0.6355 - loss: 2.0190
Epoch 37/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 114ms/step - accuracy: 0.6594 - loss: 1.9062
Epoch 38/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 135ms/step - accuracy: 0.6780 - loss: 1.8419
Epoch 39/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 120ms/step - accuracy: 0.7028 - loss: 1.8177
Epoch 40/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 112ms/step - accuracy: 0.7148 - loss: 1.7246
Epoch 41/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 6s 128ms/step - accuracy: 0.7234 - loss: 1.7103
Epoch 42/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 119ms/step - accuracy: 0.7739 - loss: 1.6100
Epoch 43/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 114ms/step - accuracy: 0.7790 - loss: 1.5062
Epoch 44/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 115ms/step - accuracy: 0.7865 - loss: 1.4838
Epoch 45/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 117ms/step - accuracy: 0.8151 - loss: 1.3944
Epoch 46/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 116ms/step - accuracy: 0.8316 - loss: 1.3351
Epoch 47/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 113ms/step - accuracy: 0.8285 - loss: 1.3022
Epoch 48/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 119ms/step - accuracy: 0.8433 - loss: 1.2223
Epoch 49/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 122ms/step - accuracy: 0.8483 - loss: 1.2126
Epoch 50/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 124ms/step - accuracy: 0.8538 - loss: 1.1496
Epoch 51/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 119ms/step - accuracy: 0.8641 - loss: 1.0830
Epoch 52/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 114ms/step - accuracy: 0.8690 - loss: 1.0550
Epoch 53/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 6s 127ms/step - accuracy: 0.8697 - loss: 1.0099
Epoch 54/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 121ms/step - accuracy: 0.8809 - loss: 0.9462
Epoch 55/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 119ms/step - accuracy: 0.9025 - loss: 0.9287
Epoch 56/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 118ms/step - accuracy: 0.8981 - loss: 0.8799
Epoch 57/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 118ms/step - accuracy: 0.8982 - loss: 0.8459
Epoch 58/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 120ms/step - accuracy: 0.9060 - loss: 0.8507
Epoch 59/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 118ms/step - accuracy: 0.9124 - loss: 0.7963
Epoch 60/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 118ms/step - accuracy: 0.8971 - loss: 0.7749
Epoch 61/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 131ms/step - accuracy: 0.9112 - loss: 0.7488
Epoch 62/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 133ms/step - accuracy: 0.9429 - loss: 0.6629
Epoch 63/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 128ms/step - accuracy: 0.9220 - loss: 0.7036
Epoch 64/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 127ms/step - accuracy: 0.9157 - loss: 0.6714
Epoch 65/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 119ms/step - accuracy: 0.9341 - loss: 0.6274
Epoch 66/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 123ms/step - accuracy: 0.9411 - loss: 0.5932
Epoch 67/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 125ms/step - accuracy: 0.9364 - loss: 0.5761
Epoch 68/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 131ms/step - accuracy: 0.9534 - loss: 0.5370
Epoch 69/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 117ms/step - accuracy: 0.9475 - loss: 0.5516
Epoch 70/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 6s 140ms/step - accuracy: 0.9369 - loss: 0.5502
Epoch 71/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 119ms/step - accuracy: 0.9433 - loss: 0.5281
Epoch 72/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 126ms/step - accuracy: 0.9449 - loss: 0.4890
Epoch 73/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 128ms/step - accuracy: 0.9335 - loss: 0.4874
Epoch 74/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 122ms/step - accuracy: 0.9555 - loss: 0.4342
Epoch 75/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 124ms/step - accuracy: 0.9489 - loss: 0.4500
Epoch 76/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 123ms/step - accuracy: 0.9492 - loss: 0.4445
Epoch 77/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 122ms/step - accuracy: 0.9525 - loss: 0.4411
Epoch 78/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 129ms/step - accuracy: 0.9494 - loss: 0.4275
Epoch 79/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 126ms/step - accuracy: 0.9501 - loss: 0.4173
Epoch 80/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 122ms/step - accuracy: 0.9639 - loss: 0.3729
Epoch 81/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 130ms/step - accuracy: 0.9503 - loss: 0.3656
Epoch 82/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 123ms/step - accuracy: 0.9618 - loss: 0.3544
Epoch 83/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 6s 140ms/step - accuracy: 0.9625 - loss: 0.3492
Epoch 84/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 4s 162ms/step - accuracy: 0.9537 - loss: 0.3479
Epoch 85/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 4s 128ms/step - accuracy: 0.9631 - loss: 0.3211
Epoch 86/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 134ms/step - accuracy: 0.9698 - loss: 0.3169
Epoch 87/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 124ms/step - accuracy: 0.9631 - loss: 0.3159
Epoch 88/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 6s 136ms/step - accuracy: 0.9647 - loss: 0.2962
Epoch 89/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 136ms/step - accuracy: 0.9668 - loss: 0.2799
Epoch 90/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 132ms/step - accuracy: 0.9615 - loss: 0.2911
Epoch 91/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 133ms/step - accuracy: 0.9553 - loss: 0.2987
Epoch 92/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 127ms/step - accuracy: 0.9724 - loss: 0.2690
Epoch 93/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 123ms/step - accuracy: 0.9521 - loss: 0.2920
Epoch 94/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 6s 151ms/step - accuracy: 0.9616 - loss: 0.2638
Epoch 95/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 5s 128ms/step - accuracy: 0.9595 - loss: 0.2775
Epoch 96/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 136ms/step - accuracy: 0.9664 - loss: 0.2605
Epoch 97/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 144ms/step - accuracy: 0.9810 - loss: 0.2494
Epoch 98/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 6s 163ms/step - accuracy: 0.9713 - loss: 0.2409
Epoch 99/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 3s 105ms/step - accuracy: 0.9734 - loss: 0.2402
Epoch 100/100
24/24 ━━━━━━━━━━━━━━━━━━━━ 4s 183ms/step - accuracy: 0.9734 - loss: 0.2309
<keras.src.callbacks.history.History at 0x2edc1474a50>
# Creating a function to predict next 20 words.
def next_word(text):
for i in range(10):
# Tokenizing the text
sequence=tokenizer.texts_to_sequences([text])[0]
#padding the text now
padded_sequence=pad_sequences([sequence],maxlen=max_len,padding='pre')
# Predicting next word
pos=np.argmax(model.predict(padded_sequence))
print(pos) # It is token index of the next predicted word
for label,index in tokenizer.word_index.items():
if index==pos:
text=text+' '+label
print(text)
next_word("Dhoni’s decision to promote himself ahead ")
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 35ms/step
8
Dhoni’s decision to promote himself ahead of
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 31ms/step
1
Dhoni’s decision to promote himself ahead of the
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 38ms/step
7
Dhoni’s decision to promote himself ahead of the in
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 33ms/step
302
Dhoni’s decision to promote himself ahead of the in form
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 20ms/step
59
Dhoni’s decision to promote himself ahead of the in form yuvraj
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 50ms/step
62
Dhoni’s decision to promote himself ahead of the in form yuvraj singh
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 56ms/step
10
Dhoni’s decision to promote himself ahead of the in form yuvraj singh was
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 54ms/step
2
Dhoni’s decision to promote himself ahead of the in form yuvraj singh was a
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 29ms/step
303
Dhoni’s decision to promote himself ahead of the in form yuvraj singh was a bold
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 43ms/step
304
Dhoni’s decision to promote himself ahead of the in form yuvraj singh was a bold
move
next_word('India began their ')
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 48ms/step
130
India began their campaign
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 21ms/step
3
India began their campaign with
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 33ms/step
2
India began their campaign with a
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 30ms/step
131
India began their campaign with a convincing
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 18ms/step
30
India began their campaign with a convincing win
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 21ms/step
20
India began their campaign with a convincing win against
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 120ms/step
70
India began their campaign with a convincing win against bangladesh
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 46ms/step
132
India began their campaign with a convincing win against bangladesh setting
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 53ms/step
1
India began their campaign with a convincing win against bangladesh setting the
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 56ms/step
133
India began their campaign with a convincing win against bangladesh setting the tone
next_word('Pakistan, known for')
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 30ms/step
11
Pakistan, known for their
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 31ms/step
252
Pakistan, known for their unpredictable
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 39ms/step
253
Pakistan, known for their unpredictable nature
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 24ms/step
254
Pakistan, known for their unpredictable nature kept
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 30ms/step
1
Pakistan, known for their unpredictable nature kept the
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 18ms/step
57
Pakistan, known for their unpredictable nature kept the chase
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 65ms/step
255
Pakistan, known for their unpredictable nature kept the chase alive
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 35ms/step
37
Pakistan, known for their unpredictable nature kept the chase alive but
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 21ms/step
22
Pakistan, known for their unpredictable nature kept the chase alive but india’s
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 40ms/step
256
Pakistan, known for their unpredictable nature kept the chase alive but india’s
bowlers