Facebook-Messenger-Bot
Facebook-Messenger-Bot copied to clipboard
Port code to python 3
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 allopen(....)
commands -
print 'string'
will be changed toprint('string')
-
raw_input
(s) will be changed toinput()
-
dict.iterItems()
will be changed todict.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 withtf.compat.v1.Session()
- Going to use
tf.compat.v1.disable_eager_execution()
, without this we cannot useplaceholder()
-
tf.random_uniform()
will be replaced withtf.random.uniform()
-
tf.truncated_normal()
will be replaced withtf.random.truncated_normal()
-
tf.placeholder()
will be replaced withtf.compat.v1.placeholder
-
tf.train.GradientDescentOptimizer()
will be replaced withtf.compat.v1.train.GradientDescentOptimizer()
-
tf.global_variables_initializer()
will be replaced withtf.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!
@adeshpande3 let me know what you think of these changes, and also if you'd like me to know anything while porting.
Yeah this sounds fantastic to me, appreciate it! Lmk if I can be helpful
@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
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 any updates on legacy_seq2seq
?
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 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
Ya totally fair. Will do so by Sunday night at the latest. Thanks for pushing on this
any updates on this?