doc2vec - How to infer vectors of documents faster?
<p>I have trained paragraph vectors for around 2300 paragraphs(between 2000-12000 words each) each with vector size of 300. Now, I need to infer paragraph vectors of around 100,000 sentences which I have considered as paragraphs(each sentence is around 10-30 words each corresponding to the earlier 2300 paragraphs already trained).</p>

<p>So, am using </p>

<p><code>model.infer_vector(sentence)</code></p>

<p>But, the problem is it is taking too long, and it does not take any arguments such as "workers" .! Is there a way I can speed up the process by threading or some other way? I am using a machine with 8gb ram and when I checked the available cores using</p>

<pre><code>cores = multiprocessing.cpu_count()
</code></pre>

<p>it comes out to be 8.</p>

<p>I need this for answering multiple choice questions. Also, are there any other libraries/models such as doc2vec which can help in this task?</p>

<p>Thanks in advance for your time.</p>

<p>You might get a slight speedup from calling <code>infer_vector()</code> from multiple threads, on different subsets of the new data on which you need to infer vectors. There would still be quite a bit of thread-contention, preventing full use of all cores, due to the Python Global Interpreter Lock ('GIL').  </p>

<p>If your RAM is large enough to do so without swapping, you could save the model to disk, then load it into 8 separate processes, and have each do inference on 1/8th of the new data. That'd be the best way to saturate all CPUs. </p>

<p>Any faster speedups would require making optimizations to the <code>infer_vector()</code> implementation in gensim â which is an <a href="https://github.com/RaRe-Technologies/gensim/issues/515" rel="nofollow">open issue</a> on the project that would accept contributed improvements. </p>

python gensim word2vec doc2vec