#GemmaSprint
Hugging Face: https://huggingface.co/Tomato6244/Gemma2_Astronomy
Tomato6244/Gemma2_Astronomy · Hugging Face
Model Card for Gemma2-Astornomy This model provides generalized information of astronomy but is more specific than original Gemma2 model. Model Details Model Description This is the model card of a 🤗 transformers model that has been pushed on the Hub. T
huggingface.co
Kaggle: https://www.kaggle.com/models/lowzxx/gemma2-your-gateway-to-the-cosmos/Transformers/default/1
lowzxx | Gemma2: Your Gateway to the Cosmos | Kaggle
www.kaggle.com
Code: https://www.kaggle.com/code/lowzxx/gemma-sprint-astronomy/notebook
Gemma Sprint Astronomy
Explore and run machine learning code with Kaggle Notebooks | Using data from Gemma 2
www.kaggle.com
모델 설명
This model utilizes a cosmology API to provide information about the origin, structure, and evolution of the universe. Users can interact with the Gemma2 model to explore various cosmological topics, such as the Big Bang theory, multiverse hypothesis, dark matter, dark energy, and more, based on the latest research and knowledge. The Gemma2 model explains complex cosmological concepts in a simple and intuitive way, offering an engaging experience that stimulates scientific curiosity.
이 모델은 우주론 API를 활용하여 우주의 기원, 구조, 그리고 진화에 관한 다양한 정보를 제공합니다. 사용자들은 파인튜닝된 Gemma2 모델과 대화하면서 빅뱅 이론, 다중우주 가설, 암흑 물질, 암흑 에너지 등 여러 흥미로운 우주론 주제를 최신 연구 결과에 기반해 쉽게 탐구할 수 있습니다. Gemma2 파인튜닝 모델은 복잡한 우주론 개념들을 누구나 이해할 수 있도록 친절하고 직관적으로 설명해 주며, 과학에 대한 호기심을 자극하는 재미있는 경험을 제공합니다.
Q1: Explan Radio astronomy as long as possible

Q2: Explan infrared astronomy as long as possible

Q3: Explan infrared astronomy as long as possible

데이터

위키피디아 API를 이용하여 위키피디아의 'Astronomy', 'Astrophysics', 'Theoretical astronomy', 'Radio astronomy', 'Infrared astronomy', 'Amateur astronomy', 'List of unsolved problems in astronomy' 페이지의 텍스트를 읽어왔습니다.

긁어온 텍스트를 학습 데이터에 적합하도록 정제했습니다.
파인튜닝

LoRA(Low-Rank Adaptation of Large Language Models) 기법을 사용하여 Gemma2 모델을 파인튜닝하였습니다. LoRA는 대규모 언어 모델을 효율적으로 파인튜닝하기 위한 기술로, 모델의 전체 파라미터를 수정하는 대신 일부 중요한 파라미터만 조정하여 메모리 사용량을 줄이고 학습 시간을 단축하는 것이 특징입니다.
- r: LoRA 매트릭스의 차원을 의미합니다. 값이 클수록 모델의 표현력이 높아지지만, 메모리 사용량도 증가합니다.
- lora_alpha: LoRA 매트릭스의 스케일링 값입니다. 값이 클수록 파인튜닝의 영향력이 커집니다.
- lora_dropout: 드롭아웃 비율을 설정합니다. 과적합을 방지하는 데 도움이 됩니다.
- bias: 바이어스 학습 여부를 설정합니다.
- task_type: LoRA 파인튜닝에서 모델이 수행할 작업의 종류를 지정하는 매개변수입니다. 이 값에 따라 모델의 학습 방식과 최적화되는 부분이 달라집니다.
- target_modules: LoRA가 적용될 모델의 특정 레이어들을 지정하는 매개변수입니다. 즉, 모델의 어떤 부분을 파인튜닝할지를 결정하는 것입니다. 어떤 레이어를 포함시키느냐에 따라 모델의 성능이 크게 달라질 수 있습니다. 일반적으로는 모델의 핵심 기능을 담당하는 레이어들을 위주로 파인튜닝하는 것이 효과적입니다.
<task_type 종류>
- CAUSAL_LM: 일반적으로 자연어 생성 모델에서 사용되는 설정입니다. 텍스트를 순차적으로 생성하는 작업에 적합하며, 왼쪽에서 오른쪽으로 컨텍스트를 고려하여 다음 토큰을 예측합니다.
- SEQ_2_SEQ_LM: 입력 시퀀스를 다른 시퀀스로 변환하는 작업에 사용됩니다. 예를 들어, 번역, 요약, 질의응답 등의 태스크에 적합합니다.
- CLASSIFICATION: 텍스트 분류 작업에 사용됩니다. 텍스트를 입력받아 미리 정의된 여러 클래스 중 하나로 분류합니다.
- QUESTION_ANSWERING: 질문에 대한 답변을 찾는 작업에 사용됩니다. 질문과 컨텍스트를 입력받아 정확한 답변을 생성합니다.
<target_modules 종류>
- attention 메커니즘 관련 레이어: q_proj, k_proj, v_proj, o_proj 등은 attention 메커니즘에서 사용되는 projection matrix를 의미합니다. 이 부분을 파인튜닝하면 모델이 입력 데이터의 관계를 더 잘 학습할 수 있습니다.
- feed-forward network 관련 레이어: gate_proj, up_proj, down_proj 등은 feed-forward network에서 사용되는 projection matrix를 의미합니다. 이 부분을 파인튜닝하면 모델의 표현 능력을 향상시킬 수 있습니다.
- 다른 레이어: 모델의 아키텍처에 따라 다양한 레이어를 지정할 수 있습니다. 예를 들어, embedding 레이어, output 레이어 등을 파인튜닝할 수 있습니다.

