Skip to content

Commit

Permalink
Add single core mode to CoherenceModel. Fix #1683 (#1685)
Browse files Browse the repository at this point in the history
* fix #1683 - no single core mode

* Update setup.py
  • Loading branch information
horpto authored and menshikh-iv committed Nov 2, 2017
1 parent 7ceeda9 commit 903b645
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gensim/models/coherencemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def __init__(self, model=None, topics=None, texts=None, corpus=None, dictionary=
self._topics = None
self.topics = topics

self.processes = processes if processes > 1 else max(1, mp.cpu_count() - 1)
self.processes = processes if processes >= 1 else max(1, mp.cpu_count() - 1)

@classmethod
def for_models(cls, models, dictionary, topn=20, **kwargs):
Expand Down
17 changes: 17 additions & 0 deletions gensim/test/test_coherencemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import tempfile
import unittest
from unittest import SkipTest
import multiprocessing as mp

import numpy as np
from gensim.corpora.dictionary import Dictionary
Expand Down Expand Up @@ -213,6 +214,22 @@ def testErrors(self):
coherence='u_mass'
)

def testProcesses(self):
cpu = mp.cpu_count()
get_model = lambda p: CoherenceModel(
topics=self.topics1, corpus=self.corpus, dictionary=self.dictionary, coherence='u_mass', processes=p,
)

model = CoherenceModel(
topics=self.topics1, corpus=self.corpus, dictionary=self.dictionary, coherence='u_mass',
)
self.assertEqual(model.processes, cpu - 1)
for p in range(-2, 1):
self.assertEqual(get_model(p).processes, cpu - 1)

for p in range(1, 4):
self.assertEqual(get_model(p).processes, p)

def testPersistence(self):
fname = testfile()
model = CoherenceModel(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def finalize_options(self):
'scikit-learn',
'pyemd',
'annoy',
'tensorflow >= 1.1.0',
'tensorflow <= 1.3.0',
'keras >= 2.0.4',
]

Expand Down

0 comments on commit 903b645

Please sign in to comment.