Skip to content
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

Update 'documents_columns' param passed to 'Sparse2Corpus' #1704

Merged
merged 3 commits into from
Nov 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gensim/sklearn_api/hdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def fit(self, X, y=None):
Calls gensim.models.HdpModel
"""
if sparse.issparse(X):
corpus = matutils.Sparse2Corpus(X)
corpus = matutils.Sparse2Corpus(sparse=X, documents_columns=False)
else:
corpus = X

Expand Down Expand Up @@ -95,7 +95,7 @@ def partial_fit(self, X):
Train model over X.
"""
if sparse.issparse(X):
X = matutils.Sparse2Corpus(X)
X = matutils.Sparse2Corpus(sparse=X, documents_columns=False)

if self.gensim_model is None:
self.gensim_model = models.HdpModel(
Expand Down
4 changes: 2 additions & 2 deletions gensim/sklearn_api/ldamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def fit(self, X, y=None):
Calls gensim.models.LdaModel
"""
if sparse.issparse(X):
corpus = matutils.Sparse2Corpus(X)
corpus = matutils.Sparse2Corpus(sparse=X, documents_columns=False)
else:
corpus = X

Expand Down Expand Up @@ -101,7 +101,7 @@ def partial_fit(self, X):

"""
if sparse.issparse(X):
X = matutils.Sparse2Corpus(X)
X = matutils.Sparse2Corpus(sparse=X, documents_columns=False)

if self.gensim_model is None:
self.gensim_model = models.LdaModel(
Expand Down
4 changes: 2 additions & 2 deletions gensim/sklearn_api/lsimodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def fit(self, X, y=None):
Calls gensim.models.LsiModel
"""
if sparse.issparse(X):
corpus = matutils.Sparse2Corpus(X)
corpus = matutils.Sparse2Corpus(sparse=X, documents_columns=False)
else:
corpus = X

Expand Down Expand Up @@ -78,7 +78,7 @@ def partial_fit(self, X):
Train model over X.
"""
if sparse.issparse(X):
X = matutils.Sparse2Corpus(X)
X = matutils.Sparse2Corpus(sparse=X, documents_columns=False)

if self.gensim_model is None:
self.gensim_model = models.LsiModel(
Expand Down
2 changes: 1 addition & 1 deletion gensim/test/test_sklearn_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def testCSRMatrixConversion(self):
newmodel.fit(sarr)
bow = [(0, 1), (1, 2), (2, 0)]
transformed_vec = newmodel.transform(bow)
expected_vec = numpy.array([0.35367903, 0.64632097])
expected_vec = numpy.array([0.12843782, 0.87156218])
Copy link
Owner

Choose a reason for hiding this comment

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

Why this change?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think because now this script interprets the input differently -> different model -> different result, but looks suspicious, I agree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@piskvorky As Ivan correctly pointed out, since the input matrix used for training (by fit method) is being interpreted differently after making this change, the model changes and thus, the output of transform changes as well.

passed = numpy.allclose(transformed_vec, expected_vec, atol=1e-1)
self.assertTrue(passed)

Expand Down