이것은 ACL 2023 조사 결과 논문 재생의 코드 리포입니다. 진보적 인 조밀 한 검색으로 교육 데이터 생성을 통한 제로 샷 텍스트 분류.
업데이트 : 최근 코드를 사용한 대형 언어 모델을 사용하여 레지전을 개선하는 방법을 확인하십시오!
python 3.8
transformers==4.2.0
pytorch==1.8.0
scikit-learn
faiss-cpu==1.6.4
tqdm>=4.62.2
nltk
코퍼스는 다음에서 다운로드 할 수 있습니다.
{Ag News, DBPedia, Yahoo, IMDB}의 테스트 세트는 Huggingface Data Hub에서 쉽게 찾을 수 있습니다. 다른 데이터 세트의 테스트 세트는 test 폴더에서 기반 할 수 있습니다.
_id 클래스 ID를 나타내고 text 문서의 내용입니다.
예제 (SST-2 데이터 세트의 경우) :
{
{"_id": 0, "text": "It seems to me the film is about the art of ripping people off without ever letting them consciously know you have done so."}
{"_id": 0, "text": "In the end , the movie collapses on its shaky foundation despite the best efforts of director joe carnahan."}
{"_id": 1, "text": "Despite its title , punch-drunk love is never heavy-handed ."}
{"_id": 1, "text": "Though only 60 minutes long , the film is packed with information and impressions."}
...
}
우리는 전례를 위해 Coco-DR의 코드를 조정합니다. 자세한 내용은 원래 구현을 확인하십시오.
2023 년 9 월 7 일에 업데이트 : 포옹 페이스에서 사전 취사 모델이 출시되었습니다.
자세한 내용은 retrieval 폴더 gen_embedding.sh 의 코드를 참조하십시오.
자세한 내용은 retrieval/retrieve.py 의 코드를 참조하십시오.
일부 주요 하이퍼 파라미터 :
args.target : 실험에 사용 된 대상 데이터 세트.args.model :이 연구에 사용 된 검색 모델.args.corpus_folder/args.corpus_name : 실험에서 사용 된 코퍼스 (예 : Wiki)의 폴더/이름.args.topN : KNN 검색에 사용되는 Topn (일반적으로 50-100으로 설정).args.round : 검색 라운드. 첫 번째 라운드에 대해 0으로 설정하십시오 (검색만을위한 레이블 이름/템플릿 사용) 및 1,2, ... 이후 라운드.참고 : 원칙적으로, 우리의 모델은 (적절한 훈련 후) 밀도가 높은 리트리버와 호환됩니다. 고유 한 짙은 검색 모델을 사용하려면 조밀 한 검색 모델이 [CLS] 토큰을 시퀀스 임베딩으로 포함시키는 것도 사용해야합니다. 그렇지 않으면 생성 된 임베딩이 올바른지 확인하기 위해 생성 부품을 포함시켜 코드를 수정해야 할 수도 있습니다.
filter 폴더의 코드를 참조하십시오. 예제 명령은이어야합니다
train_cmd="CUDA_VISIBLE_DEVICES=0 python3 inference.py --task=${task}
--unlabel_file=${unlabel_file_used_for_filtering}
--data_dir=${folder_for_data}
--cache_dir="${task}/cache" --output_dir=${output_dir} --round=${round}
--load_from_prev=1
--gpu=${gpu} --eval_batch_size=${eval_batch_size}
--max_seq_len=${max_seq_len} --auto_load=0
--model_type=${model_type}"
echo $train_cmd
eval $train_cmd
여기
folder_for_data 는 검색된 데이터의 폴더입니다.unlabel_file_used_for_filtering 검색된 데이터의 파일 이름입니다.task 작업의 이름입니다.model_type 판별 자 (예 : Roberta)로 사용되는 PLM입니다. classification 폴더의 코드를 참조하십시오. 예제 명령은이어야합니다
train_cmd="CUDA_VISIBLE_DEVICES=0 python3 main.py --do_train --do_eval --task=${task}
--train_file={PATH_FOR_GENERATED_DATASET}
--dev_file={PATH_FOR_GENERATED_VALID_DATASET
--test_file={PATH_FOR_TEST_DATASET
--unlabel_file=unlabeled.json
--data_dir=../datasets/${task}-${label_per_class} --train_seed=${train_seed}
--cache_dir="../datasets/${task}-${label_per_class}/cache"
--output_dir=${output_dir}
--logging_steps=${logging_steps}
--n_gpu=${n_gpu} --num_train_epochs=6
--learning_rate=2e-5 --weight_decay=1e-8
--batch_size=32 --eval_batch_size=128
--max_seq_len=128 --auto_load=1
--model_type=${model_type}"
echo $train_cmd
eval $train_cmd
이전 검색 단계와 비슷한 방식으로 달성됩니다. 자세한 내용은 retrieval/retrieve.py 의 코드를 다시 참조하십시오. 유일한 차이점은 변수 args.round 0 보다 큰 것으로 설정해야한다는 것입니다. 또한 필터링 후 최신 검색 결과를 위해 prev_retrieve_path_name 및 prev_retrieve_folder 문서 경로로 설정해야합니다.
생성 된 데이터 세트는이 링크에서 찾을 수 있습니다.
이 레포가 연구에 유용하다고 생각되면 신문을 친절하게 인용하십시오. 감사해요!
@inproceedings{yu2023zero,
title={ReGen: Zero-Shot Text Classification via Training Data Generation with Progressive Dense Retrieval},
author={Yu, Yue and Zhuang, Yuchen and Zhang, Rongzhi and Meng, Yu and Shen, Jiaming and Zhang, Chao},
booktitle={Findings of ACL},
year={2023}
}