พื้นที่เก็บข้อมูลนี้มีสคริปต์และแจ้งเตือนสำหรับกระดาษของเรา "TopicGpt: การสร้างแบบจำลองหัวข้อโดยการแจ้งรูปแบบภาษาขนาดใหญ่" (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 สำหรับไปป์ไลน์ที่สมบูรณ์และคำแนะนำโดยละเอียดเพิ่มเติม เราแนะนำให้คุณลองใช้งานชุดย่อยที่มีโมเดล (หรือโอเพ่นซอร์ส) ราคาถูกกว่าก่อนที่จะปรับขนาดเป็นชุดข้อมูลทั้งหมด
(ไม่บังคับ) กำหนดเส้นทาง I/O ใน config.yml และโหลดโดยใช้:
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}
}