> ## Content Index
> Fetch the complete content index at: https://bongholee.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Gensim 기본 LDA 대신, Mallet LDA 사용시 몇가지 이슈 대처법
- URL: https://bongholee.com/mallet-modele-pyldavis-sayongsi-ldamallet-object-has-no-attribute-inference/
- Published: 2022-05-29T06:20:44.000Z
- Updated: 2022-05-29T06:20:44.000Z
- Author: Bongho Lee
- Tags: Data, #Import 2026-11-22 06:32

**1.pyLDAvis 사용하려고 할 때 Inference 에러 발생시**

다음과 작성했는데, 다음과 같은 에러가 발생할 경우가 있다.

```
pyLDAvis.enable_notebook()
vis = pyLDAvis.gensim.prepare(mallet_model, corpus, id2word)
vis
```

```shell
'LdaMallet' object has no attribute 'inference'
```

Mallet Model은 gensim 기본 모델로 변환해서 사용하면 정상적으로 사용할 수 있다.

```python
import gensim    
model = gensim.models.wrappers.ldamallet.malletmodel2ldamodel(mallet_model)
```

**2.get\_document\_topics()을 Mallet Model에서 사용하고 싶을 때**

다음과 같이 작성해서 만들 수 있다.

```python
tm_results = lda_model[corpus]

document_topic_matrix = pd.DataFrame.from_records([{v: k for v, k in row} for row in tm_results])
document_topic_matrix.columns = ['Topic ' + str(i) for i in range(0,n_topics)]
print(document_topic_matrix.shape)
document_topic_matrix.head()
```