728x90

gpt-2-keyword-generation


https://github.com/minimaxir/gpt-2-keyword-generation

Usage

keyword_encode.py : 비지도 방식으로 키워드 추출, 직접 우리만의 키워드 제공도 가능

• Manual keywords may work better if you have them, which you can set with the keywords_field parameter to encode_keywords().

  • 생성한 keywords와 파일의 title을 포함하는 txt 파일을 출력함.
  1. 각 문서로부터 키워드 “keywords” 추출 (spaCy 활용)
    → 키워드 토큰화 & 품사 태깅
    • 명사, 동사, 형용사, 부사만 추출 가능
    • 명사는 그대로, 다른 품사는 lemmatizd된 버전으로
    • 고유명사, named-entities, 합성어 모두 개별 명사로 취급
    • 대명사와 불용어는 키워드에서 제외
    • 키워드 추출 시 중복 제거
  2. 키워드 추출 시, 해당 키워드를 기반으로 새로운 텍스트가 생성되기 쉽도록 해야 함.
    • 키워드 정규화 (전처리), 대소문자 구분
    • 키워드 섞기 (모델이 키워드 간 순서를 학습하여 텍스트 생성에 활용하는 것을 막음)
    • 문서의 키워드 셋이 만들어지면 → repeat random combination을 생성
      : data augmentation of sorts & 해당 키워드에의 과적합 방지
    • 각 combination에 대해, max_keywords 이하로 랜덤 숫자 지정 → 섞기
      : 신경망이 키워드 개수를 기반으로 텍스트 길이를 추측한다거나 키워드의 순서를 학습하는 것을 방지
  3. Write the keywords, then the document for each generated set of keywords

keyword_decode.py

  • bulk-generated encoded texts를 decode하는 함수 포함.
  • decode_texts() : 제공된 텍스트에 대해, specify된 분류 섹션으로부터 텍스트를 추출
  • decode_file(): 모든 텍스트를 추출, 디코딩하고 file로 작성해줌.

Taxanomy

category, keywords, title, body

category : 가장 넓은 범위
body: blog post처럼 title에 의존하는 큰 규모의 텍스트가 있을 때 사용

~로 섹션 구분

<|startoftext>~ `키워드 ~ ^타이틀 ~ @body <|endoftext>


Notes

  • There should be an equal amount of all unique category documents to prevent sampling bias.
  • 텍스트 분량 제한: The scope of the text document(s) plus the keywords must be within GPT-2's max 1023 token scope (e.g. should only be a few paragraphs max).

오답노트

(keyword2) C:\Users\동그리\Desktop\gpt-2-keyword-generation-master>
  • git clone
  • 반드시 가상환경에서!
  • 파이썬 버전 여러 개 깔 수 있음
  • 가상환경에서 특정 파이썬 버전 지정 (특정 버전 이상만 요구 or 이하만 요구하는 게 있음, 내가 사용하는 것은 무슨 버전 요구하는지 파악하기)

pip3 install -r requirements.txt의 특정 spacy 설치의 문제점.


Parts-of-speech = POS = 품사
taxonomic: 분류의
taxonomy: 분류학, 분류
delimit: 구분선을 만들다, 구분짓다

728x90

'AI > NLP' 카테고리의 다른 글

ChatGPT란?  (0) 2022.12.11
키워드 기반 텍스트 생성  (0) 2022.04.07

+ Recent posts