snakeztc / NeuralDialog-LAED

PyTorch implementation for Interpretable Dialog Generation ACL 2018, It is released by Tiancheng Zhao (Tony) from Dialog Research Center, LTI, CMU
http://www.cs.cmu.edu/~tianchez/
Apache License 2.0
198 stars 40 forks source link

code not working on python 3.5 TypeError: a bytes-like object is required, not 'str' #3

Open gwen10nnyson opened 5 years ago

gwen10nnyson commented 5 years ago

Traceback (most recent call last): File "ptb-utt.py", line 155, in main(config) File "ptb-utt.py", line 97, in main prepare_dirs_loggers(config, os.path.basename(file)) File "C:\Users\hw\NeuralDialog-LAED-master\laed\utils.py", line 105, in prepare_dirs_loggers json.dump(config.dict, fp, indent=4, sort_keys=True) File "C:\Users\hw\Anaconda3\envs\py35\lib\json__init__.py", line 179, in dump fp.write(chunk) TypeError: a bytes-like object is required, not 'str'

snakeztc commented 5 years ago

The code is written in Python 2.7. Thanks!

gwen10nnyson commented 5 years ago

Yes, I understand. but is there any way it can work on python 3.5? because I am using windows and tensorflow is not supported on python 2.7

hannamw commented 4 years ago

For future reference, this model is largely compatible with python 3. You just have to change all of the calls to open(...,'wb') to open(...,'w'), as you are not writing bytes to the files. Alternatively, encode strings as bytes before writing them.

Also, as the MosesTokenizer is no longer included in nltk, you should separately install the sacremoses package, which is the same.