Chapter 03 단어 임베딩을 사용하여 텍스트 유사성 계산하기

이 책은 (주)느린생각에서 'Deep Learning Cookbook' 책을 지원 받아 이 책을 교재로 스터디를 진행하였습니다. 이 글은 Deep Learning Cookbook의 3장 <단어 임베딩을 사용하여 텍스트 유사성 계산하기>를 실습을 목적으로 공부한 내용을 정리한 글입니다.
3장의 앞 부분은 다른 스터디원이 정리한 포스트를 참고해 주세요!
Chapter 3 : 단어 임베딩을 사용하여 텍스트 유사성 계산하기
Note : 이 포스터는 (주)느린생각의 지원을 받아 딥러닝 쿡북이라는 교재로 스터디를 하고 작성하는 포스터입니다. 이론은 딥러닝을 이용한 자연여 처리 입문(https://wikidocs.net/22660) 교재를 사용하였고 코드..
eda-ai-lab.tistory.com
Chatper 3.1 단어 임베딩 + 3.4 SVM 시각화 관련 포스트
Main
이 블로그의 내용은 DeepLearning Cookbook이라는 교재를 참고하여 작성한 글이며, 포스팅 목적은 해당 내용을 이해하고 실행할 수 있도록 도움을 주기 위함입니다. 부족한 부분은 관련 자료를 통해 설명을 하였습..
daljoong2.tistory.com
* 이전 포스터
Deep Learning Cookbook :: Chapter 03 단어 임베딩을 사용하여 텍스트 유사성 계산하기 (1)
3.4. 임베딩에서 개체의 클래스 찾기
이번 포스트에서는 챕터 3.4에 있는 실습 코드(GitHub 기준 3.2 Domain specific ranking using word2vec cosine distance)에 대해서 중점적으로 설명하였습니다. 몇 군데가 제대로 실행되지 않아서 버그를 잡느라 조금 고생했습니다.. 8ㅅ8
버그 1. figsize, geopandas, subprocess
버그 2. model 코드가 실행이 되지 않을 경우
1
|
model = gensim.models.KeyedVectors.load_word2vec_format(unzipped, binary=True)
|
cs |
이 코드를 실행하면 아래와 같은 오류가 났다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-4-57d69c358c77> in <module>
----> 1 model = gensim.models.KeyedVectors.load_word2vec_format(unzipped, binary=True)
~/.pyenv/versions/anaconda3-2.2.0/envs/myenv/lib/python3.7/site-packages/gensim/models/keyedvectors.py in load_word2vec_format(cls, fname, fvocab, binary, encoding, unicode_errors, limit, datatype)
1474 return _load_word2vec_format(
1475 cls, fname, fvocab=fvocab, binary=binary, encoding=encoding, unicode_errors=unicode_errors,
-> 1476 limit=limit, datatype=datatype)
1477
1478 def get_keras_embedding(self, train_embeddings=False):
~/.pyenv/versions/anaconda3-2.2.0/envs/myenv/lib/python3.7/site-packages/gensim/models/utils_any2vec.py in _load_word2vec_format(cls, fname, fvocab, binary, encoding, unicode_errors, limit, datatype)
383 with utils.ignore_deprecation_warning():
384 # TODO use frombuffer or something similar
—> 385 weights = fromstring(fin.read(binary_len), dtype=REAL).astype(datatype)
386 add_word(word, weights)
387 else:
ValueError: string size must be a multiple of element size
|
cs |
아무래도 문제는 전 줄에 있는 코드가 제대로 실행이 되지 않아 "generated" 폴더 안에 "GoogleNews-vectors-negative300.bin" 파일이 제대로 다운되지 않아서 생기는 문제같다.
1
|
path = get_file(MODEL + '.gz', 'https://s3.amazonaws.com/dl4j-distribution/%s.gz' % MODEL)
|
cs |
GitHub 기준 3.1 코드에 있는 링크는 아래와 같다. 링크는 다르나, 파일명이 같이 때문에 코드를 실행할 땐 굳이 파일을 다시 다운받지 않아도 될 것 같다.
path = get_file(MODEL + '.gz', 'https://deeplearning4jblob.blob.core.windows.net/resources/wordvectors/%s.gz' % MODEL)
이럴 경우,
- 파일을 불러오는 링크(https://deeplearning4jblob.blob.core.windows.net/resources/wordvectors/GoogleNews-vectors-negative300.bin.gz)에 직접 접속해서 파일을 다운받으면 된다. 제대로 다운받아진 경우, 파일 크기는 약 3.5G이다.
- 파일 위치는 "generated" 폴더 하위로 이동하며,
- 파일 이름은 "GoogleNews-vectors-negative300.bin"으로 변경하면 된다.
SVM을 활용할 수 있는 sklearn 라이브러리 특징
- n_support_: 각 클래스의 서포트의 개수
- support_: 각 클래스의 서포트의 인덱스
- support_vectors_: 각 클래스의 서포트의 x 값. 𝑥+ 와 𝑥−
- coef_: 𝑤 벡터
- intercept_: −𝑤0
- dual_coef_: 각 원소가 𝑎𝑖⋅𝑦𝑖 로 이루어진 벡터
참고 아티클
'20. 인공지능과 딥러닝' 카테고리의 다른 글
Deep Learning Cookbook :: 06 (0) | 2019.05.01 |
---|---|
Deep Learning Cookbook :: 04 위키피디아 외부 링크를 이용한 추천 시스템 구축 (0) | 2019.04.06 |
Deep Learning Cookbook :: Chapter 03 단어 임베딩을 사용하여 텍스트 유사성 계산하기 (1) (0) | 2019.03.10 |
[논문리뷰] DeepMind의 AlphaGO 논문 톺아보기 (1) | 2019.02.06 |
[딥러닝개념] 딥러닝 효과적으로 학습하기(2) (ft. regularization) (0) | 2019.01.13 |
댓글