0

Am trying to perform Avg-Word2Vec for a text corpus. And I have created the class for it as:

class W2V:

final_vectors = [];

def __init__(self, review):
    self.review = review        

def w2v_vec(self):
    for sent in self.review: # for each review/sentence
        word_vec = np.zeros(50)
        words_count = 0; # num of words with a valid vector in the sentence/review
        for word in sent: # for each word in a review/sentence
            if word in w2v_words:
                vec = w2v_model.wv[word]
                word_vec += vec
                words_count += 1          
        if words_count != 0:
            word_vec /= words_count   

        return W2V.final_vectors.append(word_vec)

And am trying it use this as :

x_train_ = W2V(x_train_sent)

x_train_w2v = x_train_.w2v_vec()

print(len(x_train_w2v))

But upon calling the class method am ending up with error as object of None type has no len(). I do given a search and understood that the function is returning a None value. But I don't know how to modify that so that I can get a text vector output when I am calling this class method with the list of split sentences.

Dale K
  • 25,246
  • 15
  • 42
  • 71
ranjith
  • 11
  • 1

0 Answers0