def build_vocab(self, data_filepath, vocab_filepath, min_count):
    'Create vocabulary-related data.'
    logger.info('Building vocabulary from file {}'.format(data_filepath))
    logger.info('Loading word counts...')
    if (self.vocab_size > 1):
        logger.warning("This instance of W2V's vocabulary does not seem to be empty. Erasing previously stored vocab...")
        (self._words, self._counts, self._total_count) = ([], [], 0)
    word_count_dict = defaultdict(int)
    with open(data_filepath, 'r') as data_stream:
        for line in data_stream:
            for word in line.strip().split():
                word_count_dict[word] += 1
    logger.info('Saving word frequencies to file: {}'.format(vocab_filepath))
    with open(vocab_filepath, 'w') as vocab_stream:
        for (word, count) in sorted(word_count_dict.items(), key=(lambda x: x[1]), reverse=True):
            print('{}\t{}'.format(word, count), file=vocab_stream)
            if (count >= min_count):
                self._words.append(word)
                self._counts.append(count)
                self._total_count += count
Create vocabulary-related data.
def build_vocab(self, data_filepath, vocab_filepath, min_count):
    
    logger.info('Building vocabulary from file {}'.format(data_filepath))
    logger.info('Loading word counts...')
    if (self.vocab_size > 1):
        logger.warning("This instance of W2V's vocabulary does not seem to be empty. Erasing previously stored vocab...")
        (self._words, self._counts, self._total_count) = ([], [], 0)
    word_count_dict = defaultdict(int)
    with open(data_filepath, 'r') as data_stream:
        for line in data_stream:
            for word in line.strip().split():
                word_count_dict[word] += 1
    logger.info('Saving word frequencies to file: {}'.format(vocab_filepath))
    with open(vocab_filepath, 'w') as vocab_stream:
        for (word, count) in sorted(word_count_dict.items(), key=(lambda x: x[1]), reverse=True):
            print('{}\t{}'.format(word, count), file=vocab_stream)
            if (count >= min_count):
                self._words.append(word)
                self._counts.append(count)
                self._total_count += count