1. TrainingArguments:
- output_dir: 학습 결과(모델, 로그 등)를 저장할 디렉토리를 지정합니다.
- per_device_train_batch_size: 각 GPU에서 처리할 배치 크기를 설정합니다.
- optim: 사용할 optimizer를 지정합니다. 저희는 paged_adamw_32bit를 사용하여 메모리 효율적인 학습을 수행하도록 하였습니다.
- gradient_accumulation_steps: 그래디언트를 누적할 스텝 수를 설정합니다. 배치 크기를 효과적으로 늘리는 방법 중 하나입니다.
- num_train_epochs: 전체 학습 에폭 수를 설정합니다.
- logging_steps: 로그를 남길 스텝 수를 설정합니다. 학습 진행 상황을 모니터링하는 데 사용됩니다.
- warmup_steps: 학습 초반에 학습률을 천천히 증가시키는 warm-up 스텝 수를 설정합니다.
- learning_rate: 학습률을 설정합니다.
- fp16, bf16: 각각 16비트 부동소수점, bfloat16 형식을 사용할지 여부를 설정합니다. GPU 메모리 효율을 높이는 데 도움이 될 수 있습니다.
- group_by_length: 데이터를 길이별로 그룹화하여 학습할지 여부를 설정합니다.
- report_to: 학습 결과를 보고할 곳을 지정합니다. 여기서는 Wandb를 사용합니다.
2. SFTTrainer:
- model: 파인튜닝할 모델을 지정합니다.
- train_dataset: 학습 데이터셋을 지정합니다.
- peft_config: LoRA와 같은 파라미터 효율적인 파인튜닝 기법을 사용할 경우 해당 설정을 지정합니다.
- max_seq_length: 입력 시퀀스의 최대 길이를 설정합니다.
- dataset_text_field: 데이터셋에서 텍스트 데이터가 저장된 필드를 지정합니다.
- tokenizer: 토크나이저를 지정합니다.
- args: 앞서 설정한 TrainingArguments를 전달합니다.
- packing: 데이터 패딩 여부를 설정합니다.
Reference
1. 파인튜닝을 통해 위키피디아 정보를 활용하여 셜록홈즈에 관한 질문에 답변하는 Gemma (2b-it) 노트북:
https://www.kaggle.com/code/lucamassaron/sherlock-holmes-q-a-with-gemma-fine-tuning/notebook
Sherlock Holmes Q&A with Gemma fine tuning
Explore and run machine learning code with Kaggle Notebooks | Using data from Gemma
www.kaggle.com
2. 위키피디아: https://www.wikipedia.org/
Wikipedia, the free encyclopedia
Wikipedia is a free online encyclopedia, created and edited by volunteers around the world and hosted by the Wikimedia Foundation.
www.wikipedia.org
'AI' 카테고리의 다른 글
statsmodels 라이브러리의 Logit vs sklearn의 LogisticRegression (2) | 2024.11.06 |
---|---|
우도(Likelihood)란 무엇인가 +로그 우드(Log-Likelihood) (1) | 2024.11.06 |
LLM API에서 스트리밍(streaming)과 비스트리밍(Non-Streaming, Blocking)의 차이 (0) | 2024.08.25 |
[ AI ] Hugging Face에서 Model을 가져올 때 양자화를 하는 이유 (0) | 2024.07.26 |
[NLP] 워드 임베딩은 왜 기계 번역에 불리한가? (4) | 2024.07.22 |