src/build_embeddings.py
def build_glove_embeddings(corpus):
    """
    DESCRIPTION: 
             Applies the Glove python SGD algorithm given by glove_python library and build the
             word embeddings from our training set.
    INPUT:
            corpus: a list of lists where each sub-list represent a tweet. The outer list represents
                    the whole training dataset.
    OUTPUT: 
            words: python dictionary of the form (word, [vector of embeddings])
    """
    words = load_glove_embeddings_from_txt_file(MY_GLOVE_PYTHON_EMBEDDINGS_TXT_FILE)
    if words != None:
        return words
    model  = Corpus()
    model.fit(corpus, window = algorithm['options']['WE']['window_size'])

    glove = Glove(no_components=algorithm['options']['WE']['we_features'], learning_rate=algorithm['options']['WE']['learning_rate'])
    print('\nFitting Glove Python Embeddings')
    glove.fit(model.matrix, epochs=algorithm['options']['WE']['epochs'])
    glove.add_dictionary(model.dictionary)

    words = {}
    for w, id_ in glove.dictionary.items():
        words[w] = np.array(glove.word_vectors[id_])

    store_embeddings_to_txt_file(words, MY_GLOVE_PYTHON_EMBEDDINGS_TXT_FILE)
    return words

    DESCRIPTION: 
             Applies the Glove python SGD algorithm given by glove_python library and build the
             word embeddings from our training set.
    INPUT:
            corpus: a list of lists where each sub-list represent a tweet. The outer list represents
                    the whole training dataset.
    OUTPUT: 
            words: python dictionary of the form (word, [vector of embeddings])
    
Applies the Glove python SGD algorithm given by glove_python library and build the
word embeddings from our training set.
INPUT:
corpus: a list of lists where each sub-list represent a tweet. The outer list represents
the whole training dataset.
OUTPUT:
words: python dictionary of the form (word, [vector of embeddings])
Applies the Glove python SGD algorithm given by glove_python library and build the word embeddings from our training set . INPUT : corpus : a list of lists where each sub - list represent a tweet . The outer list represents the whole training dataset . OUTPUT : words : python dictionary of the form ( word [ vector of embeddings ] )
def build_glove_embeddings(corpus):
    words = load_glove_embeddings_from_txt_file(MY_GLOVE_PYTHON_EMBEDDINGS_TXT_FILE)
    if words != None:
        return words
    model  = Corpus()
    model.fit(corpus, window = algorithm['options']['WE']['window_size'])
    glove = Glove(no_components=algorithm['options']['WE']['we_features'], learning_rate=algorithm['options']['WE']['learning_rate'])
    print('\nFitting Glove Python Embeddings')
    glove.fit(model.matrix, epochs=algorithm['options']['WE']['epochs'])
    glove.add_dictionary(model.dictionary)
    words = {}
    for w, id_ in glove.dictionary.items():
        words[w] = np.array(glove.word_vectors[id_])
    store_embeddings_to_txt_file(words, MY_GLOVE_PYTHON_EMBEDDINGS_TXT_FILE)
    return words
def build_glove_embeddings ( corpus ) : words = load_glove_embeddings_from_txt_file ( MY_GLOVE_PYTHON_EMBEDDINGS_TXT_FILE ) if words != None : return words model = Corpus ( ) model . fit ( corpus , window = algorithm [ 'options' ] [ 'WE' ] [ 'window_size' ] ) glove = Glove ( no_components = algorithm [ 'options' ] [ 'WE' ] [ 'we_features' ] , learning_rate = algorithm [ 'options' ] [ 'WE' ] [ 'learning_rate' ] ) print ( '\nFitting Glove Python Embeddings' ) glove . fit ( model . matrix , epochs = algorithm [ 'options' ] [ 'WE' ] [ 'epochs' ] ) glove . add_dictionary ( model . dictionary ) words = { } for w , id_ in glove . dictionary . items ( ) : words [ w ] = np . array ( glove . word_vectors [ id_ ] ) store_embeddings_to_txt_file ( words , MY_GLOVE_PYTHON_EMBEDDINGS_TXT_FILE ) return words
DESCRIPTION:
Applies the Glove python SGD algorithm given by glove_python library and build the
word embeddings from our training set.
DESCRIPTION : Applies the Glove python SGD algorithm given by glove_python library and build the word embeddings from our training set .
"""
    DESCRIPTION: 
             Applies the Glove python SGD algorithm given by glove_python library and build the
             word embeddings from our training set.
    INPUT:
            corpus: a list of lists where each sub-list represent a tweet. The outer list represents
                    the whole training dataset.
    OUTPUT: 
            words: python dictionary of the form (word, [vector of embeddings])
    """
corpus