728x90
반응형
Bag of Words
- 단어의 출현 빈도에 집중해 텍스트를 수치화 하는 표현 방법이다.
- 기존에 학습된 단어를 기반으로 하기 때문에, 새로운 단어에 대한 처리가 어렵다.
- 띄어쓰기를 기반으로 하는 영어에는 적용이 간단하다면, 중국어나 일본어, 한국어 등에는 사용이 어렵다.
- scikit-learn의 CountVectorizer를 통해 쉽게 구현할 수 있다.
from sklearn.feature_extraction.text import CountVectorizer
vectorizer = CountVectorizer()
sentence = ["John likes to watch movies. Mary likes movies too."]
vectorized_sentence = vectorizer.fit_transform(sentence)
print(vectorized_sentence.toarray())
print(vectorizer.vocabulary_)
# [[1 2 1 2 1 1 1]]
# {'john': 0, 'likes': 1, 'to': 4, 'watch': 6, 'movies': 3, 'mary': 2, 'too': 5}
'ML_DL > 딥러닝 공부하기' 카테고리의 다른 글
머신러닝 VS 딥러닝 (0) | 2024.04.17 |
---|---|
Word Embedding (0) | 2024.01.08 |
Vanishing Gradient Problem(기울기 소실) (0) | 2023.11.28 |
전이학습 (Transfer Learning) (0) | 2023.10.17 |
[자연어처리] Word Embedding (1) | 2023.10.14 |