Python code runs endlessly in Rstudio Quarto but runs properly in VS Code Jupyter Notebook

I'm new to using reticulate to incorporate python into my R scripts. Running basic code chunks seems to work great, but if I try to incorporate model development, I've found that my code will run endlessly without producing an error message. Hitting the interrupt button doesn't stop it and I have to force quit R and start over. Reprex:

import gensim as gensim
from gensim import corpora, models, similarities, downloader

texts = [['human', 'interface', 'computer'],
         ['survey', 'user', 'computer', 'system', 'response', 'time'],
         ['eps', 'user', 'interface', 'system'],
         ['system', 'human', 'system', 'eps'],
         ['user', 'response', 'time'],
         ['trees'],
         ['graph', 'trees'],
         ['graph', 'minors', 'trees'],
         ['graph', 'minors', 'survey']]

# Create Dictionary
id2word = gensim.corpora.Dictionary(texts)

# Create Corpus: Term Document Frequency
corpus = [id2word.doc2bow(text) for text in texts]

# Create lda model
Lda = gensim.models.ldamodel.LdaModel
ldamodel = Lda(corpus, num_topics=2, id2word = id2word, iterations=50)

# Create coherence model
cm = gensim.models.coherencemodel.CoherenceModel(model=ldamodel, texts=texts, dictionary=id2word, coherence='c_v')

#get coherence - code gets hung up here
result = cm.get_coherence()

My memory usage still shows 50% unused.
I'm using R version 4.2.3, Quarto version 1.2, and Pythin 3.10.4

Does the code exectute correctly outside of R Markdown or Quarto context ? So not in a chunk, but in a console context ?

Thanks

Running in the console also does not work. I now have an open issue on github here

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.