삽질/개발,엔지니어링

ChatGPT 파인튜닝 써보기 - 1

maengis 2023. 4. 12. 00:02

2022년 뚜르드프랑스 종합 우승자

제가 알 수 있는 정보는 2021년까지입니다. 2021년 뚜르드프랑스(Tour de France) 종합 우승자는 타데프 프가쳐(Tadej Pogačar)였습니다. 2022년 뚜르드프랑스 종합 우승자에 대한 정보는 제가 제공할 수 없습니다. 최신 정보를 얻으려면 인터넷 검색이나 스포츠 뉴스를 참조해 주세요.

 

2022년 우승자는 윰보비즈마 소속 요나스 빙에가르인데, 일단 내가 타데이 포가챠로 알고 있는데, 얘가 타데프 프가쳐라고 해서 이것도 이름도 얘 답변에 맞게 학습을 시켜야 할 거 같아서 다시 물어봄.

 

윰보비즈마 요나스 빙에가르 선수를 아니

네, 윰보-비즈마(Jumbo-Visma)팀의 요나스 빙가르(Jonas Vingegaard) 선수는 덴마크의 프로 자전거 선수입니다. 2021 뚜르드프랑스에서 그는 전체 랭킹 2위를 차지했습니다. 하지만 제가 알고 있는 정보는 2021년까지이므로, 2022년에 관한 성적이나 업적은 제공할  없습니다. 최신 정보를 얻으려면 인터넷 검색이나 스포츠 뉴스를 참조해 주세요.

 

맞다. 2021년에 2등한 것도 알고 있다.

 

파인튜닝은 openai에서 친절하게 안내가 되어 있다.

https://platform.openai.com/docs/guides/fine-tuning

 

OpenAI API

An API for accessing new AI models developed by OpenAI

platform.openai.com

 

나는 2022년 뚜르드프랑스 종합 우승자가 요나스 빙에가르라는 걸 학습 시킬 거라, 일단 아래 데이터로 학습을 시켜보았다.

 

{"prompt": "2022년 뚜르드프랑스 종합 우승자", "completion": "요나스 빙가르(Jonas Vingegaard)"}
{"prompt": "2022년 뚜르드프랑스 1등", "completion": "요나스 빙가르(Jonas Vingegaard)"}
{"prompt": "2022년 뚜르드프랑스 1위", "completion": "요나스 빙가르(Jonas Vingegaard)"}
{"prompt": "2022년 뚜르드프랑스 GC", "completion": "요나스 빙가르(Jonas Vingegaard)"}

 

음 오류???

    raise MissingDependencyError(PANDAS_INSTRUCTIONS)
openai.datalib.MissingDependencyError:

OpenAI error:

    missing `pandas`

This feature requires additional dependencies:

    $ pip install openai[datalib]

 

설명대로 설치하고 실행

$ openai tools fine_tunes.prepare_data -f foo.json
Analyzing...

- Your JSON file appears to be in a JSONL format. Your file will be converted to JSONL format
- Your file contains 4 prompt-completion pairs. In general, we recommend having at least a few hundred examples. We've found that performance tends to linearly increase for every doubling of the number of examples
- Based on your data it seems like you're trying to fine-tune a model for classification
- For classification, we recommend you try one of the faster and cheaper models, such as `ada`
- For classification, you can estimate the expected model performance by keeping a held out dataset, which is not used for training
- More than a third of your `prompt` column/key is uppercase. Uppercase prompts tends to perform worse than a mixture of case encountered in normal language. We recommend to lower case the data if that makes sense in your domain. See https://platform.openai.com/docs/guides/fine-tuning/preparing-your-dataset for more details
- Your data does not contain a common separator at the end of your prompts. Having a separator string appended to the end of the prompt makes it clearer to the fine-tuned model where the completion should begin. See https://platform.openai.com/docs/guides/fine-tuning/preparing-your-dataset for more detail and examples. If you intend to do open-ended generation, then you should leave the prompts empty
- All prompts start with prefix `2022년 뚜르드프랑스 `. Fine-tuning doesn't require the instruction specifying the task, or a few-shot example scenario. Most of the time you should only add the input data into the prompt, and the desired output into the completion
- The completion should start with a whitespace character (` `). This tends to produce better results due to the tokenization we use. See https://platform.openai.com/docs/guides/fine-tuning/preparing-your-dataset for more details

Based on the analysis we will perform the following actions:
- [Necessary] Your format `JSON` will be converted to `JSONL`
- [Recommended] Lowercase all your data in column/key `prompt` [Y/n]: Y
- [Recommended] Add a suffix separator ` ->` to all prompts [Y/n]: n
- [Recommended] Remove prefix `2022년 뚜르드프랑스 ` from all prompts [Y/n]: n
- [Recommended] Add a whitespace character to the beginning of the completion [Y/n]: n
- [Recommended] Would you like to split into training and validation set? [Y/n]: Y


Your data will be written to a new JSONL file. Proceed [Y/n]: Y

Wrote modified files to `foo_prepared_train.jsonl` and `foo_prepared_valid.jsonl`
Feel free to take a look!

Now use that file when fine-tuning:
> openai api fine_tunes.create -t "foo_prepared_train.jsonl" -v "foo_prepared_valid.jsonl" --compute_classification_metrics --classification_n_classes 1

 Make sure to include `stop=["요나스 빙가르(Jonas Vingegaard)"]` so that the generated texts ends at the expected place.
Once your model starts training, it'll approximately take 2.43 minutes to train a `curie` model, and less for `ada` and `babbage`. Queue will approximately take half an hour per job ahead of you.

하고나면 같은 위치에 '파일명_prepared_train.jsonl'이 생성된다.

중간에 어떤 식으로 데이터를 학습 시키면 될지를 물어본다. 시작하는 걸 뭘로 할지, 중복으로 시작되는 건 지울지. 프롬프트 마지막을 뭘로 할지 등등...

 

이제 학습을 시키면...

$ openai --api-key {API_KEY} api fine_tunes.create -t foo_prepared_train.jsonl -m davinci
Upload progress: 100%|█████████████████████████████████████████| 304/304 [00:00<00:00, 127kit/s]
Uploaded file from foo_prepared_train.jsonl: file-FOvIBDgZTPTjpB4BRNRpcImR
Created fine-tune: ft-ctPSuQoCJbM2xt0xlezvL8yG
Streaming events until fine-tuning is complete...

(Ctrl-C will interrupt the stream, but not cancel the fine-tune)
[2023-04-11 23:52:48] Created fine-tune: ft-ctPSuQoCJbM2xt0xlezvL8yG
[2023-04-11 23:53:16] Fine-tune costs $0.02
[2023-04-11 23:53:17] Fine-tune enqueued. Queue number: 3
[2023-04-11 23:53:27] Fine-tune is in the queue. Queue number: 2

파인튜닝에 대한 로그가 나오고, playground(https://platform.openai.com/playground)에 가보면 Model 선택하는 곳에 파인튜닝한 모델이 나온다.

 

선택 후 사용을 해보면...

저기요...???

Temprerature를 조정하면 좀 나아지지 않을까 했는데, 바르셀로나 종합 우승자라고 계속 말하기도 하고, 자꾸 뭔가 만들어서 말을 해야 된다는 강박에 시달리는 정신병자를 보는 거 같아서 추후 좀 더 프롬프트로 던질 걸 잘 모아서 해보는 것으루...

반응형