tekkonetes commited on
Commit
112363a
·
1 Parent(s): e323d40

Update Prediction

Browse files

Add a function to find the most common word instead of giving 'none'

Files changed (1) hide show
  1. predict.py +7 -2
predict.py CHANGED
@@ -4,11 +4,16 @@ import numpy as np
4
  import pickle
5
  nltk.download('punkt')
6
  # Define predict_word function
 
 
7
  def predict_word(model, last_word):
8
  if last_word in model:
9
- return np.random.choice(model[last_word])
 
 
 
10
  else:
11
- return None
12
  # Load the model
13
  with open("model.pkl", "rb") as f:
14
  model = pickle.load(f)
 
4
  import pickle
5
  nltk.download('punkt')
6
  # Define predict_word function
7
+ from collections import Counter
8
+
9
  def predict_word(model, last_word):
10
  if last_word in model:
11
+ next_words = model[last_word]
12
+ freq_dist = Counter(next_words)
13
+ most_common_word = freq_dist.most_common(1)[0][0]
14
+ return most_common_word
15
  else:
16
+ return ""
17
  # Load the model
18
  with open("model.pkl", "rb") as f:
19
  model = pickle.load(f)