def prepare_index(dictionary, model, tfidf, documents): if not os.path.isfile('soft_cosine.index'): similarity_index = WordEmbeddingSimilarityIndex(model.wv) similarity_matrix = SparseTermSimilarityMatrix(similarity_index, dictionary, tfidf) index = SoftCosineSimilarity( tfidf[[dictionary.doc2bow(document) for document in documents]], similarity_matrix) index.save('soft_cosine.index') return SoftCosineSimilarity.load('soft_cosine.index')
# dictionary, index and article_ids are used if past_behavior (SoftCosine) recommender is used try: lda_model = gensim.models.LdaModel.load("put path to model here") except: lda_model = None try: lda_dict = gensim.corpora.Dictionary.load("/put path to dict here") except: lda_dict = None try: dictionary = gensim.corpora.Dictionary.load("put path to dict here") except: dictionary = None try: index = SoftCosineSimilarity.load('put path to index here') except: index = None try: article_ids = pickle.load(open('put path to article ids here', 'rb')) except: article_ids = None login.login_view = 'login' if not app.debug: if app.config['MAIL_SERVER']: auth = None if app.config['MAIL_USERNAME'] or app.config['MAIL_PASSWORD']: auth = (app.config['MAIL_USERNAME'], app.config['MAIL_PASSWORD']) secure = None if app.config['MAIL_USE_TLS']: