> For the complete documentation index, see [llms.txt](https://lswkim322.gitbook.io/til/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lswkim322.gitbook.io/til/til-ml/competition/2021/undefined/day2-9.29.md).

# Day2 (9.29, 수)

* ✔ hugging face 모델가져와서 추론해보기
* ❌ fine-tuning 해보기
* ✔ 제출하기

추론을 하는 것조차도 익숙하지 않다보니 이렇게 하는게 맞는건가 머뭇거리게 되었고, 결국 동료들의 작업과 도움을 바탕으로 ainize/kobart-news 모델로 코드를 만들고 추론을 진행해볼  수 있었다.

```python
from tqdm import tqdm
from transformers import PreTrainedTokenizerFast, BartForConditionalGeneration
import torch
import pandas as pd

device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')

#  Load Model and Tokenize
tokenizer = 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 = 0

for index, input_text in enumerate(tqdm(text_list)):
    if index in [4083, 4913, 5525, 8788]:
        continue

    try:
        #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}')
        pass

submission_csv.to_csv('/content/drive/MyDrive/boostcamp/dacon/aihub-2021/submission_1.csv')

print('Job done')
```

* 처음에 알 수 없는 오류로 인해 추론이 중간중간 멈추는 현상을 겪게 되었다.&#x20;

```
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)
* 처음에는 왜 저런 문제가 발생하는지 잘 모르겠었는데 해당 데이터들을 보니 문장의 길이가 매우 긴 것으로 확인할 수 있었다.&#x20;

![](/files/-MklwnypG-7JFSZu9ahr)

## 제출

### 1차 제출

* ROUGE 평가를 생각해보니 summary를 진행하지 않고 그냥 text를 똑같이 입력해도 꽤 높은 점수가 나올 것 같다는 생각이 들었다.(종혁님께서 작업해서 제출해주심)

![](/files/-MklyffPYbMR0u3WGur_)

비슷한 생각을 가진 사람들이 있었는지 완전 동일한 점수가 몇몇 보였다 😂

### 2차 제출

* train data는 따로 활용하지 않고, test data를 pre-trained 모델 [ainize/kobart-news](https://huggingface.co/ainize/kobart-news) 을 활용하여 추론

![](/files/-Mkly1H-E758dGAaKoFo)

* 같이 작업하고 있는 준혁님께서는 같은 모델의 test데이터에 text를 전처리 작업 (특수문자 제거, 공백 제거 등) 후에 추론을 진행하였는데 아래와 같이 결과를 얻을 수 있었다고 한다.

![](/files/-MklzBX3D-Ixdr8gVv0E)

0.04나 차이나는거로 봐선 전처리를 하지 않는것이 오히려 좋은 성능을 내는 것인지 아님 단순히 랜덤 seed의 운인지 모르겠다...


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://lswkim322.gitbook.io/til/til-ml/competition/2021/undefined/day2-9.29.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
