추론을 하는 것조차도 익숙하지 않다보니 이렇게 하는게 맞는건가 머뭇거리게 되었고, 결국 동료들의 작업과 도움을 바탕으로 ainize/kobart-news 모델로 코드를 만들고 추론을 진행해볼 수 있었다.
from tqdm import tqdmfrom transformers import PreTrainedTokenizerFast, BartForConditionalGenerationimport torchimport pandas as pddevice = torch.device('cuda:0'if torch.cuda.is_available() else'cpu')# Load Model and Tokenizetokenizer = PreTrainedTokenizerFast.from_pretrained("ainize/kobart-news")model = BartForConditionalGeneration.from_pretrained("ainize/kobart-news")model.to(device)test = pd.read_csv('/content/drive/MyDrive/boostcamp/dacon/aihub-2021/test_data.csv')text_list =list(test.text)submission_csv = pd.read_csv('/content/drive/MyDrive/boostcamp/dacon/aihub-2021/sample_submission.csv')error_cnt =0for index, input_text inenumerate(tqdm(text_list)):if index in [4083,4913,5525,8788]:continuetry:#input_text = input_text[:2300] input_ids = tokenizer.encode(input_text, return_tensors="pt").to(device) summary_text_ids = model.generate( input_ids=input_ids, bos_token_id=model.config.bos_token_id, eos_token_id=model.config.eos_token_id, length_penalty=2.0, max_length=142, min_length=56, num_beams=4, ) submission_csv.summary[index]= tokenizer.decode(summary_text_ids[0], skip_special_tokens=True)except:print(f'index error {index}')passsubmission_csv.to_csv('/content/drive/MyDrive/boostcamp/dacon/aihub-2021/submission_1.csv')print('Job done')
처음에 알 수 없는 오류로 인해 추론이 중간중간 멈추는 현상을 겪게 되었다.
CUDA error: device-side assert triggered
CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.
이런 현상이 일어나는 데이터를 따로 빼내어 추론을 진행하였다. (4083, 4913, 5525, 8788)
처음에는 왜 저런 문제가 발생하는지 잘 모르겠었는데 해당 데이터들을 보니 문장의 길이가 매우 긴 것으로 확인할 수 있었다.
제출
1차 제출
ROUGE 평가를 생각해보니 summary를 진행하지 않고 그냥 text를 똑같이 입력해도 꽤 높은 점수가 나올 것 같다는 생각이 들었다.(종혁님께서 작업해서 제출해주심)
비슷한 생각을 가진 사람들이 있었는지 완전 동일한 점수가 몇몇 보였다 😂
2차 제출
train data는 따로 활용하지 않고, test data를 pre-trained 모델 ainize/kobart-news 을 활용하여 추론
같이 작업하고 있는 준혁님께서는 같은 모델의 test데이터에 text를 전처리 작업 (특수문자 제거, 공백 제거 등) 후에 추론을 진행하였는데 아래와 같이 결과를 얻을 수 있었다고 한다.
0.04나 차이나는거로 봐선 전처리를 하지 않는것이 오히려 좋은 성능을 내는 것인지 아님 단순히 랜덤 seed의 운인지 모르겠다...