topicGPT
v0.2.2 Removed redundant parameters
該存儲庫包含我們的論文“主題遊戲:主題建模來提示大型語言模型”的提示(NAACL'24)。我們的topicgpt_python軟件包由五個主要功能組成:
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文件夾。
我們還提供了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}
}