728x90 ๋ฐ์ํ Deep Learning78 LLM์ ๋ชจ๋ ๊ฒ 3 [PEFT-Parameter-efficient fine Tuning] PEFT(Parameter-efficient fine Tuning) : ๊ธฐ์กด์ ๊ฒฝ์ฐ, ์ฌ์ ํ์ต๋ LLM์ ๋ค์ด์คํธ๋ฆผ ๋ฐ์ดํฐ์ ์ ๋ฐ๋ผ ํ์ธ ํ๋ํ๋ฉด ์ฌ์ ํ์ต๋ ๋ชจ๋ธ์ ๊ทธ๋๋ก ์ฌ์ฉํ๋ ๊ฒ๋ณด๋ค ํ์คํ ์ฑ๋ฅ ํฅ์์ ๋ณด์ฌ์ค๋ค. : ํ์ง๋ง, ๋ชจ๋ธ์ด ์ ์ ์ปค์ง์ ๋ฐ๋ผ ๋ชจ๋ธ ์ ์ฒด๋ฅผ Fine tuning ํ๋ ๊ฒ์ ๋ถ๊ฐ๋ฅ! : ๋ฉ๋ชจ๋ฆฌ ์ ์ฅ ๊ณต๊ฐ ๋ฐ ๊ณ์ฐ ๋น์ฉ์ ๋ํ ๋ฌธ์ ์ ๋ ์กด์ฌ ⇒ ํด๋น ๋ฌธ์ ๋ค์ ํด๊ฒฐํ๊ธฐ ์ํด ๋์จ ๊ฒ์ด PEFT ์ด๋ค. ๐ก PEFT์ ์ญํ : ๋๋ถ๋ถ์ ํ๋ผ๋ฏธํฐ๋ฅผ ํ๋ฆฌ์งํ๊ณ ์ผ๋ถ์ ํ๋ผ๋ฏธํฐ๋ง์ ํ์ธํ๋ํจ์ผ๋ก์จ ์ ์ฅ๊ณต๊ฐ๊ณผ ๊ณ์ฐ๋ฅ๋ ฅ์ ๋ํญ ์ค์ธ๋ค. catastrophic forgetting(ํ๊ตญ์ ๋ง๊ฐ)์ ๊ทน๋ณต : Fine tuning ์ ๋ฐ์๋๋ ๋ฌธ์ ๋ก ์๋ก์ด ํ ์คํฌ๋ฅผ ํ์ตํจ์ ๋ฐ๋ผ ๊ธฐ์กด ํ ์คํฌ์ ๋ํ .. 2024. 3. 22. LLM์ ๋ชจ๋ ๊ฒ 2 [RAG-Retrieval Augmented Generation] LangChain(๋ญ์ฒด์ธ) : ๋๊ท๋ชจ ์ธ์ด ๋ชจ๋ธ๊ณผ ์ดํ๋ฆฌ์ผ์ด์ ์ ํตํฉ์ ๊ฐ์ํํ๋ SDK(์ํํธ์จ์ด ๊ฐ๋ฐ ํคํธ - ๊ฐ๋ฐ ๋๊ตฌ์ ์งํฉ์ฒด) : ๋๊ท๋ชจ ์ธ์ด ๋ชจ๋ธ(LLM)์ ๊ธฐ๋ฐ์ผ๋ก ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ตฌ์ถํ๊ธฐ ์ํ ์คํ ์์ค ํ๋ ์์ํฌ : ์ฝ๊ฒ ๋งํ๋ฉด LLM ๋ฐํคํธ๋ผ๊ณ ์๊ฐํ๋ ๊ฒ์ด ํธํ๋ค. : LLM์ ๊ตฌ์ฑํ๊ธฐ ์ํ ๋ชจ๋๋ค์ด ์กด์ฌ ๋ชจ๋ธ I/O : ์ธ์ด ๋ชจ๋ธ๊ณผ์ ์ธํฐํ์ด์ค ํ๋กฌํํธ๋ฅผ ๊ด๋ฆฌํ๊ณ ๊ณตํต ์ธํฐํ์ด์ค๋ฅผ ํตํด ์ธ์ด ๋ชจ๋ธ์ ํธ์ถํ๊ณ ๋ชจ๋ธ ์ถ๋ ฅ์์ ์ ๋ณด ์ถ์ถ ๋ฐ์ดํฐ ์ฐ๊ฒฐ : ์ ํ๋ฆฌ์ผ์ด์ ๋ณ ๋ฐ์ดํฐ์์ ์ธํฐํ์ด์ค ๋ฐ์ดํฐ๋ฅผ ๋ก๋, ๋ณํ, ์ ์ฅ ๋ฐ ์ฟผ๋ฆฌํ๊ธฐ ์ํ ๋น๋ฉ ๋ธ๋ก์ ์ ๊ณต ์ฒด์ธ : ํธ์ถ ์ํ์ค ๊ตฌ์ถ ๋ณต์กํ ์ ํ๋ฆฌ์ผ์ด์ ์ LLM์ ์ํธ, ๋๋ ๋ค๋ฅธ ๊ตฌ์ฑ์์์ ์ฒด์ธ์ผ๋ก ์ฐ๊ฒฐํด์ผ ํ๋ค. ๋ญ์ฒด์ธ์ ์ด๋ ๊ฒ ‘์ฒด์ธ์ผ๋ก ์ฐ.. 2024. 3. 22. LLM์ ๋ชจ๋ ๊ฒ 1 [RAG-Retrieval Augmented Generation] 1. RAG - Retrieval Augmented Generation : ๊ฒ์ ์ฆ๊ฐ ์์ฑ : ์๋ก์ด ์ง์์ ๊ดํ ํ ์คํธ ๋ฐ์ดํฐ ์์ค๋ฅผ Embeddingํด์ Vector stores์ ์ ์ฅํ๊ณ , ํ๋กฌํํธ ๊ตฌ์ฑ์ ์งํํ ๋ ์ธ๋ถ ๋ฐ์ดํฐ ์์ค๋ก๋ถํฐ ๊ฐ์ ธ์จ ํ ์คํธ ๋ฐ์ดํฐ๋ฅผ ํจ๊ป ์ด์ฉํด์ ํ๋กฌํํธ๋ฅผ ๊ตฌ์ฑํ ๋ค LLM์ผ๋ก๋ถํฐ ๋ต๋ณ์ ์ป์ด๋ธ๋ค. ์ฌ์ฉ์ ์ง๋ฌธ ์ง๋ฌธ ์๋ฒ ๋ฉ ๋ฐ ๋ด ๋ฐ์ดํฐ๋ ์๋ฒ ๋ฉ ์งํ ์ดํ, ๋ฒกํฐ DB(์ ์ฅ์)์ ์๋ฒ ๋ฉ๋ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅ ์ง๋ฌธ์ ์ด์ฉํด ์ ์ฅํด๋์ DB ์ ์ฅ์์์ ๊ฒ์ ์ง์ ํ๋กฌํํธ ๊ตฌ์ฑ + ์ง๋ฌธ(query ์ฌ์์ฑ) + ๊ฒ์ ๊ฒฐ๊ณผ n๊ฐ > ์ธ์ด๋ชจ๋ธ GPT์๊ฒ ์ ๊ณต ์ธ์ด ๋ชจ๋ธ์ด ๋ต๋ณ ์์ฑ ๋ต๋ณ ์ถ๋ ฅ 2-2) ์๋ฒ ๋ฉ ๋ชจ๋ธ : AI๊ฐ ์ฌ๋์ ์ธ์ด๋ฅผ ์ดํดํ๊ธฐ ์ํ ๋ฐฉ๋ฒ์ผ๋ก ์ซ์๋ก ๋ณํ ํด์ฃผ๋ AI.. 2024. 3. 5. [Transformer] train.py, dataset.py, config.py, Mask ๊ตฌํํ๊ธฐ - 2 (Pytorch) ์ง๋ ์๊ฐ์ ์ด์ด, ์ค๋์ ๋๋จธ์ง train.py, config.py, dataset.py ํ์ผ์ ๊ตฌํํ๋ค. https://www.youtube.com/watch?v=ISNdQcPhsts ์ด ๋ถ ์ฝ๋๋ฅผ ๋ฐํ์ผ๋ก ๊ตฌํํ์์ต๋๋ค. 1. Dataset.py ๊ตฌํ 1-1. Bilingual Dataset ์ฌ์ฉํ ๋ฐ์ดํฐ์ ์ Hugging Face์์ ์ ๊ณตํ๋ opus_books Dataset์ ํ์ฉํ์๋ค. https://huggingface.co/datasets/opus_books/viewer/en-it opus_books · Datasets at Hugging Face { "en": "Nor could I pass unnoticed the suggestion of the bleak shores of Laplan.. 2024. 2. 21. [Transformer] ์ํคํ ์ฒ ๊ตฌํํ๊ธฐ - 1 (Pytorch) Transformer๋ ๋ ผ๋ฌธ์ผ๋ก๋ง ์ฝ์ด๋ดค์ง, ์ฝ๋๋ก ๋ฏ์ด๋ณด๋ ๊ฒ์ ์ฒ์์ด๋ค. ๋ ผ๋ฌธ ์ ์๋ค์ ์ ๋ง ์ฒ์ฌ๊ฐ ๋ง๋ ๊ฒ ๊ฐ๋ค. ์ ํ๋ธ๋ฅผ ์ฐธ๊ณ ํด์ ์ฝ๋๋ฅผ ๊ตฌํํ์์ผ๋ฉฐ, ์ด๋ฒ ํฌ์คํ ์ ์ค๋ก์ง ์ํคํ ์ฒ์๋ง ์ด์ ์ ๋ง์ท๋ค. ๋ฐ์ดํฐ ๋ถ๋ถ์ ๋ค์์ฃผ์ ์ฌ๋ฆด ์์ . 1. Input Embedding ๊ตฌํํ๊ธฐ import torch import torch.nn as nn import math #Input embedding class InputEmbeddings(nn.Module): #d ์ฐจ์ ์ค์ , vocab size ์ค์ (์ผ๋ง๋ ๋ง์ ๋จ์ด ๋ฃ์๊ฑด์ง) def __init__(self,d_model : int, vocab_size : int): super().__init__() self.d_model = d_model self... 2024. 2. 17. [UNet] copy and crop ์ฝ๋ ๊ตฌํ ๋ฐ ์ํคํ ์ฒ ๊ตฌํํ๊ธฐ (Pytorch) ๋ค๋ฅธ ๋ธ๋ก๊ทธ๋ค์์๋ padding์ 2๋ก ๋ง์ถฐ์, ๋ฐ๋ก copy and crop์ ํ์ง ์์์ง๋ง, ํด๋น ๋ ผ๋ฌธ์ ๊ทธ๋ฆผ์ ๋ณด๊ณ ์ฌํํ๊ธฐ ์ํด padding=0์ผ๋ก ์ค์ ํด์ ๋ณธ ์ํคํ ์ฒ๋ฅผ ์๋ก ๊ตฌ์ถํ์๋ค. import torch.nn as nn import torch.nn.functional as F import torch import os import numpy as np from torchvision import transforms #https://sd118687.tistory.com/8 (Mirroring extrapolate) class UNet(nn.Module): #copy and crop ํจ์ ์ ์ #batch_size, channels, height, width def copy_and_crop(.. 2024. 2. 8. ์ด์ 1 2 3 4 ยทยทยท 13 ๋ค์ 728x90 ๋ฐ์ํ