0

同じ 10,000 個のドキュメント セットから 10,000 個のドキュメントのリストに関連するドキュメントを取得しようとしています。テストには、gensim lsi と gensim similarity の 2 つのアルゴリズムを使用しています。どちらもひどい結果をもたらします。どうすれば改善できますか?

from gensim import corpora, models, similarities
from nltk.corpus import stopwords
import re

def cleanword(word):
    return re.sub(r'\W+', '', word).strip()

def create_corpus(documents):

    # remove common words and tokenize
    stoplist = stopwords.words('english')
    stoplist.append('')
    texts = [[cleanword(word) for word in document.lower().split() if cleanword(word) not in stoplist]
             for document in documents]

    # remove words that appear only once
    all_tokens = sum(texts, [])
    tokens_once = set(word for word in set(all_tokens) if all_tokens.count(word) == 1)

    texts = [[word for word in text if word not in tokens_once] for text in texts]

    dictionary = corpora.Dictionary(texts)
    corp = [dictionary.doc2bow(text) for text in texts]

def create_lsi(documents):

    corp = create_corpus(documents)
    # extract 400 LSI topics; use the default one-pass algorithm
    lsi = models.lsimodel.LsiModel(corpus=corp, id2word=dictionary, num_topics=400)
    # print the most contributing words (both positively and negatively) for each of the first ten topics
    lsi.print_topics(10)

def create_sim_index(documents):
    corp = create_corpus(documents)
    index = similarities.Similarity('/tmp/tst', corp, num_features=12)
    return index
4

3 に答える 3

3

全然使ってないみたいcreate_lsi()?作成した LSI モデルを印刷するだけで済みます。

そして、その数字12num_features=12どこから来たのですか?num_features=len(dictionary)BOW ベクターnum_features=lsi.num_topics用、または LSI ベクター用のいずれかである必要があります。

LSIの前にTF-IDF変換を追加。

http://radimrehurek.com/gensim/tutorial.htmlでgensim のチュートリアルを確認してください。これらの手順について、コメント付きで詳しく説明しています。

于 2014-03-11T23:06:00.880 に答える
0

LSI はテキストデータの大規模なコーパスに使用されます。特異値分解を使用して、縮小されたスペースで関連する用語を含む行列を形成できます。ここgensimパッケージでは、上位n個の用語のみを返すことで、意味的に類似した上位の用語を取得できます。

lsimodel.print_topic(10, topn=5) ここで、10 はトピックの数、5 は各トピックの上位 5 つの用語を示します。

これにより、無関係な用語を減らすことができます。

于 2015-10-16T07:03:51.260 に答える