يحتوي هذا المستودع على البرامج النصية والمطالبات لورقة "TopicGpt: Topic Modeling من خلال دفع نماذج لغة كبيرة" (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 (يتطلب وحدات معالجة الرسومات للاستدلال). انظر 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 وتحميلها باستخدام:
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 )تعيين وتصحيح الموضوعات ، عادة مع نموذج أضعف في حالة استخدام واجهات برمجة التطبيقات المدفوعة لتوفير التكلفة:
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 لتقييم المحاذاة بين الموضوعات التي تم إنشاؤها وملصقات الحقيقة الأرضية (مؤشر RAND المعدل ، نقاء التوافقي ، والمعلومات المتبادلة الطبيعية).
@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}
}