Use strings instead of floats or numbers as training data

Viewed 37

So I know I am doing this wrong because I'm using input and answers based on numbers so the AI is really unnecessary, so how can I change this? Can I use strings insead of floats or numbers as training data? What else can I change?

import numpy
from sklearn.metrics import r2_score
numpy.random.seed(2)


x = []
with open("x_data_chatbot.data", "r") as f:
    for byte in f:
        x.append(int(str(byte).strip()))

y = []
with open("y_data_chatbot.data", "r") as f:
    for byte in f:
        try: y.append(int(str(byte).strip()))
        except: y.append(float(str(byte).strip()))


print(x)
print(y)


train_x = x[:80]
train_y = y[:80]

test_x = x[80:]
test_y = y[80:]

mymodel = numpy.poly1d(numpy.polyfit(train_x, train_y, 4))

inputs = []
with open("input_data_chatbot.data", "r") as f:
    for inp in f:
        inputs.append(inp.strip())

answers = []
with open("answers_data_chatbot.data", "r") as f:
    for ans in f:
        answers.append(ans.strip())



inputstr = "bot" #str(input("response: "))

while inputstr != "exit":
    inputstr = input("> ")
    for index, item in enumerate(inputs):
        if inputs[index].__contains__(inputstr.lower()):
            index += 1
            #print(index)
            break
        else:
            index = -1
    
    try: print(answers[int(mymodel(index))])
    except: print(int(round(mymodel(index))))
    
    open("x_data_chatbot.data", "a").write(str(index) + "\n")
    open("y_data_chatbot.data", "a").write(str(mymodel(index)) + "\n")

The files are:

x_data_chatbot.data:

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

y_data_chatbot.data:

0
1
2
3
4
5
6
7
8
9
9
9
12
13
14
15
16
17
18
19
20

answers_data_chatbot.data:

lol
nu
no u
bro
lmao
da dog doing good      
nein
Dietz Nuts
yes
hello friend
sup dawg
dawg

input_data_chatbot.data:

lol
bot?
yo mom
bro
tf?
what da dog doin?
amg
dietz nuts
ma ta
mata
hello
hi
sup
man
bot
0 Answers
Related