File size: 2,379 Bytes
baa1558
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import sys
import json
import spacy
import pickle
import random
import tensorflow as tf
import tensorflow_hub as hub
import tensorflow_text as text
from sklearn.preprocessing import LabelBinarizer

def print_my_examples(inputs, results):
  result_for_printing = \
    [f'input: {inputs[i]:<30} : estimated intent: {results[i]}'
                         for i in range(len(inputs))]
  print(*result_for_printing, sep='\n')
  print()


examples = [
    'play a song from U2',  # this is the same sentence tried earlier
    'Will it rain tomorrow',
    'I like to hear greatist hits from beastie boys',
    'I like to book a table for 3 persons',
    '5 stars for machines like me',
    'play a boogie wit da hoodie',
    "play Bob's favorite song",
    "give me a hug",
    "hello"
]
greetings = ["Greeting","smalltalk_greetings_hello"]
courtesy_greeting = ["CourtesyGreeting"]
stored_name = "Amari"
examples = ["hello"]
#nlp = spacy.load("en_core_web_sm")
classifier_model = tf.keras.models.load_model('caesarmodel/caesarnl.h5',custom_objects={'KerasLayer':hub.KerasLayer})

# Show the model architecture
results = tf.nn.softmax(classifier_model(tf.constant(examples)))
with open("caesarmodel/labelbinarizer.pkl","rb") as f:
    binarizer = pickle.load(f)


intents=binarizer.inverse_transform(results.numpy())
with open("intentdata/responses.json","r") as f:
  responses = json.load(f)["responses"]

if intents[0] in greetings:
  greetresponse = random.choice(responses["Greeting"]).replace("<HUMAN>",stored_name)
  print(greetresponse)
  


#sentence_intents = dict(zip(examples,intents))
#print(sentence_intents)
#print_my_examples(examples, intents)

# TODO AIM - Implement Chatbot Gossip to Caesar
# 1. Add data to datasets train | valid | test 
#     a. then clean labels
# 2. Augment data to provide more potential possibilites
# 3. Use BERT to match input with the response
# Command Labels - AddToPlaylist | GetWeather -> API -> user
# Conversation Labes - Greeting | Goodbye  -> BERTNN: input:"hello" => response:"hi there, I am caesar" -> user

# TODO AIM - Single names of songs artists like "play a boogie" and it will play a boogie's music.
# 1. Idea one - NER detect the named entities
# 2. Create new Neural Network that detects that. * Have to determine the relationship between the entites