반응형
블로그 이미지
개발자로서 현장에서 일하면서 새로 접하는 기술들이나 알게된 정보 등을 정리하기 위한 블로그입니다. 운 좋게 미국에서 큰 회사들의 프로젝트에서 컬설턴트로 일하고 있어서 새로운 기술들을 접할 기회가 많이 있습니다. 미국의 IT 프로젝트에서 사용되는 툴들에 대해 많은 분들과 정보를 공유하고 싶습니다.
솔웅

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리


반응형

https://d2l.ai/chapter_attention-mechanisms-and-transformers/index.html

 

11. Attention Mechanisms and Transformers — Dive into Deep Learning 1.0.0-beta0 documentation

 

d2l.ai

11. Attention Mechanisms and Transformers

 

 

10.1. Long Short-Term Memory (LSTM) — Dive into Deep Learning 1.0.0-beta0 documentation

 

d2l.ai

 

The earliest years of the deep learning boom were driven primarily by results produced using the multilayer perceptron, convolutional network, and recurrent network architectures. Remarkably, the model architectures that underpinned many of deep learning’s breakthroughs in the 2010s had changed remarkably little relative to their antecedents despite the lapse of nearly 30 years. While plenty of new methodological innovations made their way into most practitioner’s toolkits—ReLU activations, residual layers, batch normalization, dropout, and adaptive learning rate schedules come to mind—the core underlying architectures were clearly recognizable as scaled-up implementations of classic ideas. Despite thousands of papers proposing alternative ideas, models resembling classical convolutional neural networks (Section 7) retained state of the art status in computer vision and models resembling Sepp Hochreiter’s original design for the LSTM recurrent neural network (Section 10.1), dominated most applications in natural language processing. Arguably, to that point, the rapid emergence of deep learning appeared to be primarily attributable to shifts in the available computational resources (due to innovations in parallel computing with GPUs) and the availability of massive data resources (due to cheap storage and Internet services). While these factors may indeed remain the primary drivers behind this technology’s increasing power we are also witnessing, at long last, a sea change in the landscape of dominant architectures.

 

딥 러닝 붐의 초창기는 주로 다층 퍼셉트론 multilayer perceptron , 컨볼루션 네트워크 convolutional network  및 순환 네트워크 recurrent network 아키텍처를 사용하여 생성된 결과에 의해 주도되었습니다. 놀랍게도, 2010년대 딥 러닝의 돌파구를 뒷받침하는 모델 아키텍처는 거의 30년이 지났음에도 불구하고 선행 모델에 비해 거의 변하지 않았습니다. ReLU activations,  residual layers, batch normalization, dropout, adaptive learning rate schedules 등 대부분의 실무자의 툴킷에 많은 새로운 방법론적 혁신이 도입되었지만 핵심 기본 아키텍처는 고전적인 아이디어의 확장된 구현으로 분명히 인식할 수 있었습니다. 대체 아이디어를 제안하는 수천 개의 논문에도 불구하고 고전적인 컨볼루션 신경망 classical convolutional neural networks(섹션 7)과 유사한 모델은 컴퓨터 비전에서 최첨단 상태를 유지했으며 Sepp Hochreiter의 LSTM 순환 신경망 recurrent neural network (섹션 10.1)에 대한 원래 설계와 유사한 모델은 자연 언어 처리에서 대부분의 애플리케이션을 지배했습니다. 아마도 그 시점까지 딥 러닝의 급속한 출현은 주로 사용 가능한 컴퓨팅 리소스의 변화(GPU를 사용한 병렬 컴퓨팅의 혁신으로 인해)와 대용량 데이터 리소스의 가용성(저렴한 스토리지 및 인터넷 서비스로 인해)에 기인한 것으로 보입니다.. 이러한 요인들이 실제로 이 기술의 힘을 증가시키는 주요 동인으로 남아있을 수 있지만, 마침내 우리는 지배적인 아키텍처의 지형에서 엄청난 변화를 목격하고 있습니다.

 

At the present moment, the dominant models for nearly all natural language processing tasks are based on the Transformer architecture. Given any new task in natural language processing, the default first-pass approach is to grab a large Transformer-based pretrained model, (e.g., BERT (Devlin et al., 2018), ELECTRA (Clark et al., 2020), RoBERTa (Liu et al., 2019), or Longformer (Beltagy et al., 2020)) adapting the output layers as necessary, and fine-tuning the model on the available data for the downstream task. If you have been paying attention to the last few years of breathless news coverage centered on OpenAI’s large language models, then you have been tracking a conversation centered on the GPT-2 and GPT-3 Transformer-based models (Brown et al., 2020, Radford et al., 2019). Meanwhile, the vision Transformer has emerged as a default model for diverse vision tasks, including image recognition, object detection, semantic segmentation, and superresolution (Dosovitskiy et al., 2021, Liu et al., 2021). Transformers also showed up as competitive methods for speech recognition (Gulati et al., 2020), reinforcement learning (Chen et al., 2021), and graph neural networks (Dwivedi and Bresson, 2020).

 

