본문 바로가기
daily./연구실 TIL

230714 연구실

by 브라이티_ 2023. 7. 14.
반응형

출근: 10시 / 퇴근: 15시 30분

 

[ 일기 ]

오늘은 자연어처리 분야의 QA (Question-Answering) Task에 자주 활용된다고 하는, T5 모델을 팠다. 특정 QA 데이터셋을 통해 T5 모델을 파인튜닝하는 코드를, 연구실 선배님께서 보내주셔서 한번 직접 코랩에서 돌려보고 있었다. 2020년에 작성된 코드라 버전이 안맞는 부분들이 많아서, 그래도 조금씩 수정해가며 코드를 고치고 한 셀씩 잘 돌리고 있었는데, 어떤 오류에서 막혀버렸다.

 

이 오류는 라이브러리의 (실제 구현된) T5 모델 코드에서 발생하고 있는 오류라서 도대체 어떻게 건드려야할지 감이 안와서, 진도가 더 안나갔다. 일단 이 상태로 집에 퇴근했고, 조금 더 해결방법을 찾아보다가 안되면 연구실 선배님들께 한 번 여쭤보려고 한다. 그리고 아나콘다나 허깅페이스 사용법조차 아직 잘 모르는 나라서, 이런 개발환경 설정부터 완전히 이해하고 해봐야할 것 같다. 

 


 

[ 오늘 새롭게 알게 된것 목록 ]

1. 큰 모델일 수록 더 많은 파라미터를 저장할 수있기 때문에, 더 좋은 성능을 보인다.  

A bigger T5 model that can store more parameters does better.

This is not surprising as a bigger model can pack more parameters

 

그렇지만 코랩에서는 T5-base 모델까지밖에 안돌아간다.

 

 

2. 체크포인트(Checkpoint)의 의미

딥러닝 모델 학습시키는 소스코드들을 살펴보면, checkpoint 를 자주 접하게 된다. 사실 이것이 무엇인지, 어떤 역할을 하는지, 왜 쓰는지 등에 대해 정확히 몰랐었기 때문에 이번 기회에 한번 제대로 찾아보았다.

추론(inference) 또는 학습(training)의 재개를 위해 체크포인트(checkpoint) 모델을 저장하고 불러오는 것은 마지막으로 중단했던 부분을 선택하는데 도움을 줄 수 있습니다. 체크포인트를 저장할 때는 단순히 모델의 state_dict 이상의 것을 저장해야 합니다. 모델 학습 중에 갱신되는 버퍼와 매개변수들을 포함하는 옵티마이저(Optimizer)의 state_dict를 함께 저장하는 것이 중요합니다. 이 외에도 중단 시점의 에포크(epoch), 마지막으로 기록된 학습 오차(training loss), 외부 torch.nn.Embedding 계층 등, 알고리즘에 따라 저장하고 싶은 항목들이 있을 것입니다.

참고자료)

https://tutorials.pytorch.kr/recipes/recipes/saving_and_loading_a_general_checkpoint.html

 

결론적으로 모델 학습을 중단했다 재개하기 위해 필요한 장치라고 한다. 

 

 

3. 모델의 reproducibility 확보를 위한 random seed 는 왜 항상 42일까?

 

def set_seed(seed):
    random.seed(seed)
    np.random.seed(seed)
    torch.manual_seed(seed)
    if torch.cuda.is_available():
        torch.cuda.manual_seed_all(seed)

set_seed(42) # 항상 보통 42? - 관례적인 것이라고 한다.

소스코드들을 읽다 보면 항상 42를 집어넣길래, 궁금해서 찾아봤다.

과거 어떤 소설에서 유래해서 그냥 관례적인 것이라고 한다. 사실 꼭 42를 넣을 필요는 없다.

 

참고) https://dacon.io/codeshare/2363

 

 

4. auto regressive language model 의 의미

