import codecs


def get_word_vectors_utf8(word_vectors_filename, encoding='utf-8'):
    """
    Get word vectors from a word2vec generated file
    """

    word_vectors = dict()
    with codecs.open(word_vectors_filename, encoding=encoding) as f:
        for line in f:
            splt = line.strip().split()
            word = splt[0]
            try:
                vector = [float(el) for el in splt[1:]]
                word_vectors[word] = vector
            except ValueError:
                continue
    return word_vectors