현재 거의 모든 자연어 처리 작업에 대한 지배적인 모델은 Transformer 아키텍처를 기반으로 합니다. 자연어 처리의 새로운 작업이 주어지면 기본 1차  접근 방식은 큰 Transformer 기반 사전 훈련된 모델(예: BERT(Devlin et al., 2018),  ELECTRA(Clark et al., 2020), RoBERTa (Liu et al., 2019) 또는 Longformer(Beltagy et al., 2020))로서  필요에 따라 output layers를 adapting하고 다운스트림 작업을 위한 available data 에 대해 모델을 미세 조정 fine-tuning합니다. 지난 몇 년간 OpenAI의 대규모 언어 모델을 중심으로 한 숨가쁜 뉴스 보도에 관심을 가졌다면 당신은 GPT-2 및 GPT-3 Transformer 기반 모델을 중심으로 한 대화를 추적해 왔을 겁니다 (Brown et al., 2020). , Radford et al., 2019). 한편, 비전 트랜스포머는 이미지 인식, 물체 감지, semantic segmentation, 초고해상 superresolution도 등 다양한 비전 작업을 위한 기본 모델로 등장했다(Dosovitskiy et al., 2021, Liu et al., 2021). 트랜스포머는 또한 음성 인식 speech recognition(Gulati et al., 2020), 강화 학습 reinforcement learning(Chen et al., 2021) 및 그래프 신경망 graph neural networks(Dwivedi and Bresson, 2020)을 위한 경쟁 방법으로 나타났습니다.

 

The core idea behind the Transformer model is the attention mechanism, an innovation that was originally envisioned as an enhancement for encoder-decoder RNNs applied to sequence-to-sequence applications, like machine translations (Bahdanau et al., 2014). You might recall that in the first sequence-to-sequence models for machine translation (Sutskever et al., 2014), the entire input was compressed by the encoder into a single fixed-length vector to be fed into the decoder. The intuition behind attention is that rather than compressing the input, it might be better for the decoder to revisit the input sequence at every step. Moreover, rather than always seeing the same representation of the input, one might imagine that the decoder should selectively focus on particular parts of the input sequence at particular decoding steps. Bahdanau’s attention mechanism provided a simple means by which the decoder could dynamically attend to different parts of the input at each decoding step. The high level idea is that the encoder could produce a representation of length equal to the original input sequence. Then, at decoding time, the decoder can (via some control mechanism) receive as input a context vector consisting of a weighted sum of the representations on the input at each time step. Intuitively, the weights determine the extent to which each step’s context “focuses” on each input token, and the key is to make this process for assigning the weights differentiable so that it can be learned along with all of the other neural network parameters.

 

Transformer 모델의 핵심 아이디어는 attention mechanism 입니다. 원래 기계 번역 machine translation과 같은 sequence-to-sequence applications에 적용된 encoder-decoder RNNs을 개선한 것으로 혁신적인 개념입니다.(Bahdanau et al., 2014). 당신은 기계 번역을 위한 첫 번째 sequence-to-sequence 모델(Sutskever et al., 2014)에서 전체 입력이 인코더에 의해 단일 고정 길이 벡터로 압축되어 디코더에 공급되었음을 기억할 것입니다. attention 뒤에 숨겨진 직관 intuition 은 입력을 압축하는 것보다 디코더가 every step에서 input sequencerevisit 하는 것이 더 나을 수 있다는 것입니다. 더욱이, input의 동일한 representation 을 항상 보는 것보다 디코더가 특정 디코딩 단계에서 입력 시퀀스의 특정 부분에 선택적으로 초점을 맞춰야 한다고 생각할 수 있습니다. Bahdanau’s attention mechanism은 디코더가 각 디코딩 단계에서 입력의 다른 부분에 동적으로 attend 할 수 있는 (주의를 기울일 수 있는) 간단한 수단을 제공했습니다. high level idea는 인코더가 원래 입력 시퀀스와 동일한 길이의 representation 을 생성할 수 있다는 것입니다. 그런 다음 디코딩 시간에 디코더는 (일부 제어 메커니즘을 통해) 각 시간 단계에서 입력에 대한 representations 의 가중 합으로 구성된 컨텍스트 벡터를 입력으로 수신할 수 있습니다. 직관적으로 가중치 weights 는 각 단계의 컨텍스트가 각 입력 토큰에 "focuses" 정도를 결정하며, 핵심은 다른 모든 신경망 매개변수와 함께 학습될 수 있도록 가중치를 미분 가능하게 할당하는 이 프로세스를 만드는 것입니다.

 

Initially, the idea was a remarkably successful enhancement to the recurrent neural networks that already dominated machine translation applications. The models performed better than the original encoder-decoder sequence-to-sequence architectures. Moreover, researchers noted that some nice qualitative insights sometimes emerged form inspecting the pattern of attention weights. In translation tasks, attention models often assigned high attention weights to cross-lingual synonyms when generating the corresponding words in the target language. For example, when translating the sentence “my feet hurt” to “j’ai mal au pieds”, the neural network might assign high attention weights to the representation of “feet” when generating the corresponding French word “pieds”. These insights spurred claims that attention models confer “interpretability” although what precisely the attention weights mean—i.e., how, if at all, they should be interpreted remains a hazy research topic.

 