이전 단어가 무엇이었는지에 따라 그 다음 단어를 예측해서 문장을 생성해내는 것 같이, sequence(순서)의 영향을 받는 언어모델을 의미한다. gpt 계열이 대표적이다. 이전 단어를 바탕으로 확률 계산을 통해 다음 단어를 추론해낸다. 다음은 챗지피티의 자세한 설명이다.

 An auto-regressive language model is a type of language model that predicts the probability distribution of the next word in a sequence of words, given the previous words in the sequence. It generates text by iteratively predicting one word at a time based on the preceding context.In an auto-regressive language model, the output at each time step is conditioned on the previously generated words. It models the conditional probability of the next word given the history of words in the sequence. This type of model is also known as autoregressive because it regresses the prediction of each word on the prior words in the sequence.Auto-regressive language models are typically implemented using recurrent neural networks (RNNs), such as long short-term memory (LSTM) or gated recurrent units (GRUs), or transformer-based architectures like the Transformer model. These models can capture dependencies between words and generate coherent and contextually relevant text.During training, auto-regressive language models are usually trained using techniques like maximum likelihood estimation (MLE) or self-supervised learning. The model is presented with a sequence of words, and it learns to predict the next word in the sequence based on the previous words. The training objective is to maximize the likelihood of the observed data, encouraging the model to generate text that resembles the training data.Auto-regressive language models have a wide range of applications, including text generation, machine translation, speech recognition, and dialogue systems. They are particularly useful when the sequential order of words is important, and they have been pivotal in achieving state-of-the-art performance in various natural language processing tasks.What are the examples of auto regressive lanugage models?ChatGPTThere are several notable examples of auto-regressive language models that have made significant advancements in natural language processing tasks. Some of the prominent ones include:GPT (Generative Pre-trained Transformer): GPT is a series of auto-regressive language models developed by OpenAI. The models in the GPT series, such as GPT-2 and GPT-3, have achieved remarkable performance in various language-related tasks, including text generation, question answering, and language translation.Transformer-XL: Transformer-XL is an auto-regressive language model introduced by Google Research. It improves upon the Transformer model by addressing the limitation of fixed-length contexts. Transformer-XL enables longer-term dependencies in the generation process, leading to more coherent and contextually informed text generation.CTRL (Conditional Transformer Language Model): CTRL is an auto-regressive language model introduced by Salesforce Research. It allows for controlled text generation by conditioning the model on specific prompts or attributes. CTRL has shown effectiveness in generating text that aligns with given instructions or adheres to specific styles or topics.XLNet: XLNet is an auto-regressive language model proposed by Google Research. It leverages permutation-based training, which allows the model to learn bidirectional dependencies between words while maintaining the auto-regressive property during text generation. XLNet has achieved state-of-the-art performance in various natural language processing tasks.T5 (Text-To-Text Transfer Transformer): T5 is a versatile auto-regressive language model introduced by Google Research. It follows a "text-to-text" framework where various natural language processing tasks are cast as text generation problems. T5 has demonstrated strong performance across a wide range of language tasks, including text classification, machine translation, and summarization.These models have made significant contributions to the field of natural language processing and have pushed the boundaries of what is possible in terms of language generation, understanding, and translation.torch.

 

5. model.generate()에서 num_beams 파라미터의 의미

 

참고자료) Beam search (generate 에서의 전략 중 하나)

https://littlefoxdiary.tistory.com/46  

 

모델이 다음 단어를 generate 할 때, 후보로 고려하게 되는 옵션의 개수라고 생각하면 쉽다.  각 타임 스텝에서 가장 가능성 있는 num_beams개의 시퀀스를 유지하고, 최종적으로 가장 확률이 높은 가설을 선택한다.

 


[ TMI ]

금요일은 학교에 사람이 별로 없다. 그래서 그런지 오늘 학식 진짜 역대급 별로였다.

반찬이 김치 콩볶음 동그랑땡2개 실화인가...이러고 4500원이라니...

 

반응형