Skip to content

Commit

Permalink
Added ability to pass checkpoint name as a parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-kukiela committed Mar 26, 2018
1 parent 612f197 commit 3216538
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,21 @@ utils/pairing_testing_outputs.py - joins model/output_dev file with data/tst2012
Inference
-------------

Whenever a model is trained, inference.py, when directly called, allows to "talk to" AI in interactive mode. It will start and setup everything needed to use trained model (using saved hparams file within the model folder and setup/settings.py for the rest of settings or lack of hparams file).
Whenever a model is trained, `inference.py`, when directly called, allows to "talk to" AI in interactive mode. It will start and setup everything needed to use trained model (using saved hparams file within the model folder and setup/settings.py for the rest of settings or lack of hparams file).

For every question will be printed up to a number of responses set in setup/settings.py. Every response will be marked with one of three colors:

- green - first one with that color is a candidate to be returned. Answers to the color passed blacklist check (setup/response_blacklist.txt)
- orange - still proper responses, but doesn't pass check against the blacklist
- red - improper response - includes `<unk>`
- orange - still proper responses, but with lower than maximum score
- red - improper response - below threshold

Steps from the question to the answers:

1. Pass question
2. Compute up to number of responses set in setup/settings.py
3. Detokenize answers using rules from setup/answers_detokenized.txt
3. Replace responses or their parts using rules from setup/answers_replace.txt
4. Score responses with -1 (includes `<unk>`, 0 (matches against at least one rule in setup/answers_blacklist.txt file) or 1 (passes all checks)
3. Detokenize answers using either embedded detokenizer or rules from setup/answers_detokenized.txt (depending on settings)
3. Replace responses or their parts using additional rules
4. Score responses
5. Return (show with interactive mode) responses

It is also possible to process a batch of the questions by simply using command redirection:
Expand All @@ -166,6 +166,11 @@ or:

python inference.py < input_file > output_file

It is possible to pass specified checkpoint as a parameter to use inference using that checkpoint, for example:

python inference.py translate.ckpt-1000


Importing nmt-chatbot
-------------

Expand Down Expand Up @@ -209,7 +214,9 @@ Changelog
- Fixed info about importing project as a module
- Updated README
- Added changelog
- various fixes and other small improvements
- Added table of contents
- Added passing checkpoint name as a parameter for inference
- Various fixes and other small improvements

### v0.2
- BPE/WPM-like tokenizer
Expand All @@ -218,7 +225,7 @@ Changelog
- Fixed issue with paths on Linux and MacOS machines
- Improved pair testing utility
- Fixed command for tag cloning
- various fixes and other small improvements, improved readme file
- Various fixes and other small improvements, improved readme file

### v0.1
- Initial commit, code for tutorial: https://pythonprogramming.net/chatbot-deep-learning-python-tensorflow/
Expand Down
8 changes: 7 additions & 1 deletion inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,14 @@ def process_questions(questions, return_score_modifiers = False):
sys.exit()

# Interactive mode
print("\n\nStarting interactive mode (first response will take a while):")
colorama.init()
print("\n\nStarting interactive mode (first response will take a while):")

# Specified model
if len(sys.argv) >= 2 and sys.argv[1]:
checkpoint = hparams['out_dir'] + str(sys.argv[1])
hparams['ckpt'] = checkpoint
print("Using checkpoint: {}".format(checkpoint))

# QAs
while True:
Expand Down

0 comments on commit 3216538

Please sign in to comment.