핵심 개념 (corpus·vector·model)

핵심 개념 (corpus·vector·model)

Gensim에는 세 가지 필수 개념이 있어요. 말뭉치(corpus), 벡터(vector), 모델(model)이죠. 텍스트를 어떻게 벡터로 바꾸고, 모델로 학습하는지 흐름을 잡는 게 중요해요.

세 가지 개념

  • Corpus: 문서들의 집합. 보통 단어-빈도 벡터의 스트림으로 표현돼요.
  • Vector: 문서나 단어를 숫자로 나타낸 표현.
  • Model: 말뭉치에서 학습해 벡터 공간을 변환하는 변환기.
from gensim import corpora, models

# 문서를 Bag-of-Words 코퍼스로 변환
dictionary = corpora.Dictionary(tokenized_docs)
corpus = [dictionary.doc2bow(doc) for doc in tokenized_docs]

# LDA 토픽 모델 학습
lda = models.LdaModel(corpus, num_topics=10)
print(lda.print_topics())

확인 포인트

  • 코퍼스는 메모리가 아니라 스트림으로 처리할 수 있어서 큰 데이터에도 적용돼요.
  • 사전(dictionary)으로 단어→ID 매핑을 만든 뒤 코퍼스를 만드는 순서예요.

출처: https://radimrehurek.com/gensim/auto_tutorials/core/1_core_concepts.html

더 알아보기