초기에 이 아이디어는 이미 machine translation applications을 지배하고 있던 recurrent neural networks을 놀랍도록 성공적으로 개선한 것이었습니다. 모델은 original encoder-decoder sequence-to-sequence architectures보다 성능이 뛰어났습니다. 더욱이 연구원들은 attention weights의 패턴을 조사하는 과정에서 때때로 좋은 질적 통찰력이 나타났다고 지적했습니다. 번역 작업에서 attention modelscorresponding wordstarget language로 생성할 때 교차 언어 동의어 cross-lingual synonyms에 높은 attention weights를 할당하는 경우가 많습니다. 예를 들어, "my feet hurt"라는 문장을 "j'ai mal au pieds"로 번역할 때 신경망은 해당 프랑스어 단어 "pieds"를 생성할 때 "feet" 표현에 high attention weights를 할당할 수 있습니다. 이러한 통찰력 insights attention weights 가 가지는 의미에도 불구하고 이런 어텐션 모델이 "해석 가능성 interpretability"을 부여한다는 주장 (이 모델이 의미가 연결되도록 해석하고 있다는 주장)에 박차를 가했습니다. — 만약 그렇다면 그것들은 해석되어야 (interpreted) 한다는 것이고 이것은 모호한 연구 주제로 여전히 남아 있습니다.

 

However, attention mechanisms soon emerged as more significant concerns, beyond their usefulness as an enhancement for encoder-decoder recurrent neural networks and their putative usefulness for picking out salient inputs. In 2017, Vaswani et al. (2017) proposed the Transformer architecture for machine translation, dispensing with recurrent connections together, and instead relying on cleverly arranged attention mechanisms to capture all relationships among input and output tokens. The architecture performed remarkably well, and by 2018 the Transformer began showing up in the majority of state-of-the-art natural language processing systems. Moreover, at the same time, the dominant practice in natural language processing became to pretrain large-scale models on enormous generic background corpora to optimize some self-supervised pretraining objective, and then to fine-tune these models using the available downstream data. The gap between Transformers and traditional architectures grew especially wide when applied in this pretraining paradigm, and thus the ascendance of Transformers coincided with the ascendence of such large-scale pretrained models, now sometimes called foundation models (Bommasani et al., 2021).

 

attention mechanisms는 encoder-decoder recurrent neural networks 같은 유용성과 sailent inputs를 선택하기 위한 putative 한 유용성을 넘어 선 좀 더 중요한 문제로 금방 부상 됐습니다.  2017년에 Vaswani et al. (2017)은 machine translation을 위한 Transformer architecture를 제안했습니다. 이는 recurrent connections들을 같이 dispensing  (처리)하는 대신에 input and output tokens들 사이의  모든 relationships 를 캡처하는 cleverly arrangedattention mechanisms에 의존하는 것이었습니다. 아키텍처는 놀라울 정도로 잘 작동했으며 2018년에 Transformer는 대부분의 최첨단 자연어 처리 시스템에 나타나기 시작했습니다. 또한 동시에  pretrain large-scale models은 natural language processing의 지배적인 practice가 되었습니다. 이것은 self-supervised pretraining objective를 최적화하기 위한 거대한 generic background corpora이며 가능한 downstream data를 사용해서 이 model들을 fine-tune 하는 것입니다. Transformers와 기존 아키텍처 사이의 격차는 이 사전 pretraining paradigm이 적용될 때 특히 커졌으며, 따라서 Transformers의 ascendence(조상)은 그러한 large-scale pretrained models 의 ascendence (조상) 과 일치합니다. 지금은 종종 이것을 foundation models라고 합니다.(Bommasani et al., 2021).

 

In this chapter, we introduce attention models, starting with the most basic intuitions and the simplest instantiations of the idea. We then work our way up to the Transformer architecture, the vision Transformer, and the landscape of modern Transformer-based pretrained models.

 

이 장에서는 가장 기본적인 직관 intuitions 과 아이디어의 가장 간단한 인스턴스화부터 시작하여 attention models을 소개합니다. 그런 다음 Transformer 아키텍처, Transformer 비전 및 최신 Transformer 기반 사전 학습 모델의 환경까지 작업합니다.

 

https://youtu.be/AA621UofTUA

https://github.com/ndb796/Deep-Learning-Paper-Review-and-Practice/blob/master/lecture_notes/Transformer.pdfhttps://github.com/ndb796/Deep-Learning-Paper-Review-and-Practice/blob/master/code_practices/Attention_is_All_You_Need_Tutorial_(German_English).ipynb

 

 

https://arxiv.org/abs/1706.03762

 

Attention Is All You Need

The dominant sequence transduction models are based on complex recurrent or convolutional neural networks in an encoder-decoder configuration. The best performing models also connect the encoder and decoder through an attention mechanism. We propose a new

arxiv.org

 

반응형