This is the official PyTorch implementation of paper CLUSTERLLM: Large Language Models as a Guide for Text Clustering (EMNLP2023).
pip install -r requirements.txt
Download zip file here and unzip.
cd perspective/2_finetune
bash scripts/get_embedding.sh
The embeddings are produced in each folder of datasets
. It will also save the clustering measures. Details instructions see bash script. E5 embeddings are produced with scripts/get_embedding_e5.sh
.
cd perspective/1_predict_triplet
bash scripts/triplet_sampling.sh
Sampled triplets will be produced in perspective/1_predict_triplet/sampled_triplet_results
. Details instructions see bash script.
First replace the openai keys in perspective/1_predict_triplet/scripts/predict_triplet.sh
.
cd perspective/1_predict_triplet
bash scripts/predict_triplet.sh
Predicted triplets will be in perspective/1_predict_triplet/predicted_triplet_results
. Details instructions see bash script.
This step only converts the format.
cd perspective/2_finetune
bash scripts/convert_triplet.sh
bash scripts/convert_triplet_self.sh
Converted triplets will be in perspective/2_finetune/converted_triplet_results
. Details instructions see bash script.
cd perspective/2_finetune
bash scripts/finetune.sh
Finetuned model will be in perspective/2_finetune/checkpoints
. Details instructions see bash script.
cd perspective/2_finetune
bash scripts/get_embedding.sh
This time, switch to checkpoints. Clustering measures will be saved into checkpoint folder.
cd granularity
bash scripts/sample_pairs.sh
Sampled pairs will be saved in sampled_pair_results
.
4 pairs will be sampled as in-context examples.
cd granularity
bash scripts/sample_pairs_for_prompt.sh
First replace the openai keys in granularity/scripts/predict_pairs.sh
.
cd granularity
bash scripts/predict_pairs.sh
Predicted pairs will be in granularity/predicted_pair_results
. Also specify prompt_file
to sampled the prompt.
cd granularity
bash scripts/predict_num_clusters.sh
Details instructions see bash script.
I have reduced the run for the whole pipeline into 2 bash scrips.
First, run create_output_folders.sh
once to create a list of emptied folder to store ouput of each step in the pipeline:
bash create_output_folders.sh
Then run the pipeline,
bash run_file.sh -i 3 -e 4
For the first run, please run the pipeline with a small number of epoch and iteration to test the pipline. The default iteration (-i) is 6 and epoch (-e) is 30.
IMPORTANT
Please run these 2 files in ClusterLLM or else the path's references in the bash files gonna be incorrect. For example:
cd ClusterLLM
bash run_file.sh
@misc{zhang2023clusterllm,
title={ClusterLLM: Large Language Models as a Guide for Text Clustering},
author={Yuwei Zhang and Zihan Wang and Jingbo Shang},
year={2023},
eprint={2305.14871},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
Some of the code was adapted from:
Yuwei Zhang [email protected]