skills_ml/algorithms/embedding/models.py
def infer_vector(self, doc_words, warning=False):
        """
        Average all the word-vectors together and ignore the unseen words
        Arg:
            doc_words (list): a list of tokenized words
        Returns:
            a vector representing a whole doc/sentence
        """
        sum_vector = np.zeros(self.vector_size)
        words_in_vocab = []
        for token in doc_words:
            try:
                sum_vector += self[token]
                words_in_vocab.append(token)
            except KeyError as e:
                if warning:
                    logging.warning("".join([str(e), ". Ignore the word."]))
                pass

        if len(words_in_vocab) == 0:
            logging.warning("None of the words is in vocabulary.")
            return np.random.rand(self.vector_size)
        sentence_vector = sum_vector / len(words_in_vocab)
        return sentence_vector

        Average all the word-vectors together and ignore the unseen words
        Arg:
            doc_words (list): a list of tokenized words
        Returns:
            a vector representing a whole doc/sentence
        
Average all the word-vectors together and ignore the unseen words
Arg:
doc_words (list): a list of tokenized words
Average all the word - vectors together and ignore the unseen words Arg : doc_words ( list ) : a list of tokenized words
def infer_vector(self, doc_words, warning=False):
        sum_vector = np.zeros(self.vector_size)
        words_in_vocab = []
        for token in doc_words:
            try:
                sum_vector += self[token]
                words_in_vocab.append(token)
            except KeyError as e:
                if warning:
                    logging.warning("".join([str(e), ". Ignore the word."]))
                pass
        if len(words_in_vocab) == 0:
            logging.warning("None of the words is in vocabulary.")
            return np.random.rand(self.vector_size)
        sentence_vector = sum_vector / len(words_in_vocab)
        return sentence_vector
def infer_vector ( self , doc_words , warning = False ) : sum_vector = np . zeros ( self . vector_size ) words_in_vocab = [ ] for token in doc_words : try : sum_vector += self [ token ] words_in_vocab . append ( token ) except KeyError as e : if warning : logging . warning ( "" . join ( [ str ( e ) , ". Ignore the word." ] ) ) pass if len ( words_in_vocab ) == 0 : logging . warning ( "None of the words is in vocabulary." ) return np . random . rand ( self . vector_size ) sentence_vector = sum_vector / len ( words_in_vocab ) return sentence_vector
Average all the word-vectors together and ignore the unseen words
Arg:
doc_words (list): a list of tokenized words
Average all the word - vectors together and ignore the unseen words Arg : doc_words ( list ) : a list of tokenized words
"""
        Average all the word-vectors together and ignore the unseen words
        Arg:
            doc_words (list): a list of tokenized words
        Returns:
            a vector representing a whole doc/sentence
        """
a vector representing a whole doc/sentence
a vector representing a whole doc / sentence
self
doc_words
warning