Skip to content

made tutorials compatible with python 3 #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 9, 2016
Merged

made tutorials compatible with python 3 #132

merged 9 commits into from
Feb 9, 2016

Conversation

gyom
Copy link
Contributor

@gyom gyom commented Jan 22, 2016

All the examples from the main page (http://deeplearning.net/tutorial/) have been updated, except for two.

They have all been tested, to then extent that they run fine with python 2 and python 3, for 10-20 minutes, but I didn't have a GPU available to run them to completion (potential source for errors in final lines of scripts).

rnnrbm.py has an issue with the "midi" module that is downloaded from an external source. I am led to believe that it is not compatible with python 3 due to the way that it loads local sources. Not sure if this is fixable without modifying the "midi" module.

With rnnslu.py, the existing code currently fails to run on python 2 without any changes to the code. Not sure if Gregoire Mesnil is responsible for maintaining this code. For one thing, the script is referring to the url http://www-etud.iro.umontreal.ca/~mesnilgr/atis/conlleval.pl which is currently broken.

@lamblin
Copy link
Member

lamblin commented Jan 26, 2016

Fix #114.

@lamblin
Copy link
Member

lamblin commented Jan 26, 2016

Two tests are failing because of a change in Theano, in some place we did not expect code to use directly: the Param class has been deleted, since the In class now supports all its features. See Theano/Theano#3890
While I think we should be nice to keep some compatibility if possible (we'll discuss that), it would still be a good idea to update the tutorials.

For conlleval, you can download a copy at http://www-etud.iro.umontreal.ca/~lamblinp/code/conlleval.pl so you can run (and port) rnnslu.py (not to replace the URL). We will try to find a better hosting for that script.

Could you do that this week?

@gyom
Copy link
Contributor Author

gyom commented Jan 27, 2016

I'll do this Thursday to be able to talk to you (Pascal and Fred) in person about issues that come up. Are you going to be at the lab ?

@lamblin
Copy link
Member

lamblin commented Jan 27, 2016

I'm going to be there, but Fred is away until next week.

@gyom
Copy link
Contributor Author

gyom commented Jan 28, 2016

Made changes from Fred's pull request.

Also fixed rnnslu.py. Right now, this requires manually downloading conlleval.py into code/rnnslu/conlleval.py before running the script.

c.append(pretraining_fns[i](index=batch_index,
corruption=corruption_levels[i],
lr=pretrain_lr))
print 'Pre-training layer %i, epoch %d, cost ' % (i, epoch),
print numpy.mean(c)
print('Pre-training layer %i, epoch %d, cost ' % (i, epoch))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not equivalent to the previous call: the previous call was printing something without a newline at the end, so that the next print statement would append to the same line.
The equivalent for the new print() function would be:
print('Pre-training layer %i, epoch %d, cost ' % (i, epoch), end='')

@lamblin
Copy link
Member

lamblin commented Jan 28, 2016

Other than that, it looks good to me, but I'll let @nouiz do a final review.

@nouiz
Copy link
Member

nouiz commented Jan 29, 2016

I'll do a final review when @lamblin comment are addressed. thanks

On Thu, Jan 28, 2016 at 5:47 PM, Pascal Lamblin notifications@github.com
wrote:

Other than that, it looks good to me, but I'll let @nouiz
https://github.com/nouiz do a final review.


Reply to this email directly or view it on GitHub
#132 (comment)
.

@nouiz
Copy link
Member

nouiz commented Feb 1, 2016

I don't get a notification when a new commit is added to a PR. Add a comment to the PR when you want one of us to review it again.

@@ -7,6 +7,7 @@
"""


from six.moves import xrange
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be a better example to follow if we don't use this import and change everywhere xrange to range. Can you do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change all the instances with range instead of xrange. That's what I did at first, but then I figured the proper way to use xrange in a compatible way. I'll just use range for all cases. They're "safe" in the sense that none of those calls require fast execution.

@nouiz
Copy link
Member

nouiz commented Feb 1, 2016

Can you add this in the .travis file to have travis run with python 3?

language: python
python:
  - "2.6"
  - "3.3"

What is the problem with rnnrbm? The midi related files? For this one can you download this zip file: http://www.iro.umontreal.ca/~lisa/deep/midi.zip and make a new zip with the files updated to python 3? I will then update it on the server. (and remove the command related to it)

thanks

@gyom
Copy link
Contributor Author

gyom commented Feb 1, 2016

The issue with the rnnrbm is that the midi library is not loading properly in python 3 because it uses one way to refer to its internal files instead of the python 3 way. I spoke with Pascal about this, and he knows better what I'm talking about. If we can update the midi.zip file, then it's possible to fix this, and this is what I'll do.

@nouiz
Copy link
Member

nouiz commented Feb 1, 2016

thanks

On Mon, Feb 1, 2016 at 1:35 PM, Guillaume Alain notifications@github.com
wrote:

The issue with the rnnrbm is that the midi library is not loading properly
in python 3 because it uses one way to refer to its internal files instead
of the python 3 way. I spoke with Pascal about this, and he knows better
what I'm talking about. If we can update the midi.zip file, then it's
possible to fix this, and this is what I'll do.


Reply to this email directly or view it on GitHub
#132 (comment)
.

except:
# python 3 compatibility
# http://stackoverflow.com/questions/3073259/python-nose-import-error
from hmc.hmc import HMC_sampler
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I have more insight about this.
In this case, the issue is a clash of names between the hmc/ directory and the hmc.py file inside. On Python 3, nosetests thinks hmc is the directory, but the regular Python interpreter thinks it is hmc.py (if you try to import test_hmc for instance, or run python test_hmc.py).
This looks like an issue with nosetests to me. Possible solutions would include:

  • Yours (except that I would catch only ImportError rather than anything)
  • Having different names, by either renaming hmc/ or hmc.py. That would break direct links, though.

I would prefer the first one.
However, for midi, I'm not sure that the issue is the same exactly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also prefer option 1.

@lamblin
Copy link
Member

lamblin commented Feb 3, 2016

For conlleval, can you try downloading it from http://www.cnts.ua.ac.be/conll2000/chunking/conlleval.txt ?

@abergeron
Copy link
Contributor

conlleval has already been fixed in master.

@nouiz
Copy link
Member

nouiz commented Feb 3, 2016

Also, this PR need a rebase, it have conflict with master.

@gyom
Copy link
Contributor Author

gyom commented Feb 3, 2016

In terms of language compatibility and imported modules, I have made the "midi" module work with python 2 and 3. Now, the problem is that it has difficulties loading midi files. It works fine in python 2, but in python 3 I get this error.

Traceback (most recent call last):
File "code/rnnrbm.py", line 298, in
model = test_rnnrbm()
File "code/rnnrbm.py", line 294, in test_rnnrbm
batch_size=batch_size, num_epochs=num_epochs)
File "code/rnnrbm.py", line 248, in train
for f in files]
File "code/rnnrbm.py", line 248, in
for f in files]
File "/u/alaingui/Documents/DeepLearningTutorials/code/midi/utils.py", line 23, in init
midi_in.read()
File "/u/alaingui/Documents/DeepLearningTutorials/code/midi/MidiInFile.py", line 47, in read
p.parseMThdChunk()
File "/u/alaingui/Documents/DeepLearningTutorials/code/midi/MidiFileParser.py", line 48, in parseMThdChunk
raise TypeError("It is not a valid midi file!")
TypeError: It is not a valid midi file!

At first glance, this seems like it's a problem when decoding the raw files. This might be due to byte array encodings, with strings being used for one purpose in python 2 that just doesn't translated well into python 3.

I'm signaling this because I'm now no longer strictly in the "straightforward port from python 2 to 3", but probably more into the development of the "midi" module where I'm required to figure out what the code does and what it's trying to do to decode midi files. The question becomes whether this falls outside of the scope of the original ticket or not.

I won't commit this "midi" code in the DeepLearningTutorials in any case, but I can put it elsewhere if you want to have a look at it.

@nouiz
Copy link
Member

nouiz commented Feb 3, 2016

Can you give us access to that midi version?

On Wed, Feb 3, 2016 at 4:29 PM, Guillaume Alain notifications@github.com
wrote:

In terms of language compatibility and imported modules, I have made the
"midi" module work with python 2 and 3. Now, the problem is that it has
difficulties loading midi files. It works fine in python 2, but in python 3
I get this error.

Traceback (most recent call last):
File "code/rnnrbm.py", line 298, in
model = test_rnnrbm()
File "code/rnnrbm.py", line 294, in test_rnnrbm
batch_size=batch_size, num_epochs=num_epochs)
File "code/rnnrbm.py", line 248, in train
for f in files]
File "code/rnnrbm.py", line 248, in
for f in files]
File "/u/alaingui/Documents/DeepLearningTutorials/code/midi/utils.py",
line 23, in init
midi_in.read()
File
"/u/alaingui/Documents/DeepLearningTutorials/code/midi/MidiInFile.py", line
47, in read
p.parseMThdChunk()
File
"/u/alaingui/Documents/DeepLearningTutorials/code/midi/MidiFileParser.py",
line 48, in parseMThdChunk
raise TypeError("It is not a valid midi file!")
TypeError: It is not a valid midi file!

At first glance, this seems like it's a problem when decoding the raw
files. This might be due to byte array encodings, with strings being used
for one purpose in python 2 that just doesn't translated well into python 3.

I'm signaling this because I'm now no longer strictly in the
"straightforward port from python 2 to 3", but probably more into the
development of the "midi" module where I'm required to figure out what the
code does and what it's trying to do to decode midi files. The question
becomes whether this falls outside of the scope of the original ticket or
not.

I won't commit this "midi" code in the DeepLearningTutorials in any case,
but I can put it elsewhere if you want to have a look at it.


Reply to this email directly or view it on GitHub
#132 (comment)
.

@nouiz
Copy link
Member

nouiz commented Feb 8, 2016

travis tests are failing due to that:

File "/home/travis/build/lisa-lab/DeepLearningTutorials/code/rnnslu.py", line 144
print stdout.split('\n')

this is the new change in master that requested a rebase.

@gyom
Copy link
Contributor Author

gyom commented Feb 9, 2016

Should be fixed. We'll see what travis reports.

@nouiz
Copy link
Member

nouiz commented Feb 9, 2016

thanks. merging.

nouiz added a commit that referenced this pull request Feb 9, 2016
made tutorials compatible with python 3
@nouiz nouiz merged commit 1bb3230 into lisa-lab:master Feb 9, 2016
taneishi pushed a commit to taneishi/DBN that referenced this pull request Nov 28, 2019
made tutorials compatible with python 3
taneishi pushed a commit to taneishi/DBN that referenced this pull request Feb 13, 2020
made tutorials compatible with python 3

Former-commit-id: 2efc6cb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants