Repository: piskvorky/gensim

Issue:
model/coherencemodel.py issue - no single core mode
#### Description
**model/coherencemodel.py** can not be used in single core mode.

#### Steps/Code/Corpus to Reproduce
**line 218**
`self.processes = processes if processes > 1 else max(1, mp.cpu_count() - 1)`

#### Expected Results
If I choose processes parameter = 1 for TopicCoherence, self.processes should be 1, too.

#### Actual Results
If I choose processes parameter = 1 for TopicCoherence, self.processes is mp.cpu_count() - 1. In my case self.processes = 3.

#### Solution
**line 218**
`self.processes = processes if processes >= 1 else max(1, mp.cpu_count() - 1)`

#### Versions
Windows-10-10.0.14393-SP0
Python 3.5.2 |Enthought, Inc. (x86_64)| (default, Mar  2 2017, 16:37:47) [MSC v.1900 64 bit (AMD64)]
NumPy 1.13.3
SciPy 1.0.0
gensim 3.0.1
FAST_VERSION 0


model/coherencemodel.py issue - no single core mode
#### Description
**model/coherencemodel.py** can not be used in single core mode.

#### Steps/Code/Corpus to Reproduce
**line 218**
`self.processes = processes if processes > 1 else max(1, mp.cpu_count() - 1)`

#### Expected Results
If I choose processes parameter = 1 for TopicCoherence, self.processes should be 1, too.

#### Actual Results
If I choose processes parameter = 1 for TopicCoherence, self.processes is mp.cpu_count() - 1. In my case self.processes = 3.

#### Solution
**line 218**
`self.processes = processes if processes >= 1 else max(1, mp.cpu_count() - 1)`

#### Versions
Windows-10-10.0.14393-SP0
Python 3.5.2 |Enthought, Inc. (x86_64)| (default, Mar  2 2017, 16:37:47) [MSC v.1900 64 bit (AMD64)]
NumPy 1.13.3
SciPy 1.0.0
gensim 3.0.1
FAST_VERSION 0




Discussion:
Thanks for report @chriswi93 
Thanks for report @chriswi93 

Resolving patch:
diff --git a/gensim/models/coherencemodel.py b/gensim/models/coherencemodel.py
--- a/gensim/models/coherencemodel.py
+++ b/gensim/models/coherencemodel.py
@@ -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):
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -231,7 +231,7 @@ def finalize_options(self):
     'scikit-learn',
     'pyemd',
     'annoy',
-    'tensorflow >= 1.1.0',
+    'tensorflow <= 1.3.0',
     'keras >= 2.0.4',
 ]
 


Test patch:
diff --git a/gensim/test/test_coherencemodel.py b/gensim/test/test_coherencemodel.py
--- a/gensim/test/test_coherencemodel.py
+++ b/gensim/test/test_coherencemodel.py
@@ -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
@@ -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(