tensorlayer / seq2seq-chatbot

Chatbot in 200 lines of code using TensorLayer
https://github.com/tensorlayer/tensorlayer
835 stars 314 forks source link

I am new in python please provide me a code for using the chatbot I finish the training and I want to use it in discord how to use the training model? #46

Open bag7dad opened 4 years ago

bag7dad commented 4 years ago

I don't need discord bot code I just want the method for using Your script I have knowledge in other languages programing

carlitoselmago commented 3 years ago

@medozeus here's a code you can addapt, mine is a simple terminal chatbot interface

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
from main import * # import the main python file with model from the example
import time

load_weights = tl.files.load_npz(name='saved/model.npz')
tl.files.assign_weights(load_weights, model_)

def respond(input):
    sentence = inference(input, 3)
    response=' '.join(sentence)
    return response

while True:
    userInput=input("user# ")
    time.sleep(0.5)
    print("bot# ",respond(userInput))
Radioactivebun0 commented 3 years ago

@carlitoselmago I copied and pasted your code into a file named "chatbot.py" with model.npz in a folder named "saved". chatbot.py and "main.py" are in the same folder. When I run your code, I get this error:

C:\Users\tjpet\Downloads\seq2seq-chatbot-master\seq2seq-chatbot-master>py chatbot.py
Traceback (most recent call last):
  File "chatbot.py", line 8, in <module>
    tl.files.assign_weights(load_weights, model_)
NameError: name 'model_' is not defined
carlitoselmago commented 3 years ago

@Radioactivebun0 that because there's some problem importing main.py file. try to add an empty file called

__init__.py

in the folder where both main.py and chatbot.py are located.

jessedoka commented 3 years ago

@carlitoselmago I ran into the same error and I have created a __init__.py but I am still falling into this error.

jessedoka commented 3 years ago

I figured it out! I figured was that model_ and inference() is defined in main.py, but that only when __name__ == "__main__" so it did not exist when I ran my file e.g chatbot.py so I took the following outside the if __name__ == "__main__": ; data pre-processing, parameters, and other variables including the inference function. I am not sure if this harms any of the code in main.py though.