본문 바로가기

좌충우돌개발일지

Welcome to Hogwarts!

Gemma Sprint를 어느정도 마무리 지었다.

Sprint를 진행하면서, 다시금 데이터가 얼마나 중요한지 느낄 수 있는 시간이었다.

 

해리포터 자료를 얻기 위해, 총 3가지를 고려했다.

 

https://hp-lexicon.org/

 

Harry Potter Lexicon

Harry and Hermione, in disguise as an elderly Muggle couple, encounter who they think is Bathilda Bagshot in Godric’s Hollow on Christmas Eve. They follow her to her house, where she is revealed to be Nagini. In the ensuing battle, Hermione’s quick thi

www.hp-lexicon.org

https://harrypotter.fandom.com/

 

Harry Potter Wiki

Your Legacy Is What You Make It Welcome to the Wizarding World of Harry Potter! Hogwarts Legacy is a new immersive open-world action roleplaying game set in the wizarding world. Experience Hogwarts School of Witchcraft and Wizardry in the 1890s as a studen

harrypotter.fandom.com

https://github.com/Ginga1402/Harry-Potter-Dataset

 

GitHub - Ginga1402/Harry-Potter-Dataset: Harry potter Novels

Harry potter Novels. Contribute to Ginga1402/Harry-Potter-Dataset development by creating an account on GitHub.

github.com

 

책의 내용의 경우, 주인공들에게 편향적일 수 있다는 생각이 들었고,

Fandom Wiki의 경우 열정적인 Fan에 의해 자료의 차이가 많이 발생할 수 있다고 생각했다.

따라서 해리포터 사전인 Harry Potter Lexicon을 활용했다.

Lexicon에서 Crawling을 통해 데이터를 확보하고, Gemma-2b모델로 1차 QnA를 생성했다.

[
    {
        "instruction": "What is the incantation used to summon an object to the caster? ",
        "input": "",
        "output": "Accio"
    },
    {
        "instruction": "What is the incantation to summon a fountain or jet of drinkable water from a caster’s wand?",
        "input": "",
        "output": "Aguamenti"
    },
    {
        "instruction": "What is the incantation required to unlock a door with the Unlocking Charm?",
        "input": "",
        "output": "Alohomora"
    },
    {
        "instruction": "What type of magical ability does Anti-Apparition Charm specifically counter?",
        "input": "",
        "output": "Apparating"
    },
...

와 같은 방식으로, 단답이 나오도록 QnA를 작성하는 실수를 범했다.

당시에는 이 나비효과를 눈치채지 못했다..

 

Fine-tuning은 unsloth를 활용했다.

https://github.com/unslothai/unsloth?tab=readme-ov-file

 

GitHub - unslothai/unsloth: Finetune Llama 3.1, Mistral, Phi & Gemma LLMs 2-5x faster with 80% less memory

Finetune Llama 3.1, Mistral, Phi & Gemma LLMs 2-5x faster with 80% less memory - unslothai/unsloth

github.com

unsloth 덕분에, 2B 모델이 아닌 7B 모델로 학습할 수 있었고, 더 나은 성능이 나온것이 아닌가 생각했다.

 

모델 학습 완료 이후, hugging face에 모델을 배포했다.

https://huggingface.co/rnltls/harrypotter_lexicon_finetune

 

rnltls/harrypotter_lexicon_finetune · Hugging Face

Uploaded model Developed by: rnltls License: apache-2.0 Finetuned from model : unsloth/gemma-7b-bnb-4bit This gemma model was trained 2x faster with Unsloth and Huggingface's TRL library.

huggingface.co

튜닝이라기엔 부끄러웠지만, 재밌는 경험이었다.

 

이후 Gradio를 활용하여, 데모 페이지를 제작했다.

데모 페이지를 배포하고 싶었으나, 금전적인 문제로 인해 colab link로 대체한다.

https://colab.research.google.com/drive/18ZOVYbVuf2S6oNOyGdGtDCb8dewoumSy#scrollTo=zLbEoeFq2IAc

 

gradio_unit_test.ipynb

Colab notebook

colab.research.google.com

 

이때, QnA의 나비효과를 발견할 수 있었다.

젠장. 단답으로 나온다

튜닝을 단답으로 진행했기 때문에, 대답도 단답으로 나와버리는 것이었다...

2차 튜닝에서는 이를 해결하기 위해 QnA set을 재정비하고, 다시 튜닝을 진행하고자 한다.

 

또한 기숙사 선택 기능을 제공하고 있는데, 이는 Fine-Tuning이 아닌 Prompt Engineering을 통해 제공하고 있다.

Lexicon에서도 어느정도 그리핀도르 등장인물이 많다 보니, 주로 그리핀도르가 나오는 문제점을 확인했다.

2차 튜닝에서는 이를 보완하고자 각 기숙사의 성격에 맞는 대답들을 활용하여 올바른 정답이 나올 수 있도록 데이터를 준비하고자 한다.

'좌충우돌개발일지' 카테고리의 다른 글

HumanML3D Dataset 준비하기  (3) 2024.11.13
정사각형으로 외곽선 검출  (0) 2023.01.31
이미지 전처리  (0) 2023.01.30