Embedding

사람이 사용하는 언어(자연어)를 컴퓨터가 이해할 수 있는 언어(숫자) 형태인 벡터로 변환한 결과 혹은 일련 과정

1️⃣ 희소 표현 기반 임베딩; sparse representation

One-hot Encoding

N개의 단어를 각 N차원의 벡터로 표현하는 방식 단어가 포함된 위치에 1, 나머지에 0

2️⃣ 횟수 기반 임베딩

Bag of words, CounterVector

문서 집합에서 단어를 토큰으로 생성하고 각 단어의 출현 빈도수를 이용하여 인코딩해서 벡터를 만드는 방법 즉, 토크나이징과 벡터화가 동시에 가능

스크린샷 2023-08-18 오전 12.24.01.jpg

corpus = ["When I'm away from you, I miss your touch (ooh)",
        "You're the reason I believe in love",
        "It's been difficult for me to trust (ooh)",
        "And I'm afraid that I'ma fuck it up",
        "Ain't no way that I can leave you stranded",
        "'Cause you ain't never left me empty-handed",
        "And you know that I know that I can't live without you"]

from sklearn.feature_extraction.text import CountVectorizer

vectorizer = CountVectorizer()
vectorizer.fit(corpus)
vectorizer.vocabulary_

TF-IDF