-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Utils and Matutils changes #1062
Conversation
@@ -608,7 +607,7 @@ def is_corpus(obj): | |||
doc1 = next(iter(obj)) # empty corpus is resolved to False here | |||
if len(doc1) == 0: # sparse documents must have a __len__ function (list, tuple...) | |||
return True, obj # the first document is empty=>assume this is a corpus | |||
id1, val1 = next(iter(doc1)) # if obj is a numpy array, it resolves to False here | |||
id1, val1 = next(iter(doc1)) # if obj is a np array, it resolves to False here |
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 replacement (and the one above) look unnecessary, the original was clearer.
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.
Cool, will fix it
@@ -74,15 +64,15 @@ def expect_log_sticks(sticks): | |||
|
|||
def lda_e_step(doc_word_ids, doc_word_counts, alpha, beta, max_iter=100): | |||
gamma = np.ones(len(alpha)) | |||
expElogtheta = np.exp(dirichlet_expectation(gamma)) | |||
expElogtheta = np.exp(matutils.dirichlet_expectation(gamma)) |
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.
better to add from matutils import dirichlet_expectation
to avoid this change
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.
Okay, changed
Thanks for the improvement! |
@@ -829,15 +828,15 @@ def __init__(self, q, corpus, chunksize, maxsize, as_numpy): | |||
|
|||
def run(self): | |||
if self.as_numpy: | |||
import numpy # don't clutter the global namespace with a dependency on numpy | |||
import np # don't clutter the global namespace with a dependency on numpy |
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.
Looks like the global module namespace already has numpy, so this line is unnecessary.
@@ -801,13 +800,13 @@ def chunkize_serial(iterable, chunksize, as_numpy=False): | |||
[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]] | |||
|
|||
""" | |||
import numpy | |||
import numpy as np |
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.
Already imported at module level, this line no longer unnecessary.
* Utils, Matutils changes * Changed comments * changed matutils import
dirichlet_expectation
tomatutils
as the same code was being used in bothldamodel
andhdpmodel
.numpy
inutils
andmatutils
tonp
, keeping it uniform across the package.hdpmodel
to make it consistent withldamodel