-
Notifications
You must be signed in to change notification settings - Fork 60
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
Updating DNA2Vec to work with Python 3.7, and to work on Windows 10. #15
base: master
Are you sure you want to change the base?
Conversation
Could you elaborate on the memory issue? I'm looking into using this in a unix environment and might be able to help. |
Well, the original author uses the “resource” package to be able to monitor
the RAM and CPU usage, but it is an UNIX specific library. If you look at
attic_util/util.py, I commented out resources (all it did was return the
memory usage) and just returned 0 instead on my branch. If you want to use
this feature, just uncomment the relevant areas. By the way, tell me how it
goes, I’ve only tested it on windows.
…On Thursday, May 21, 2020, Kennan LeJeune ***@***.***> wrote:
A slight issue that I haven't gotten around to yet is fixing the memory
usage, as the packages "resource" is a Unix specific package.
Could you elaborate on the memory issue? I'm looking into using this in a
unix environment and might be able to help.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#15 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGKLDQU2OG6OXFIMVFSP7XLRSVML5ANCNFSM4M7WJTBA>
.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you be more specific about what's incompatible in python 3.7?
attic_util/util.py
Outdated
@@ -1,6 +1,6 @@ | |||
import random | |||
import string | |||
import resource | |||
# import resource |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of commenting this out, you can use the try
and catch ImportError
pattern: https://stackoverflow.com/questions/3131217/error-handling-when-importing-modules
You can move this within memory_usage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll work on it when I get the chance.
requirements.txt
Outdated
tox==2.7.0 | ||
tox-pyenv==1.0.3 | ||
virtualenv==15.1.0 | ||
arrow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please pin the versions. This will install the latest versions, which may break the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was one of the issues when moving up to Python 3.7. Several of the older versions of the libraries were incompatible with Python 3.7, so installing the latest versions would definitely reduce incompatibilities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that these older versions are incompatible with python 3.7. A couple of months from now, when there are upgrades to these libraries, the API for the new versions may not be backward-compatible to the current code.
Pinning the versions to new version numbers ensure that this is at least compatible to the version you tested on, which is python 3.7. You can see the versions of your current environment with pip freeze
The existing version of |
class SingleKModel: | ||
def __init__(self, model): | ||
self.model = model | ||
self.vocab_lst = sorted(model.vocab.keys()) | ||
|
||
class MultiKModel: | ||
def __init__(self, filepath): | ||
self.aggregate = word2vec.Word2Vec.load_word2vec_format(filepath, binary=False) | ||
self.aggregate = gensim.models.KeyedVectors.load_word2vec_format(filepath, binary=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pnpnpn I'm not sure if this is actually broken in python 3.7, but Word2Vec has definitely been deprecated so this is probably still a good idea.
scripts/train_dna2vec.py
Outdated
@@ -52,7 +52,7 @@ def train(self, kmer_seq_generator): | |||
|
|||
def write_vec(self): | |||
out_filename = '{}.w2v'.format(self.out_fileroot) | |||
self.model.wv.save_word2vec_format(out_filename, binary=False) | |||
self.model.wv.save_word2vec_format("."+out_filename, binary=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you prepend with .
? This would make it a hidden file in linux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must've not noticed that change as I was working on Windows. I'll change it in the latest push.
requirements.txt
Outdated
tox==2.7.0 | ||
tox-pyenv==1.0.3 | ||
virtualenv==15.1.0 | ||
arrow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that these older versions are incompatible with python 3.7. A couple of months from now, when there are upgrades to these libraries, the API for the new versions may not be backward-compatible to the current code.
Pinning the versions to new version numbers ensure that this is at least compatible to the version you tested on, which is python 3.7. You can see the versions of your current environment with pip freeze
from gensim import matutils | ||
|
||
import gensim |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The train_dna2vec.py
also imports word2vec
. Would the upgrade of gensim break the training of that file? Have you try training?
@@ -132,7 +132,7 @@ def main(): | |||
args.kmer_fragmenter)) | |||
|
|||
out_txt_filename = '{}.txt'.format(out_fileroot) | |||
with open(out_txt_filename, 'w') as summary_fptr: | |||
with open(out_txt_filename, 'w+') as summary_fptr: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the w+
change?
print(header_str, file=fptr) | ||
for vocab in vocabs: | ||
vec_str = ' '.join("%f" % val for val in self.aggregate[vocab]) | ||
print('{} {}'.format(vocab, vec_str), file=fptr) | ||
fptr.flush() | ||
return SingleKModel(word2vec.Word2Vec.load_word2vec_format(fptr.name, binary=False)) | ||
open(fptr.name, "rb") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose for this?
@@ -25,6 +27,7 @@ def __init__(self, filepath): | |||
self.data = {} | |||
for k in range(self.k_low, self.k_high + 1): | |||
self.data[k] = self.separate_out_model(k) | |||
print(len(self.data)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this for debugging? Please remove.
@@ -4,17 +4,19 @@ | |||
import tempfile | |||
import numpy as np | |||
|
|||
from gensim.models import word2vec | |||
# from gensim.models import word2vec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just delete this.
A slight issue that I haven't gotten around to yet is fixing the memory usage, as the packages "resource" is a Unix specific package.