How to use Non Negative Matric Factorization (NMF)'s transform method to project topics on new text data I have created a NMF topic model in python the code snippet for which is as follows:

def select_vectorizer(req_ngram_range=[1,2]):
    ngram_lengths = req_ngram_range
    vectorizer = TfidfVectorizer(analyzer='word', ngram_range=(ngram_lengths), stop_words='english', min_df=2)
    #print("User specified custom stopwords: {} ...".format(str(custom_stopwords)[1:-1]))
    return vectorizer

vectorizer = select_vectorizer([2,5])
X = vectorizer.fit_transform(new_review_list)


clf = decomposition.NMF(n_components=20, random_state=3, alpha = .1).fit(X)
vocab = vectorizer.get_feature_names()
print_top_words(clf, vocab, num_top_words)


which created 20 topics like the following:

Topic #0:
[u'blocks available', u'delivery blocks available', u'notifications blocks', u'notifications blocks available', u'new blocks', u'know blocks available', u'new blocks available', u'know blocks', u'open blocks available', u'available work', u'zero blocks', u'like blocks', u'notification blocks', u'day blocks', u'slow blocks', u'10 blocks', u'option set', u'logged 10', u'notification blocks available', u'day blocks available']
Topic #1:
['something', 'something'] and so on..


Now I want to supply new text data to this fitted NMF model such that the model tells us which topic this new text belongs to. I have searched a lot, somebody suggested using "transform", but I do not know how to use it. For eg: if I have a new text, like:

new_feedback = "This is a new tester feedback"


Then how do I find which topic out of the 20 topics created earlier, does this new_feedback fall into? Please help!!

UPDATE: On trying to do what's mentioned in the below comment, I receive the following error:

clf.transform(vectorizer.transform(new_feedback))
  File "/usr/local/lib/python2.7/site-packages/sklearn/feature_extraction/text.py", line 1380, in transform
    X = super(TfidfVectorizer, self).transform(raw_documents)
  File "/usr/local/lib/python2.7/site-packages/sklearn/feature_extraction/text.py", line 884, in transform
    "Iterable over raw text documents expected, "
ValueError: Iterable over raw text documents expected, string object received.
This is how you should get your topics and corresponding words. You first get the NMF transformation of your new input and sort its components. The biggest components tell you which features to look at in nmf.components_, which links topics to words (your tfidf features). Finally, you print the k most important words of the topics. Topics and words scores are just calculated by dividing their value by the sum of all values.  

    import numpy as np
    # Transform new_feedback to NMF space
    nmf_new_feedback = clf.transform(vectorizer.fit(new_feedback))
    # top 10 topics of the new feedback
    compo = np.argsort(nmf_new_feedback)[-10:][::-1]
    # Connection between indices and words of tfidf
    feature_names = vectorizer.get_feature_names()
    for topic_idx in compo:
        # Current nmf topic
        topic = nmf.components_[topic_idx]
        print("Topic number: ", topic_idx)
        print("Topic score: ", nmf_new_feedback[topic_idx]/sum(nmf_new_feedback))
        # Top 15 words of current topic
        for k in topic.argsort()[-15:][::-1]]
            print("Word: ",feature_names[k], "  Score: ", topic[k]/ sum(topic))