Facebook-Messenger-Bot icon indicating copy to clipboard operation
Facebook-Messenger-Bot copied to clipboard

Port code to python 3

Open TotallyNotChase opened this issue 5 years ago • 9 comments

Python 2 has reached EOL and it's time for this repo to upgrade. I've been working on a basic port for awhile and I'd like to detail my approach-

General

  • encoding='utf-8' will be included as an extra parameter in all open(....) commands
  • print 'string' will be changed to print('string')
  • raw_input (s) will be changed to input()
  • dict.iterItems() will be changed to dict.items()

Tensorflow

We will be using tensorflow 2.1.0, please note there has been drastic changes in this version compared to the one we are using. I'm only focusing on replacing the old commands with their alternatives. The new tensorflow probably offers many improved features and it might even have different behaviours for the existing commands, which I'll not be focusing on.

  • tf.Session() will be replaced with tf.compat.v1.Session()
  • Going to use tf.compat.v1.disable_eager_execution(), without this we cannot use placeholder()
  • tf.random_uniform() will be replaced with tf.random.uniform()
  • tf.truncated_normal() will be replaced with tf.random.truncated_normal()
  • tf.placeholder() will be replaced with tf.compat.v1.placeholder
  • tf.train.GradientDescentOptimizer() will be replaced with tf.compat.v1.train.GradientDescentOptimizer()
  • tf.global_variables_initializer() will be replaced with tf.compat.v1.global_variables_initializer()

*more changes soon

As of now, createDataset.py and Word2Vec.py are completely overhauled with python 3, I am currently working on porting Seq2Seq.py and will be posting my progress and/or hurdles here. Please be on a lookout for that!

TotallyNotChase avatar Jan 31 '20 16:01 TotallyNotChase

@adeshpande3 let me know what you think of these changes, and also if you'd like me to know anything while porting.

TotallyNotChase avatar Jan 31 '20 16:01 TotallyNotChase

Yeah this sounds fantastic to me, appreciate it! Lmk if I can be helpful

adeshpande3 avatar Feb 03 '20 03:02 adeshpande3

@adeshpande3 Everything except tf.contrib.legacy_seq2seq has an alternative in tensorflow 2.1.0. This blocks me from upgrading Seq2Seq.py to python 3. I'm not really experienced enough to come up with an alternative to that, could you look into that a bit? All the changes are live in the branch python3-upgrade, you can experiment in there. Also keep in mind the new codebase must use python3 64 bit. I personally used 3.7 64 bit

TotallyNotChase avatar Feb 03 '20 05:02 TotallyNotChase

Ahhh gotcha interesting, don't have as much bandwidth rn but will take a look over the weekend. I have no doubt there is an alternative but it'll probably require a bit of a refactor.

adeshpande3 avatar Feb 05 '20 14:02 adeshpande3

@adeshpande3 any updates on legacy_seq2seq?

TotallyNotChase avatar Feb 11 '20 05:02 TotallyNotChase

Hey, unfortunately I was only able to take a cursory look. Unfortunately this stemmed from me making the choice back then to use a tf.contrib.legacy function which as the name implied was likely not going to be supported for long.

Will try to take another look this weekend, but think it might be slightly costly to rearchitect and ramp back up on to find a solution. I'm open to finding other folks to help maintain this though (since I know I haven't had as much free time). Is there a way to make this a formal Issue and see if folks can contribute?

adeshpande3 avatar Feb 14 '20 04:02 adeshpande3

@adeshpande3 I think that's our only choice. I'd appreciate it if you could make an issue describing some primary things-

  • Exactly what the function currently does
  • What we expect a refactor to also achieve
  • A preferred solution path if you have one

Also some guidelines when someone does take it on -

  • Test and Work on the python3-upgrade branch
  • Code should be for python3 (preferably 64 bit for cross platform compatibility?)

The reason I'd like you to do this is because you've a better understanding of this function than I do haha

TotallyNotChase avatar Feb 14 '20 06:02 TotallyNotChase

Ya totally fair. Will do so by Sunday night at the latest. Thanks for pushing on this

adeshpande3 avatar Feb 14 '20 14:02 adeshpande3

any updates on this?

elijaholmos avatar Feb 08 '22 05:02 elijaholmos