Gensim: ValueError: не удалось создать намерение (кеш | скрыть) | необязательный массив должен иметь определенные размеры, но получил (0,)

Я пытаюсь эмулировать потоковую передачу для некоторых документов и обновлять LSI для дополнительных документов, передаваемых в потоковом режиме. Я нахожу эту ошибку:

Traceback (most recent call last):
  File "gensimStreamGen_tutorial5.py", line 57, in <module>
    for vector in corpus_memory_friendly: # load one vector into memory at a time
  File "gensimStreamGen_tutorial5.py", line 44, in __iter__
    lsi = models.LsiModel(corpus, num_topics=10) # initialize an LSI transformation
  File "/Users/Desktop/gensim-0.12.0/gensim/models/lsimodel.py", line 331, in __init__
    self.add_documents(corpus)
  File "/Users/Desktop/gensim-0.12.0/gensim/models/lsimodel.py", line 388, in add_documents
    update = Projection(self.num_terms, self.num_topics, job, extra_dims=self.extra_samples, power_iters=self.power_iters)
  File "/Users/Desktop/gensim-0.12.0/gensim/models/lsimodel.py", line 126, in __init__
    extra_dims=self.extra_dims)
  File "/Users/Desktop/gensim-0.12.0/gensim/models/lsimodel.py", line 677, in stochastic_svd
    q, _ = matutils.qr_destroy(y) # orthonormalize the range
  File "/Users/Desktop/gensim-0.12.0/gensim/matutils.py", line 398, in qr_destroy
    qr, tau, work, info = geqrf(a, lwork=-1, overwrite_a=True)
ValueError: failed to create intent(cache|hide)|optional array-- must have defined dimensions but got (0,)

Код для потоковой передачи документов и обновления модели LSI:

class MyCorpus(object):
    def __iter__(self):
        for document in documents:
            # Stream-in documents and build TF-IDF model to construct new_vec
            yield new_vec
            corpus.append(new_vec)
            tfidf = models.TfidfModel(corpus)
            corpus_tfidf = tfidf[corpus]
            lsi = models.LsiModel(corpus_tfidf,  num_topics=2)
            corpus_lsi = lsi[corpus_tfidf]
            lsi.print_topics(2)
            for doc in corpus_lsi:
                print(doc)

corpus_memory_friendly = MyCorpus()
for vector in corpus_memory_friendly:
    print(vector)

Корпус получает новый new_vec каждую итерацию. new_vec для каждого выхода для разных итераций:

[]
[(0, 1)]
[(1, 1), (2, 1), (3, 1)]
[(3, 2), (4, 1), (5, 1)]
[(2, 1), (6, 1), (7, 1)]
[]
[(8, 1)]
[(8, 1), (9, 1)]
[(9, 1), (10, 1), (11, 1)]

Ошибка появляется на первой итерации (первая строка в ожидаемом new_vec). Остальное — ожидаемый результат от new_vec.


person otayeby    schedule 20.07.2015    source источник
comment
Вам необходимо предоставить минимальный воспроизводимый образец, чтобы получить больше ответов, см. stackoverflow.com/help/mcve.   -  person Baris Demiray    schedule 20.07.2015
comment
Вы когда-нибудь решали это?   -  person user1761806    schedule 16.09.2017
comment
Да, это из-за пустых списков.   -  person otayeby    schedule 18.09.2017


Ответы (1)


Я думаю из-за ваших данных в документах пусто попробуйте добавить

if(document!=[]and document!=[[]])
person 蔡宇祥    schedule 01.02.2016