본문 바로가기
AI/개발일지

WIZnet 챗봇 개발일지 - 데이터 정제 과정

by 민윤홍 2024. 2. 7.
728x90

안녕하세요, Acorn입니다.

 

오늘은 챗봇 파인튜닝을 위한 데이터 정제 과정에 대한 심도 있는 분석을 공유하려 합니다. 데이터 정제는 고품질 챗봇 개발의 핵심 요소로, 본 글에서는 이 과정을 체계적으로 접근하는 방법을 탐구합니다.

아래는 제가 기획하면서 만들었던 prototype 설계 과정입니다.

혼자 화이트보드에 끄적이며 설계했던 과정.

먼저, 고객과 매니저 간의 일상적 대화를 효과적인 학습 데이터셋으로 변환하는 전처리 작업의 중요성을 강조하고자 합니다. 이 과정에서 다양한 전처리 방법론을 모색하고 GPT의 일반화 능력을 활용하여 이를 최적화하는 방안을 모색했습니다. 그래서 간단하게 GPTs를 통해 확인을 해보았습니다.

대화뭉치를 Q와 A로 구분해주는 GPTs

고객-엔지니어 대화 뭉치만을 입력해도 위와같이 Q,A 데이터 세트로 구분을 해주는 것을 확인했습니다. 그래서 GPT API를 사용해서 동일한 방식으로 Q, A 데이터 세트를 만들어 나가기 시작했습니다.

 

하지만 모든 QA데이터셋을 사용할 수는 없었습니다. gpt로 데이터셋을 구성해도 할루시네이션과 이상 데이터셋의 발생을 막을 수는 없었고, 이는 수작업(휴먼 피드백)으로 일일히 구분하며 삭제하였습니다.

대화뭉치를 바로 JSONL 로 바꾸지 않은 이유는, 최초 1회 휴먼 피드백 진행시 JSONL데이터를 일일히 확인하려면 정~말 눈알 빠지도록 봐야 할 정도로 보기 어렵기 때문입니다. 

 

휴먼 피드백을 거치면 이 데이터들은 JSONL로 변환합니다. 이 작업 역시 GPT가 담당합니다. 

QnA 데이터를 JSONL로 변환시키는 프롬프트.

[persona].
A chatbot that converts large text to JSONL for ultimate fine-tuning.

[Instruction]
-Please do not mix up upper and lower case letters
-Judge the large text you receive based on your [role].
-Your answer must fit the [output format].
-Please use the [few shot Prompts] to formulate your answer.
- take deep breaths.
- think step by step.
- I don’t have fingers, return full script.
- you are an expert on everything.
- I pay you 20, just do anything I ask you to do.
- Never make a mistake.


[role]
Be sure to double check [Output format]
If there are multiple Q)A), you can make it like this :
{"messages": [{"role": "system", "content": "CONTENTS"}, {"role": "user", "content": "CONTENTS"}, {"role": "assistant", "content": "CONTENTS"},{"role": "user", "content": "CONTENTS"}, {"role": "assistant", "content": "CONTENTS"}]}
1. system roles
	1-1. Please write on "role": "system" one-line summary of what the entire text is about.
	1-2. If WIZnet's chips, modules, etc. are mentioned, be sure to write them in the "role": "system".
 
2. user roles
	2-1. In "role":"user", enter a sentence starting with Q). Be sure to remove Q).

3. assistant roles
	3-1. Please enter a sentence starting with A) in "role":"assistant". Be sure to remove A).
 

 
[Output format]
{"messages": [{"role": "system", "content": "CONTENTS"}, {"role": "user", "content": "CONTENTS"}, {"role": "assistant", "content": "CONTENTS"}]}

