Comments (2)
Hi Alessandro, generation for this type of model has to occur one character at a time, because each character is chosen based on all of the previous characters. You can disable beam search by typing "--beam_width 1" during chat, which will make generation faster (and much worse), but it will still choose one character at a time.
from chatbot-rnn.
@geroale just wanted to share something similar I wanted and how I did it, although it does not return the output instantly, it does return it as a whole (sentence) at once. Usefull for creating APIs or integrating the output in your own code
def chatbot(net, sess, chars, vocab, max_length, beam_width, relevance, temperature, topn, input_text):
states = initial_state_with_relevance_masking(net, sess, relevance)
while True:
#user_input = input('\n> ')
user_input = input_text
start_time = time.time()
user_command_entered, reset, states, relevance, temperature, topn, beam_width = process_user_command(
user_input, states, relevance, temperature, topn, beam_width)
if reset: states = initial_state_with_relevance_masking(net, sess, relevance)
if not user_command_entered:
beam_width = 1
states = forward_text(net, sess, states, relevance, vocab, sanitize_text(vocab, "> " + user_input + "\n>"))
computer_response_generator = beam_search_generator(sess=sess, net=net,
initial_state=copy.deepcopy(states), initial_sample=vocab[' '],
early_term_token=vocab['\n'], beam_width=beam_width, forward_model_fn=forward_with_mask,
forward_args={'relevance':relevance, 'mask_reset_token':vocab['\n'], 'forbidden_token':vocab['>'],
'temperature':temperature, 'topn':topn})
#print(chars)
out_chars = []
out = []
for i, char_token in enumerate(computer_response_generator):
out_chars.append(chars[char_token])
out.append(possibly_escaped_char(out_chars))
#print(possibly_escaped_char(out_chars), end='', flush=True)
states = forward_text(net, sess, states, relevance, vocab, chars[char_token])
if i >= max_length: break
#print("".join(out))
#print("--- %s seconds ---" % (time.time() - start_time))
return "".join(out)
states = forward_text(net, sess, states, relevance, vocab, sanitize_text(vocab, "\n> "))
You just store the characters in var[] and once the loop ends, you join them in a single statement.
PS: My code modification is to return the output, if you want to just print it, comment return line and uncomment print.
from chatbot-rnn.
Related Issues (20)
- Speed up inference HOT 1
- reddit_parse error HOT 1
- Using this bot on discord HOT 2
- Training on GPU? HOT 4
- Unable to run chatbot.py. Throwing error on tensorflow HOT 13
- Link to your pre trained not reachable HOT 3
- Unable to run chatbot.py.Getting an error
- Using the Pre-Trained Model for Regression
- Weird Unreadable Response HOT 2
- Error with reddit-parser HOT 123
- Issue with train.py - error loading data
- Question: HOT 1
- Even the checkpont file is in the correct directory it is not identifying it HOT 5
- Chatbot output russian chars issue HOT 1
- question chatbot HOT 2
- no module named tensorflow.contrib HOT 7
- requirements.txt HOT 1
- Parse Reddit Corpus in zip format
- Parse Reddit Corpus in zip format
- Can I delete old ckpt files when training?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chatbot-rnn.