Skip to content

Latest commit

 

History

History
217 lines (189 loc) · 7.97 KB

README.md

File metadata and controls

217 lines (189 loc) · 7.97 KB

부스트캠프 4기 NLP 07조 염보라

Members

김한성 염성현 이재욱 최동민 홍인희
Github Github Github Github Github

Wrap up report

project report 바로가기

 

Open-Domain Question Answering(ODQA)

프로젝트 수행 기간

22/12/19 ~ 23/01/05

 

프로젝트 개요

Open-Domain Question Answering (ODQA) 은 주어지는 지문이 따로 존재하지 않고 사전에 구축되어있는 Knowledge resource 에서 질문에 대답할 수 있는 문서를 찾는 과정입니다. ODQA는 two-stage로 질문에 관련된 문서를 찾아주는 “retriever”, 관련된 문서를 읽고 적절한 답변을 찾아주는 “reader” 로 구성되어 있습니다. 두 가지 단계를 각각 구성하고 통합하여 어려운 질문을 던져도 답변을 해주는 ODQA 시스템을 만들고자 하였습니다.

 

데이터 설명

아래는 제공하는 데이터셋의 분포를 보여줍니다.

데이터셋은 Huggingface 에서 제공하는 datasets를 이용하여 pyarrow 형식의 데이터로 저장되어있습니다. data 폴더의 구성은 아래와 같습니다.
./data/                        # 전체 데이터
    ./train_dataset/           # 학습에 사용할 데이터셋. train 과 validation 으로 구성 
    ./test_dataset/            # 제출에 사용될 데이터셋. validation 으로 구성 
    ./wikipedia_documents.json # 위키피디아 문서 집합. retrieval을 위해 쓰이는 corpus.

data에 대한 argument 는 arguments.pyDataTrainingArguments 에서 확인 가능합니다.

 

프로젝트 세부 내용

Data

  • EDA
  • Preprocesisng
  • Data Augmentation

Retriever

  • BM25
  • Dense retriever
  • Poly encoder

Reader

  • Scheduler & Optimizer

Post processing

Ensemble

 

설치 방법

요구 사항

# data (51.2 MB)
tar -xzf data.tar.gz

# 필요한 파이썬 패키지 설치. 
bash install/install_requirements.sh

 

Train, Evaluation, Inference

# train, evaluation, inference를 통합하여 진행하고자 한다면, 아래 코드를 실행하세요.
python main.py

 

Train, Evaluation

train, evaluation에서 필요한 세팅은 config/config.yaml에서 해주세요. 설정해줘야 할 값들은 아래와 같습니다.

# config/config.yaml
data:
    data_path: /opt/ml/input/data
    dataset_name: /opt/ml/input/data/train_dataset # train data
    aug_path : ['squad_kor_v1', 'OTHER_PATH']      # 증강할 데이의 폴더를 입력하면 됩니다.
    overwrite_cache: False
    max_seq_length: 512
    pad_to_max_length: False
    doc_stride: 256
    max_answer_length: 30
    output_model_dir: ./models/model_output        # 파일 이름 변경하기

model:
    model_name: klue/roberta-large
    if_not_roberta: False           # bert는 True, roberta는 False
    huggingface_hub: True           # huggingface에 올리는건 True, 아니면 False

train:
    train_mode: True                # train 할 시, True로 설정
    seed: 42
    batch_size: 8
    epoch: 15
    lr : 1e-5
    weight_decay: 0.1
    warmup_ratio: 0.1
    logging_step: 100
    eval_step: 4000                 # eval step와 save step은 같이 바뀝니다.
    label_smoothing_factor: 0.1
    load_best_model_at_end: True
    gradient_accumulation_steps: 1
    optimizer_step_size: 8000       # 본인이 하는거에 맞춰서 주기 5 ~ 10정도에 맞게 설정하기

wandb:
    wandb_mode: True                # train 할 시, wandb 사용 유무 설정
    entity: mrc_bora
    project_name: testtest
    exp_name: robeta-large_kor1-2_aihub
# train, evaluation만 한다면
# train_mode = True, test_mode = False 설정
python main.py

 

Inference

inference에서 필요한 세팅은 config/config.yaml에서 해주세요. 설정해줘야 할 값들은 아래와 같습니다.

data:
    data_path: /opt/ml/input/data
    context_path: wikipedia_documents.json       # 위키피디아 문서 집합. retrieval을 위해 쓰이는 corpus.
    test_dataset_name: /opt/ml/input/data/test_dataset/  # 제출에 사용될 데이터셋. validation 으로 구성 
    overwrite_cache: False
    max_answer_length: 30
    eval_retrieval: True
    dense_retrieval: False              # dense retrieval 사용 시 True, sparse retrieval 사용 시 False
    num_clusters: 64
    top_k_retrieval: 40
    use_faiss: False                    # BM25의 경우 faiss를 사용하지 않습니다.
    output_model_dir: ./models/model_output     # 학습된 모델 경로 
    output_json_dir: ./outputs/output_pred/     # output predictions

model:
    model_name: klue/roberta-large      # 학습에 사용한 PLM name
    if_not_roberta: False               # bert는 True, roberta는 False

test:
    test_mode: True                     # inference 할 시, True로 설정
    BM25: True                          # BM25는 True, TF-IDF는 False

encoder:                                # dense encoder 설정
    model_name: klue/roberta-base
    epoch: 50
    batch_size: 16
    lr: 2e-5
    weight_decay: 0.01
    dense_train: False                  # encoder 학습 시, True
    faiss_gpu: False                    # faiss GPU 사용 시, True
    embedding_name: dense_embedding.bin
    encoder_postfix: test               # if dense_train == True
    load_encoder_path: test             # if dense_train == False
# inference만 한다면
# train_mode = False, test_mode = True 설정
python main.py

How to submit

inference 후, output_json_dir 위치에 predictions.json이라는 파일이 생성됩니다. 해당 파일을 제출해주세요.

 

프로젝트 구조

ODQA Project/
│
├── train.py 
├── train_sweep.py    ... for hyper parameter search
├── inference.py 
├── arguments.py
├── main.py
│
├── backup/ backup for baseline..
├── install/
│   └── install_requirements.sh
│
├── notebook/
│   ├── EDA_for_wikipedia.ipynb
│   ├── ...
│   └── squad.ipynb
│
│
├── config/ - abstract all config for model
│   ├── config.yaml
│   └── sweep_config.yaml
│
├── model/ 
│   ├── poly_encoder/ for poly , bi-encoder, cross encoder
│   ├── bm25.py
│   ├── sparse_retrieval.py -> compose TF-IDF, BM25
│   ├── dense_retrieval.py
│   ├── poly_retrieval.py
│   ├── encoder.py -> for DPR encoder
│   └── reader.py
│
├── trainer/ 
│   └── trainer.py  -> trian_qa.py 변형 및 통합
│
├── utils/ 
│   ├── load_data.py
│   ├── util_qa.py
│   └── util.py
│
│  
└── thanks for comming I'm Yeombora