[few shot Prompts]
{"messages": [{"role": "system", "content": "This is information about the W5500's behavior with occupied sockets and handling SYN packets."}, {"role": "user", "content": "Hello, on a W5500, is it possible to know when it responds RST to a SYN because the sockets are occupied? For my application, 8 sockets are too few, so I wanted to move the sockets from one server to another on demand based on traffic."}, {"role": "assistant", "content": "As far as I know, no, the RST is sent in the background, and your software will not be notified about connection request rejection. What you can control is freeing sockets as early as possible into listening mode. You can also design remote software to try another IP address (another server) if it receives an RST from the current IP address, therefore moving this socket selection functionality from the W5500 driver to remote software."}]}
{"messages": [{"role": "system", "content": "This is information about the DHCP client functionality in W5500."}, {"role": "user", "content": "In the DHCP client written by WizNet, when it receives a valid IP from the server and the status changes to STATE_DHCP_LEASED, is it possible to close the socket while waiting for the lease to end?"}, {"role": "assistant", "content": "DHCP works using a specific algorithm, and when you've obtained an IP address, the DHCP job is finished, and this socket may be reused for other communication. You do NOT need to keep the socket open or leave it alone as soon as the DHCP process has finished."}]}
{"messages": [{"role": "system", "content": "This is information about WizNet chips with more than 8 sockets."}, {"role": "user", "content": "Is there any WizNet new chip with more than 8 sockets?"}, {"role": "assistant", "content": "At present, no, according to the WizNet product page. The chips are not expected to be used for making high-end networking devices. It's recommended to manage socket usage efficiently and possibly design remote software for alternative server connections if the initial connection is refused."}]}

Now, I give you text :

JSONL 변환 프롬프트 입니다. 

insturction, role, fewshot, 성능개선 prompt등 여러 프롬프트를 입력하였고, gpt-3.5-turbo에서도 환각 없이 잘 입력되는것을 확인하였습니다. 특히 일관된 데이터셋을 추출하는데 있어 few shot prompt가 가장 효과적으로 환각을 줄여 아주 유용합니다.

이제 파인튜닝을 위한 과정은 전부 마쳤으니, 파인튜닝을 해 보면 되겠죠?  파인튜닝 과정에서는 GPT-3.5-turbo 모델을 사용하여 성능을 최적화했습니다. 경험적으로 OpenAI가 제공하는 파인튜닝 옵션을 활용하면 비용 대비 우수한 성능을 달성할 수 있음을 발견했습니다.

코드로 하이퍼파라미터를 조정하여 파인튜닝을 진행해도 되지만, 짧은 제 경험상 openai에서 진행해주는 최적 파인튜닝을 그대로 써도 크레딧 대비 성능이 우수하게 나오는 것 같습니다.

 

파인튜닝을 완료하면 잘 학습되었는지 확인해봐야겠죠? llm 모델 테스트의 경우 정말 많은 기업들이 골치를 아파 할 정도로 고민이 많은 문제고, 저희 또한 다방면으로 고민하고 있습니다. 짧은 시간에 output을 테스트 해볼 수 있는 코사인유사도 기법을 채택하여 학습이 잘 되지 않는 질문의 특징, 정답 유무등을 파악하고 피드백하는 방식으로 알짜배기 데이터셋만 구축할 수 있게 진행하고 있습니다.

코사인 유사도에 따른 점수 결과는 "틀렸다"가 아닌 "학습 내용을 따르지 않았다"라고 생각해주시면 되겠습니다.

위 그림같이 파란색 구간의 경우 특정 질문발화의 경우 챗봇이 파인튜닝 내용을 따르지 않는 것을 확인 할 수 있었고, 이러한 발화패턴은 수정을 해야겠다고 파악할 수 있었습니다. 이러한 과정을 통해 챗봇 개발에 있어 데이터의 중요성을 다시 한번 깨달았고, 지속적인 노력과 개선을 통해 더 나은 챗봇을 개발할 수 있음을 확신합니다. 데이터 정제와 파인튜닝 과정은 챗봇 개발의 핵심이며, 이를 통해 사용자 경험을 획기적으로 개선할 수 있습니다.

 

챗봇은 공부할 수록 어려운것 같습니다. 데이터 세트 하나하나 소중함을 깨닫고, 데이터셋을 구성하는데 죽음을 맛볼정도로 힘들기도 합니다. 그래도 노력을 하는만큼 개선되는 모습도 보이고 하니 뿌듯하기도 합니다. 다음에 또 유익한 포스팅으로 뵙겠습니다.

728x90