项目作者: DongjunLee

项目描述 :
TensorFlow implementation of Conversation Models
高级语言: Python
项目地址: git://github.com/DongjunLee/conversation-tensorflow.git
创建时间: 2017-09-08T13:14:26Z
项目社区:https://github.com/DongjunLee/conversation-tensorflow

开源协议:

下载


A Neural Conversational Model hb-research

TensorFlow implementation of Conversation Models.

  1. Model

    • seq2seq_attention : Seq2Seq model with attentional decoder
  2. Dataset

Requirements

Project Structure

initiate Project by hb-base

  1. .
  2. ├── config # Config files (.yml, .json) using with hb-config
  3. ├── data/ # dataset path
  4. ├── scripts # download dataset using shell scripts
  5. ├── seq2seq_attention # seq2seq_attention architecture graphs (from input to logits)
  6. ├── __init__.py # Graph
  7. ├── encoder.py # Encoder
  8. ├── decoder.py # Decoder
  9. ├── data_loader.py # raw_date -> precossed_data -> generate_batch (using Dataset)
  10. ├── hook.py # training or test hook feature (eg. print_variables)
  11. ├── main.py # define experiment_fn
  12. └── model.py # define EstimatorSpec

Reference : hb-config, Dataset, experiments_fn, EstimatorSpec

Todo

Config

Can control all Experimental environment.

example: cornell-movie-dialogs.yml

  1. data:
  2. base_path: 'data/cornell_movie_dialogs_corpus/'
  3. conversation_fname: 'movie_conversations.txt'
  4. line_fname: 'movie_lines.txt'
  5. processed_path: 'processed_cornell_movie_dialogs_data'
  6. word_threshold: 2
  7. max_seq_length: 200
  8. sentence_diff: 0.33 # (Filtering with input and output sentence diff)
  9. testset_size: 25000
  10. PAD_ID: 0
  11. UNK_ID: 1
  12. START_ID: 2
  13. EOS_ID: 3
  14. model:
  15. batch_size: 32
  16. num_layers: 4
  17. num_units: 512
  18. embed_dim: 256
  19. embed_share: true # (true or false)
  20. cell_type: gru # (lstm, gru, layer_norm_lstm, nas)
  21. dropout: 0.2
  22. encoder_type: bi # (uni / bi)
  23. attention_mechanism: normed_bahdanau # (bahdanau, normed_bahdanau, luong, scaled_luong)
  24. train:
  25. learning_rate: 0.001
  26. sampling_probability: 0.25 # (Scheduled Sampling)
  27. train_steps: 100000
  28. model_dir: 'logs/cornell_movie_dialogs'
  29. save_checkpoints_steps: 1000
  30. loss_hook_n_iter: 1000
  31. check_hook_n_iter: 1000
  32. min_eval_frequency: 1000
  33. print_verbose: True
  34. debug: False
  35. predict:
  36. beam_width: 5 # (0: GreedyEmbeddingHelper, 1>=: BeamSearchDecoder)
  37. length_penalty_weight: 1.0
  38. slack:
  39. webhook_url: "" # after training notify you using slack-webhook

Usage

Install requirements.

pip install -r requirements.txt

First, check if the model is valid.

python main.py --config check_tiny --mode train

Then, download Cornell_Movie-Dialogs_Corpus and train it.

  1. sh scripts/prepare_Cornell_Movie-Dialogs_Corpus.sh
  2. python data_loader --config cornell-movie-dialogs # pre-processing data
  3. python main.py --config cornell-movie-dialogs --mode train_and_evaluate

Experiments modes

:white_check_mark: : Working
:white_medium_small_square: : Not tested yet.

  • :white_check_mark: evaluate : Evaluate on the evaluation data.
  • :white_medium_small_square: extend_train_hooks : Extends the hooks for training.
  • :white_medium_small_square: reset_export_strategies : Resets the export strategies with the new_export_strategies.
  • :white_medium_small_square: run_std_server : Starts a TensorFlow server and joins the serving thread.
  • :white_medium_small_square: test : Tests training, evaluating and exporting the estimator for a single step.
  • :white_check_mark: train : Fit the estimator using the training data.
  • :white_check_mark: train_and_evaluate : Interleaves training and evaluation.

After training, start chatting.

python chat.py --config cornell-movie-dialogs

Tensorboard

tensorboard --logdir logs

Conversation Example

> (Human)

  1. > hi.
  2. i ' m sorry . <\s>
  3. > why?
  4. i ' m not interested .
  5. > hmm.. are you human?
  6. nnnnn . <\s>
  7. > you are you?
  8. i ' m not going to marry you . <\s>
  9. > what? me also!
  10. i ' m sorry . <\s>
  11. > anyway, what is your name?
  12. i ' m not going to kill you . <\s>
  13. > i'm asking your name.
  14. i ' m sorry . <\s>
  15. > yeah, so.. where are you from?
  16. i ' m not sure . <\s>
  17. > Have you lost your memory?
  18. i ' m not sure i ' m not going to you . <\s>
  19. > Have you ever been to Florida?
  20. i ' m not sure i ' m not a little . <\s>
  21. > there there.
  22. no , no , no , no ,
  23. > Are you alright?
  24. i ' m not going to die . <\s>
  25. > alsoulutely, you are very healthy.
  26. i don ' t know . <\s>
  27. > you know that? you are robot.
  28. i ' m not sure . <\s>
  29. > i don ' t know what to say.
  30. i ' m not sure i ' m not a little stupid . <\s>
  31. > what do you like to do in your free time?
  32. i ' m not sure i ' m not gonna take you a little more . <\s>
  33. > are you in love?
  34. i ' m not sure i ' m not stupid . <\s>
  35. > i know.
  36. i ' m not going to let you
  37. > what's your name?
  38. i ' m not sure i ' m not a good guy . <\s>
  39. > oh god..
  40. i ' m not going to do that . <\s>
  41. > let's talk about something else.
  42. i ' m not sure . <\s>
  43. > i have to figure out what is the problem.
  44. i ' m not sure . <\s>
  45. > because of you are stupid.
  46. i ' m not going to get you . <\s>
  47. > florida?
  48. he is a homosexual - -
  49. > really?
  50. i ' m not sure i
  51. > can you tell me about more detail about him?
  52. i ' m not a cop . <\s>
  53. > okay.
  54. i ' m not going to
  55. > you always say 'i....'
  56. i ' m not sure i ' m not a murderer . <\s>
  57. > hmm.....
  58. i ' m not sure i ' m not a little popular . <\s>
  59. > you are not popular.
  60. i ' m not sure i ' m not a girl .
  61. > are you boy?
  62. i ' m not sure . <\s>
  63. > are you girl?
  64. i ' m not sure . <\s>
  65. > who are you?
  66. i ' m sorry . <\s>
  67. > i'm sorry.
  68. i ' m not crowding . <\s>
  69. > just kidding.
  70. i ' m going to be a writer
  71. > great!
  72. i don ' t know .
  73. > what do you mean?
  74. i ' m sorry , i ' m sorry . <\s>
  75. > omg
  76. no . <\s>
  77. > florida.
  78. he hasn ' t got any
  79. > music is my life.
  80. you ' re a fool , you ' re a man !
  81. > wow!
  82. i ' m not kidding .
  83. > sorry.
  84. i ' m not kidding .
  85. > yeah, i know it.
  86. i ' m not sure . <\s>
  87. > california?
  88. what ? <\s>
  89. > haha.
  90. it ' s a real competition

Reference

Author

Dongjun Lee (humanbrain.djlee@gmail.com)

Contributors