ValueError: cannot compute mean with no input

182 views Asked by At
import spacy
nlp = spacy.load("en_core_web_lg") # if this fails then run "python -m spacy download en_core_web_lg" to download that model

def preprocess_and_vectorize(text):
    # remove stop words and lemmatize the text
    doc = nlp(text)
    filtered_tokens = []
    for token in doc:
        if token.is_stop or token.is_punct:
            continue
        filtered_tokens.append(token.lemma_)
        
    return glv.get_mean_vector(filtered_tokens)


df1['vector'] = df1['message'].apply(lambda message: preprocess_and_vectorize(message))

whenever i execute the last operation it is showing me error the error is

ValueError                                Traceback (most recent call last)
<ipython-input-13-acf3ff3d1ec8> in <cell line: 1>()
----> 1 df1['vector'] = df1['message'].apply(lambda message: preprocess_and_vectorize(message))

6 frames
/usr/local/lib/python3.9/dist-packages/gensim/models/keyedvectors.py in get_mean_vector(self, keys, weights, pre_normalize, post_normalize, ignore_missing)
    494         """
    495         if len(keys) == 0:
--> 496             raise ValueError("cannot compute mean with no input")
    497         if isinstance(weights, list):
    498             weights = np.array(weights)

ValueError: cannot compute mean with no input
df1['vector'] = df1['message'].apply(lambda message: preprocess_and_vectorize(message))

i want to execute this

0

There are 0 answers