Bag of Words
๋จ์ด ๋ฐ ๋ฌธ์๋ฅผ ์ซ์ํํ๋ก ๋ํ๋ด๋ ๊ฐ์ฅ ๊ฐ๋จํ ๊ธฐ๋ฒ์ผ๋ก์
TextMining ๋ถ์ผ์์ ๋ฅ๋ฌ๋ ๊ธฐ์ ์ด ์ ์ฉ๋๊ธฐ ์ด์ ์ ๋ง์ด ํ์ฉ๋๋ ๋ฐฉ์์ด๋ผ๊ณ ํ๋ค.
Step 1. Constructing the vocabulary containing unique words
Example sentences: "John really really loves this movie", "Jane really likes this song"
์ด ๋ฌธ์ฅ์์ really์ this๋ ์ค๋ณต๋๊ธฐ์ ํ ๋ฒ๋ง ํฌํจํ๋ฉด ๋๋ค.
Vocabulary: {"John", "really", "loves", "this", "movie", "Jane", "likes", "song"}
Step 2. Encoding unique words to one-hot vectors(One-hot ์ธ์ฝ๋ฉ)
Vocabulary: {"John", "really", "loves", "this", "movie", "Jane", "likes", "song"}
John: [1 0 0 0 0 0 0 0]
really: [0 1 0 0 0 0 0 0]
loves: [0 0 1 0 0 0 0 0]
this: [0 0 0 1 0 0 0 0]
movie: [0 0 0 0 1 0 0 0]
Jane: [0 0 0 0 0 1 0 0]
likes: [0 0 0 0 0 0 1 0]
song: [0 0 0 0 0 0 0 1]
์ด๋ฐ ์์ผ๋ก ๊ฐ ๋จ์ด๋ฅผ One-hot vector๋ก ๋ง๋ค์ด์ค๋ค.
์ด๋, ๊ฐ ๋จ์ด์ ์ ์ฌ๋ ์ธก์ ์ ๋ค์๊ณผ ๊ฐ์ ๋ ๊ฐ์ง ๋ฐฉ๋ฒ์ผ๋ก ํ ์ ์๋ค.
1. ์ ํด๋ฆฌ๋ ๊ฑฐ๋ฆฌ (Euclidean Distance)
2. ์ฝ์ฌ์ธ ์ ์ฌ๋ (Cosine Similarity)
1. Euclidean Distance Similarity
๊ฑฐ๋ฆฌ๊ฐ ์งง์ผ๋ฉด ์ ์ฌ๋๊ฐ ๋ ๋๋ค๋ผ๊ณ ํ๋จํ๋ ์ ์ฌ๋ ์ธก์ ๋ฐฉ๋ฒ์ด๋ค.(L2 Norm)
2. Cosine Similarity
๋จ์ด์ ์๊ฐ ๋์ด๋๋ฉด ์ค์ ์ ๋ต์ ๋ชจ์๋๋ ๊ฒฐ๊ณผ๊ฐ ๋์ฌ ๋๊ฐ ์๋ค.
์ด ๋ถ๋ถ์ ํด๊ฒฐํ ์ ์๋ ๊ฒ์ด ๋ฒกํฐ์ ํฌ๊ธฐ๋ฅผ ๋ฌด์ํ๊ณ ์ ์ฌ๋๋ฅผ ์ธก์ ํ๋ ์ฝ์ฌ์ธ ์ ์ฌ๋์ ์ฅ์ ์ด๋ค.
๋ฒกํฐ์ ๋ฒกํฐ ๊ฐ์ ์ ์ฌ๋๋ฅผ ๋น๊ตํ ๋ ๋ ๋ฒกํฐ ๊ฐ์ ์ฌ์๊ฐ์ ๊ตฌํด์ ์ผ๋ง๋ ์ ์ฌํ์ง ์์น๋ก ๋ํ๋ธ๋ค.
๋ฒกํฐ ๋ฐฉํฅ์ด ๋น์ทํ ์๋ก ๋ ๋ฒกํฐ๋ ์๋ก ์ ์ฌํ๋ฉฐ, ๋ฒกํฐ ๋ฐฉํฅ์ด 90๋ ์ผ๋๋ ๋ ๋ฒกํฐ ๊ฐ์ ๊ด๋ จ์ฑ์ด ์์ผ๋ฉฐ, ๋ฒกํฐ ๋ฐฉํฅ์ด ๋ฐ๋๊ฐ ๋ ์๋ก ๋ ๋ฒกํฐ๋ ๋ฐ๋ ๊ด๊ณ๋ฅผ ๋ณด์ธ๋ค.
์ฐธ๊ณ : https://sy-programmingstudy.tistory.com/13
์์์ ์์ฑํ ๋ฒกํฐ๋ฅผ ๊ธฐ์ค์ผ๋ก ํ๋์ ๋ฌธ์ฅ/๋ฌธ์๋ฅผ One-hot ๋ฒกํฐ๋ก ํํํ ์ ์๋ค.
"John really really loves this movie" => John + really + really + loves + this + movie => [1 2 1 1 1 0 0 0]
"Jane really likes this song" => Jane + really + likes + this + song => [0 1 0 1 0 1 1 1]