topicGPT
v0.2.2 Removed redundant parameters
이 저장소에는 논문의 스크립트와 프롬프트가 포함되어 있습니다. "TopicGpt : 대형 언어 모델을 프롬프트하여 주제 모델링"(NAACL'24). 우리의 topicgpt_python 패키지는 5 가지 주요 기능으로 구성됩니다.
generate_topic_lvl1 높은 수준의 일반화 가능한 주제를 생성합니다.generate_topic_lvl2 각 하이 레벨 주제에 낮은 수준의 특정 주제를 생성합니다.refine_topics 유사한 주제를 병합하고 관련없는 주제를 제거하여 생성 된 주제를 개선합니다.assign_topics 생성 된 주제를 할당을 지원하는 견적과 함께 입력 텍스트에 생성 된 주제를 할당합니다.correct_topics 최종 주제 할당이 주제 목록에 기반되도록 모델을 재 포착하여 생성 된 주제를 수정합니다. 
topicgpt_python 출시되었습니다! pip install topicgpt_python 통해 설치할 수 있습니다. OpenAI API, Vertexai, Azure API, Gemini API 및 VLLM을 지원합니다 (추론을위한 GPU 필요). PYPI를 참조하십시오. pip install topicgpt_python
# Run in shell
# Needed only for the OpenAI API deployment
export OPENAI_API_KEY={your_openai_api_key}
# Needed only for the Vertex AI deployment
export VERTEX_PROJECT={your_vertex_project} # e.g. my-project
export VERTEX_LOCATION={your_vertex_location} # e.g. us-central1
# Needed only for Gemini deployment
export GEMINI_API_KEY={your_gemini_api_key}
# Needed only for the Azure API deployment
export AZURE_OPENAI_API_KEY={your_azure_api_key}
export AZURE_OPENAI_ENDPOINT={your_azure_endpoint}
.jsonl 데이터 파일을 준비하십시오. {
" id " : " IDs (optional) " ,
" text " : " Documents " ,
" label " : " Ground-truth labels (optional) "
}data/input 에 넣으십시오. 코드를 디버깅하는 샘플 데이터 파일 data/input/sample.jsonl . 완전한 파이프 라인 및보다 자세한 지침은 demo.ipynb 확인하십시오. 전체 데이터 세트로 확장하기 전에 먼저 저렴한 (또는 오픈 소스) 모델을 사용하여 하위 집합에서 실행하는 것이 좋습니다.
(선택 사항) config.yml 에서 I/O 경로를 정의하고 다음을 사용하여로드하십시오.
import yaml
with open ( "config.yml" , "r" ) as f :
config = yaml . safe_load ( f )패키지로드 :
from topicgpt_python import *높은 수준의 주제 생성 :
generate_topic_lvl1 ( api , model , data , prompt_file , seed_file , out_file , topic_file , verbose )저수준 주제 생성 (선택 사항)
generate_topic_lvl2 ( api , model , seed_file , data , prompt_file , out_file , topic_file , verbose )중복 근처를 병합하고 낮은 주파수 (선택 사항)로 주제를 제거하여 생성 된 주제를 개선합니다.
refine_topics ( api , model , prompt_file , generation_file , topic_file , out_file , updated_file , verbose , remove , mapping_file )유료 API를 사용하여 비용을 절약하는 경우 일반적으로 약한 모델로 주제를 할당하고 수정하십시오.
assign_topics (
api , model , data , prompt_file , out_file , topic_file , verbose
) correct_topics(
api, model, data_path, prompt_path, topic_path, output_path, verbose
)
샘플 출력에 대한 data/output 폴더를 확인하십시오.
또한 생성 된 주제와지면 진실 레이블 (조정 된 RAND 인덱스, 고조파 순도 및 정규화 된 상호 정보) 간의 정렬을 평가하기 위해 topicgpt_python.metrics 에서 메트릭 계산 기능을 제공합니다.
@misc{pham2023topicgpt,
title={TopicGPT: A Prompt-based Topic Modeling Framework},
author={Chau Minh Pham and Alexander Hoyle and Simeng Sun and Mohit Iyyer},
year={2023},
eprint={2311.01449},
archivePrefix={arXiv},
primaryClass={cs.CL}
}