하고자 하는 프로젝트에서는 주제처럼 추상적이고 포괄적인 keyword를 뽑는 것이 아니라, question에 대한 'answer'다.
즉 사용자 입장에서 '정답으로써 매력 있는 키워드'를 추출해야 하는 것이다.
KorQuAD
What is KorQuAD 2.0? KorQuAD 2.0은 KorQuAD 1.0에서 질문답변 20,000+ 쌍을 포함하여 총 100,000+ 쌍으로 구성된 한국어 Machine Reading Comprehension 데이터셋 입니다. KorQuAD 1.0과는 다르게 1~2 문단이 아닌 Wikipedia artic
korquad.github.io
KorQuAD dataset를 살펴볼 경우, 대상, 인물, 시간, 장소, 방법 등이 answer로 들어오는 것을 확인할 수 있었다.
내가 추출하는 Keyword는 Question Generation Model에 들어가는 Input이라는 것을 염두에 두어야 한다.
고민을 해보았는데, 개체명 인식으로 들어온 토큰들에서 정해둔 기준에 따라 keyword로 뽑아내는 것이 어떨까 하는 생각이 들었다.
인식된 개체가 없다면, KeyBERT로 다소 추상적일 수는 있지만 문서와 코사인 유사도가 높은 keyword를 뽑는 것으로 계획하고 있다.
https://github.com/eagle705/pytorch-bert-crf-ner
GitHub - eagle705/pytorch-bert-crf-ner: KoBERT와 CRF로 만든 한국어 개체명인식기 (BERT+CRF based Named Entity Recogn
KoBERT와 CRF로 만든 한국어 개체명인식기 (BERT+CRF based Named Entity Recognition model for Korean) - GitHub - eagle705/pytorch-bert-crf-ner: KoBERT와 CRF로 만든 한국어 개체명인식기 (BERT+CRF based Named Entity Recognition m...
github.com
해당 깃헙을 통해 Inference를 진행했다.
이를 수행하면서 겪은 여러 자잘한 오류를 어떻게 해결했는지 적겠다.
(python version 3.8 환경)
1. Requirements 설치할 때 버전 관련 여러 오류가 뜨는데, 시키는 대로 버전을 수정해주면 설치가 된다.
2. git에 올라와 있는 드라이브를 통해 bin file을 다운 받아 Inference를 실행한다.
3. state_dict missing key error 발생
RuntimeError: Error(s) in loading state_dict for KobertCRF:
Missing key(s) in state_dict: "bert.embeddings.position_ids", "crf.trans_matrix", "crf.start_trans", "crf.end_trans".
ney.py 파일을 아래와 같이 수정한다.
# from TorchCRF import CRF
from torchcrf import CRF
# self.crf = CRF(num_labels=num_classes)
self.crf = CRF(num_tags=num_classes, batch_first=True)
4. 그후 inference 실행시 RuntimeError 발생
RuntimeError: Error(s) in loading state_dict for KobertCRF:
Missing key(s) in state_dict: "bert.embeddings.position_ids".
inference 60번째 줄을 아래와 같이 수정한다.
# model.load_state_dict(convert_keys)
model.load_state_dict(convert_keys, strict=False)
5. 그후 inference 실행시 device 관련 Error 발생
RuntimeError: Input, output and indices must be on the current device
inference의 input 부분을 아래와 같이 수정한다.
x_input = torch.tensor(list_of_input_ids).long().to(torch.device('cuda'))
그러면 Inference를 성공적으로 할 수 있을 것이다.
'정보' 카테고리의 다른 글
Keyword Extraction (0) | 2023.01.09 |
---|---|
Ubuntu 환경 Elasticsearch 설치하기 (0) | 2023.01.07 |
Ubuntu 환경 mecab 설치하기 (0) | 2023.01.06 |
BeautifulSoup로 이미지 저장하기 (0) | 2022.09.24 |
Python과 몽고DB 연결 및 조회하기, 값 추출하기 (0) | 2022.09.04 |
댓글