feature_vector np add(feature_vectormodel[word]if nwordsfeature_vector np divide(feature_vectornwordsreturn feature_vector def averaged_word_vectorizer(corpusmodelnum_features)vocabulary set(model wv index wordfeatures [average_word_vectors(tokenized_sentencemodelvocabularynum_featuresfor tokenized_sentence in corpusreturn np array(featuresin [ ] v_feature_array averaged_word_vectorizer(corpus=tokenized_corpusmodel= v_modelnum_features=feature_sizepd dataframe( v_feature_arrayfigure - averaged word vector feature set for our corpus documents thuswe have our averaged word vector based feature set for all our corpus documentsas depicted by the dataframe in figure - let' use different clustering algorithm this time known as affinity propagation to try to cluster our documents based on these new features affinity propagation is based on the concept of message passing and you do not need to specify the number of clusters beforehand like you did in -means clustering in [ ]from sklearn cluster import affinitypropagation ap affinitypropagation(ap fit( v_feature_arraycluster_labels ap labels_ cluster_labels pd dataframe(cluster_labelscolumns=['clusterlabel']pd concat([corpus_dfcluster_labels]axis= out[ ]document category clusterlabel the sky is blue and beautiful weather love this blue and beautiful skyweather the quick brown fox jumps over the lazy dog animals