Update chat.py
Browse files
chat.py
CHANGED
|
@@ -26,11 +26,29 @@ model = NeuralNet(input_size, hidden_size, output_size).to(device)
|
|
| 26 |
model.load_state_dict(model_state)
|
| 27 |
model.eval()
|
| 28 |
|
| 29 |
-
bot_name = "
|
| 30 |
# print(
|
| 31 |
# "Hello, I am B-BOT, personal ChatBOT of Mr. Bibek. Let's chat! (type 'quit' or 'q' to exit)" # NoQA
|
| 32 |
# )
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
def generate_response(sentence):
|
| 36 |
# sentence = input("You: ")
|
|
@@ -52,8 +70,7 @@ def generate_response(sentence):
|
|
| 52 |
|
| 53 |
probs = torch.softmax(output, dim=1)
|
| 54 |
prob = probs[0][predicted.item()]
|
| 55 |
-
|
| 56 |
-
if prob.item() > 0.95:
|
| 57 |
for intent in intents["intents"]:
|
| 58 |
if tag == intent["tag"]:
|
| 59 |
return f"{bot_name}: {random.choice(intent['responses'])}"
|
|
|
|
| 26 |
model.load_state_dict(model_state)
|
| 27 |
model.eval()
|
| 28 |
|
| 29 |
+
bot_name = "BGPT"
|
| 30 |
# print(
|
| 31 |
# "Hello, I am B-BOT, personal ChatBOT of Mr. Bibek. Let's chat! (type 'quit' or 'q' to exit)" # NoQA
|
| 32 |
# )
|
| 33 |
|
| 34 |
+
def generate_tag(sentence):
|
| 35 |
+
# sentence = input("You: ")
|
| 36 |
+
sentence = correct_typos(sentence)
|
| 37 |
+
# print(sentence)
|
| 38 |
+
if sentence.lower() == "quit" or sentence.lower() == "q":
|
| 39 |
+
# Needs to quit
|
| 40 |
+
pass
|
| 41 |
+
|
| 42 |
+
sentence = tokenize(sentence)
|
| 43 |
+
X = bag_of_words(sentence, all_words)
|
| 44 |
+
X = X.reshape(1, X.shape[0])
|
| 45 |
+
X = torch.from_numpy(X).to(device)
|
| 46 |
+
|
| 47 |
+
output = model(X)
|
| 48 |
+
_, predicted = torch.max(output, dim=1)
|
| 49 |
+
|
| 50 |
+
tag = tags[predicted.item()]
|
| 51 |
+
return tag
|
| 52 |
|
| 53 |
def generate_response(sentence):
|
| 54 |
# sentence = input("You: ")
|
|
|
|
| 70 |
|
| 71 |
probs = torch.softmax(output, dim=1)
|
| 72 |
prob = probs[0][predicted.item()]
|
| 73 |
+
if prob.item() > 0.8:
|
|
|
|
| 74 |
for intent in intents["intents"]:
|
| 75 |
if tag == intent["tag"]:
|
| 76 |
return f"{bot_name}: {random.choice(intent['responses'])}"
|