<p>With <code>gensim</code>, there is no way around the initial load time for the model. You can use a smaller model to reduce load times, but large model files will  inevitably require a few seconds to load when your application is being initialized. However, if you have designed your application correctly, this should be a cost you pay only once (when your program first starts). </p>

<p>If it's really important to save those few seconds at startup, you might consider switching from <code>gensim</code>'s word2vec implementation to <a href="https://github.com/plasticityai/magnitude" rel="nofollow noreferrer"><code>magnitude</code></a>, which has an initial load time of less than one second, as well as speed/usability improvements in many other areas (as in, speed improvements of hundreds to thousands of times faster than gensim for many tasks). If you're interested in reading a bit on the background behind magnitude, you can read the academic paper by it's authors (free to read on arXiv):</p>

<p><a href="https://arxiv.org/abs/1810.11190" rel="nofollow noreferrer">Magnitude: A Fast, Efficient Universal Vector Embedding Utility Package</a></p>
Class of word2vec model (Python)
<h3>Task</h3>

<p>I want to make a class for <code>word2vec</code> model and call it, so the process will be faster and more efficient. </p>

<h3>Script</h3>

<pre><code>from docsim import DocSim
from gensim.models.keyedvectors import KeyedVectors

word2vec_model = 'w2vec_wiki_id_case_doc'

model = KeyedVectors.load(word2vec_model, mmap='r')
ds = DocSim(model)
</code></pre>

<h3>Problem</h3>

<p>With my code, the process takes a long time to read the <code>word2vec</code> model. How can I  solve the problem? </p>