Я схожу с ума! У меня возникла проблема с работой Gensim CoherenceModel с моей моделью BERTopic.
Я получаю сообщение об ошибке:
ValueError: невозможно интерпретировать тему как список токенов или список идентификаторов
Поэтому я вернулся к основам и позаимствовал блок кода, сгенерированный Второй пилот:
from gensim.models import CoherenceModel
from gensim.corpora import Dictionary
# Sample data
topic_tokens = [['word1', 'word2', 'word3'], ['word4', 'word5', 'word6']]
tweet_tokens = [['this', 'is', 'a', 'tweet'], ['another', 'tweet', 'here']]
# Create a dictionary
dictionary = Dictionary(tweet_tokens)
# Print the dictionary to verify
print("Dictionary:", dictionary.token2id)
# Create the CoherenceModel
coherence_model = CoherenceModel(topics=topic_tokens, texts=tweet_tokens, dictionary=dictionary, coherence='u_mass')
Этот простой блок кода также выдает ошибку ValueError!
Я использую gensim.версия 4.3.3< /p>
Есть идеи?
Я замаскировал путь к файлу, но вот информация Traceback:
Traceback (most recent call last):
File "C:\Users\....\venv\lib\site-packages\IPython\core\interactiveshell.py", line 3577, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 15, in
coherence_model = CoherenceModel(topics=topic_tokens, texts=tweet_tokens, dictionary=dictionary, coherence='u_mass')
File "C:\Users\....\venv\lib\site-packages\gensim\models\coherencemodel.py", line 214, in __init__
self.topics = topics
File "C:\Users\....\venv\lib\site-packages\gensim\models\coherencemodel.py", line 429, in topics
topic_token_ids = self._ensure_elements_are_ids(topic)
File "C:\Users\....\venv\lib\site-packages\gensim\models\coherencemodel.py", line 453, in _ensure_elements_are_ids
raise ValueError('unable to interpret topic as either a list of tokens or a list of ids')
ValueError: unable to interpret topic as either a list of tokens or a list of ids
Подробнее здесь: https://stackoverflow.com/questions/790 ... -a-list-of