In [ ]:
import gensim

texts = ["Human machine interface for lab abc computer applications",
         "A survey of user opinion of computer system response time",
         "The EPS user interface management system",
         "System and human system engineering testing of EPS",
         "Relation of user perceived response time to error measurement",
         "The generation of random binary unordered trees",
         "The intersection graph of paths in trees",
         "Graph minors IV Widths of trees and well quasi ordering",
         "Graph minors A survey"]

texts = [t.split() for t in texts]

def main():
    fcount = 5
    d = gensim.corpora.Dictionary(texts)
    c = [d.doc2bow(t) for t in texts]

    tfidf_model = gensim.models.TfidfModel(c, d, normalize=True)
    tfidf_corpus = tfidf_model[c]

    lsi_model = gensim.models.LsiModel(
        corpus=tfidf_corpus,
        id2word=d,
        num_topics=fcount)

    print lsi_model

    lsi_corpus = lsi_model[tfidf_corpus]

    msim = gensim.similarities.MatrixSimilarity(lsi_corpus,
num_features=fcount )
    sim = gensim.similarities.Similarity(None, lsi_corpus, fcount,
shardsize=2)

    msim.num_best = 1
    sim.num_best = 1

    qtext = ["human",  "system"]
    query = lsi_model[tfidf_model[d.doc2bow(qtext)]]

    a1 = msim[query]
    a2 = sim[query]
    print a1
    print a2
    assert a1 == a2

if __name__ == "__main__":
    main()