title: word2vec/gensim — RuntimeError: you must first build vocabulary before training the model
body: <p>I am having trouble training my own <code>word2vec</code> model on the <code>.txt</code> files.</p>
  <p>The code:</p>
  <pre><code>import gensim
  import json
  import pandas as pd
  import glob
  import gensim.downloader as api
  import matplotlib.pyplot as plt
  from gensim.models import KeyedVectors
  
  
  # loading the .txt files
  
  sentences = []
  sentence = []
  for doc in glob.glob('./data/*.txt'): 
       with(open(doc, 'r')) as f:
          for line in f:
              line = line.rstrip()
              if line == &quot;&quot;:
                  if len(sentence) &gt; 0:
                      sentences.append(sentence)
                      sentence = []
              else:
                  cols = line.split(&quot;\t&quot;)
                  if len(cols) &gt; 4:
                      form = cols[1]
                      lemma = cols[2]
                      pos = cols[3]
                      if pos != &quot;PONCT&quot;:
                          sentence.append(form.lower())
  
  
  # trying to train the model
  
  from gensim.models import Word2Vec
  model_hugo = Word2Vec(sentences, vector_size=200, window=5, epochs=10, sg=1, workers=4)
  </code></pre>
  <p>Message error:</p>
  <pre><code>RuntimeError: you must first build vocabulary before training the model
  </code></pre>
  <p>How do I build the vocabulary?</p>
  <p>The code works with the sample <code>.conll</code> files, but I want to train the model on my own data.</p>