전체 글

전체 글

    BLEU (Bilingual Evaluation Understudy) Score - LLM Evaluation

    BLEU (Bilingual Evaluation Understudy) Score - LLM Evaluation

    LLM이 생성한 (예측한) 결과를 평가하기 위해 PPL (Perplexity) 도 쓰이지만, 그보다 BLEU Score를 더 많이 사용한다.  PPL은 쉽게 말해 모델이 정답을 예측할 때 헷갈려하는 정도이다. 따라서 작으면 작을수록 좋다. 5개의 선택지 중 고민하는 것 보다, 2개의 선택지 중 고민하는게 모델이 그만큼 똑똑하다는 것이니까. 하지만, 번역 작업을 예로 들면, 우리는 문장의 맥락을 고려해서 번역이 잘 되었는지를 평가하고 싶어 한다. 해당 평가에 BLEU Score를 사용한다.  BLEU란?$BLEU = BP\cdot \prod_{n=1}^{N}p_{n}^{w_{n}}$로 계산되는 Evaluation Score이다. $p_{n}$ : n-gram precision$w_{n}$ : weight,..

    SVM (Support Vector Machine) 이란?

    SVM (Support Vector Machine) 이란?

    SVM은 전통적인 ML 기법 중 하나로 분류되며 이진 분류를 위해 사용된다.  간단히 말하면, SVM은 서로 다른 클래스를 분리하기 위한 "국경 긋기 방법"이다.  그럼 국경 (Decision boundary) 을 어떻게 그어야 할까? 자기 집 앞이 DMZ가 되지 않도록 모두가 만족하게 그어야 할 것이다. 이렇게 하기 위해서는 파란색 데이터에서 국경까지의 거리와 빨간색 데이터에서 국경까지의 거리가 동일해야 한다. 국경 (Decision boundary) 까지의 거리를 우리는 "Margin" 이라고 명칭하고,  데이터마다 Margin이 같도록, global한 관점에서 봤을 때는 Margin이 크도록 국경을 긋게 된다.  이 국경을 좌표평면에서 수식으로 표현하면, $ax+by=c$ 이고 이를 행렬로 나타내면..

    랜덤 포레스트 (Random Forest)

    랜덤 포레스트 (Random Forest)

    https://welldonecode.tistory.com/157 의사결정트리 (Decision Tree)Random Forest의 기초가 되는 의사결정트리 (Decision Tree)에 대해서 알아본다. 의사결정트리는 지도학습 방법 중, "분류" 문제를 푸는데 사용된다. 데이터가 존재할 때, 스무고개를 통해 그 데이터가welldonecode.tistory.com이전 게시물에서 의사결정트리에 대해 다뤘고, 의사결정트리의 overfitting 문제를 해결하기 위해 random forest가 등장하였다고 언급하였다. 이번엔 이 random forest에 대해 알아본다.  의사결정트리에서 "나무"를 만들었다면, 랜덤 포레스트에서는 나무들로 이루어진 "숲"을 만든다. 하나의 나무가 문제를 잘 해결하지 못하니, ..

    의사결정트리 (Decision Tree)

    의사결정트리 (Decision Tree)

    Random Forest의 기초가 되는 의사결정트리 (Decision Tree)에 대해서 알아본다. 의사결정트리는 지도학습 방법 중, "분류" 문제를 푸는데 사용된다. 데이터가 존재할 때, 스무고개를 통해 그 데이터가 어떤 class에 속하는지 맞추는 예시와 상당히 유사하다. 그렇다면, 의사결정트리의 구성요소에 대해 설명한다.  위와 같은 그림에서 각 노드의 명칭은 아래와 같다.맨 처음 분류 기준을 Root Node중간 분류 기준을 Intermediate Node맨 마지막 노드를 Terminal Node 혹은 Leaf Node 이제, 완성된 의사결정트리를 보고 역으로 그 원리에 대해 설명하겠다. 위 그림은 depth=2 상태로 완성된 의사결정트리이다. 여기서 Root Node와 Intermediate N..

    [pytorch] 순환신경망 (Recurrent Neural Network) 예제 코드

    import torchimport torch.nn as nnimport torch.optim as optimimport numpy as npn_hidden = 35lr = 0.01epochs = 1000string = "hello pytorch. how long can a rnn cell remember? show me your limit!"chars = "abcdefghijklmnopqrstuvwxyz ?!.,:;01"char_list = [i for i in chars]n_letters = len(char_list)# one-hot encodingdef string_to_onehot(string): start = np.zeros(shape=n_letters, dtype=int) end = np...

    [pytorch] 합성곱 신경망 (Convolution Neural Network) 예제 코드

    import torchimport torch.nn as nnimport torch.optim as optimimport torch.nn.init as initimport torchvision.datasets as dsetimport torchvision.transforms as transformsfrom torch.utils.data import DataLoaderbatch_size = 256learning_rate = 0.0002num_epoch = 10mnist_train = dset.MNIST("./", train=True, transform=transforms.ToTensor(), target_transform=None, download=True)mnist_test = dset.MNIST("./"..

    [pytorch] 심층신경망 (Deep Neural Network) 예제 코드

    import torchimport torch.nn as nnimport torch.nn.init as initimport torch.optim as optimnum_data = 1000num_epoch = 10000noise = init.normal_(torch.FloatTensor(num_data, 1), std=1)x = init.uniform_(torch.Tensor(num_data, 1), -15, 15)y = (x**2) +3y_noise = y + noise# Sequential 함수 안에 작성된 순서대로 데이터 연산 진행# 은닉층은 4개, activation은 ReLU 사용model = nn.Sequential( nn.Linear(1,6), nn.ReLU(), nn.Linea..

    [pytorch] 선형 회귀 (Linear Regression) 예제 코드

    import torchimport torch.nn as nnimport torch.optim as optimimport torch.nn.init as initnum_data = 1000num_epoch = 500x = init.uniform(torch.Tensor(num_data, 1), -10, 10)noise = init.normal(torch.Tensor(num_data, 1), std=1)y = 2*x+3y_noise = 2*(x+noise)+3model = nn.Linear(1,1)# Loss함수로 L1 Lossloss_func = nn.L1Loss()# Optimizer로 Stochastic Gradient Descentoptimizer = optim.SGD(model.parameters(),..

    [논문리뷰] Can LLMs Learn from Previous Mistakes? Investigating LLMs’ Errors to Boost for Reasoning

    [논문리뷰] Can LLMs Learn from Previous Mistakes? Investigating LLMs’ Errors to Boost for Reasoning

    https://aclanthology.org/2024.acl-long.169/ Can LLMs Learn from Previous Mistakes? Investigating LLMs’ Errors to Boost for ReasoningYongqi Tong, Dawei Li, Sizhe Wang, Yujia Wang, Fei Teng, Jingbo Shang. Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers). 2024.aclanthology.orgACL 2024에 게재된 해당 논문을 간단하게 리뷰한다.정형화된 포맷을 LLM이 알맞게 출력하도록 하는 연구를..

    seq2seq (시퀀스 to 시퀀스)

    seq2seq (시퀀스 to 시퀀스)

    해당 게시물은 "혁펜하임의 AI DEEP DIVE"를 수강하고 작성되었습니다. seq2seq 의 구조는 위 그림과 같다. 각 셀은 LSTM이나 GRU를 주로 사용한다. (장기 의존성 문제를 최대한 해결하고자.. 하지만 100% 해결하지는 못함.) 또한 encoder의 마지막 context vector를 decoder의 처음 context vector으로 사용한다. 위 그림에서 볼 수 있듯 학습 시에는 정답을 decoder의 입력에 넣는다. (teacher forcing이라고 부른다.) 테스트 시에는 sos토큰이 decoder에 들어가서 나오는 출력인 $y_0$을 그 다음 입력으로 사용하고 $y_0$으로부터 나오는 출력인 $y_1$을 그 다음 입력으로 사용하고.. 하는 형태이다. 이를 eos토큰이 나올 때..