Post

[Paper]T5

“Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer” 논문은 google research 팀에서 발표한 내용으로 Text-To-Text Transfer Transformer(T5)는 전이 학습 기술을 찾는 경험적 연구들의 인사이트에 관한 내용입니다.

Ⅰ. Introduction

해당 논문에서 모든 text 기반의 언어 문제를 text-to-text 형태로 전환하는 통일된 프레임워크를 소개함으로서 NLP의 전이 학습 기술의 현황을 보여줍니다.

Colossal Clean Crawled Corpus (C4)라는 open-soruce 데이터셋을 활용하여 학습되었으며 인코더 구성 요소에 사용될 최적의 사전학습 목표로 span corruption을 사용합니다.

다시 말해, 다른 길이의 단어(spans)들은 특정 문자(placeholders)들로 교체되며 모델이 이를 디코딩하도록 합니다.

BERT와 달리 T5에서는 디코더가 입력이나 class label의 span만을 출력합니다. 이는 모든 NLP 작업을 입력과 출력이 항상 text string의 연속이 되도록 통일된 Text-to-Text 형태로 재구성합니다.

이러한 결과로 NLP 작업에 동일한 모델, 손실 함수, 하이퍼파라미터들을 적용가능합니다.

Ⅱ. Text-to-Text

1 Figure 1 : Text-to-Text format, 모든 작업의 입력을 해당 모델에 적용시켜 목표 텍스트를 생성한다. 이러한 방법은 같은 모델, loss 함수, 하이퍼파라미터를 다양한 작업에 걸쳐 사용합니다.

위에서 설명했듯이 모든 텍스트 과제를 Text-to-Text 프레임워크로 전환하고 같은 모델, 목적, 학습, 디코딩 절차를 적용합니다.

즉, 모델은 일부 텍스트를 문맥 또는 조건으로 받고나서 출력 텍스트를 생성하도록 요청되는 작업입니다. 해당 프레임워크는 사전학습 및 미세조정을 위한 학습 목표를 제공합니다.

모델이 수행햐야하는 작업을 명시하기 위해 모델은 task-specific한 prefix를 원본 입력 시퀀스에 추가해야합니다.

위에 대한 예시로 “That is good”을 번역하기 위해서 “translate Englsih to German: That is good.”을 제공하여 번역된 값을 출력하도록 훈련합니다.

Ⅲ. Model

ⅰ. Objective

최근 Unsupervised objective로 “denoising objective”가 주목받았습니다. 이러한 목적은 모델이 사라지거나 손상된 토큰들을 예측하도록 학습하는 것입니다.

BERT에서의 MLM은 각 토큰은 개별적인 [MASK] 토큰으로 대체했으나 해당 모델에서는 SpanBERT에서 나온 span-corruption objective를 위한 denoising objective를 사용합니다.

2 _Figure 2 : Original text의 span을 특정 토큰 , 로 대체하고 마지막에 를 추가해 mask된 text들을 분할하여 출력으로 지정합니다._

Figure 2 처럼 unlabeled data 집합에서 텍스트의 span을 샘플링하고, 랜덤한 위치에서 prefix와 목표 부분을 분리합니다. 일반적인 언어 모델의 경우 모델이 시작부터 끝까지 전체 span을 예측하도록 학습하지만, 해당 모델의 목표는 text-to-text 모델을 위해 설계되어 입력과 목표를 Figure 2 처럼 입력과 출력을 연결합니다.

1
2
3
4
5
6
7
8
9
10
11
def tokenize(self, text: "TextInput", **kwargs) -> List[str]:

    ...

    text = text.replace(SPIECE_UNDERLINE, " ")
    if self.add_prefix_space:
        text = SPIECE_UNDERLINE + text

    ...
    
    return tokens

ⅱ. Architecture

해당 모델은 원래의 Transformer 모델과 거의 동일한 인코더-디코더 구조 입니다.

3 Figure 3:(왼쪽) 셀프어텐션 매커니즘이 매 출력 단계마다 전체 입력을 볼 수 있게 함 (가운데) i번째 출력 “미래”의 입력 요소에 의존하는 것을 방지함 (오른쪽) Causal masking에서 prefix만 허용함.

Figure 3에 나와있는 것처럼 인코더의 셀프어텐션은 Fully-visible mask를 진행하고, 디코더의 셀프어텐션은 Causal mask를 사용합니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# We can provide a self-attention mask of dimensions [batch_size, from_seq_length, to_seq_length]
# ourselves in which case we just need to make it broadcastable to all heads.
attention_mask = tf.cast(attention_mask, dtype=inputs_embeds.dtype)
num_dims_attention_mask = len(shape_list(attention_mask))
if num_dims_attention_mask == 3:
    extended_attention_mask = attention_mask[:, None, :, :]
elif num_dims_attention_mask == 2:
    # Provided a padding mask of dimensions [batch_size, mask_seq_length]
    # - if the model is a decoder, apply a causal mask in addition to the padding mask
    # - if the model is an encoder, make the mask broadcastable to [batch_size, num_heads, mask_seq_length, mask_seq_length]
    if self.is_decoder:
        seq_ids = tf.range(mask_seq_length)
        causal_mask = tf.less_equal(
            tf.tile(seq_ids[None, None, :], (batch_size, mask_seq_length, 1)),
            seq_ids[None, :, None],
        )
        causal_mask = tf.cast(causal_mask, dtype=attention_mask.dtype)
        extended_attention_mask = causal_mask[:, None, :, :] * attention_mask[:, None, None, :]
        if past_key_values[0] is not None:
            extended_attention_mask = extended_attention_mask[:, :, -seq_length:, :]
    else:
        extended_attention_mask = attention_mask[:, None, None, :]

4 Figure 4 : T5 Architecture, (왼쪽) 인코더와 인코더-디코더 구조에서 Fully-visible masking 사용하고, 디코더에서 Causal masking을 사용 (가운데) 단일 Transformer layer을 연속적으로 쌓는 형태로 causal mask를 사용해 입력과 목표의 연결이 공급된다 (오른쪽) prefix를 추가하는 것은 입력에 fully-visible 허용하는 것입니다.

Figure 4에 나온 것처럼 인코더-디코더 구조로 이루어져있으며 디코더만 사용하여 LM으로 사용거나 prefix LM으로 사용할 수 있습니다. 특히, prefix를 추가하는 것은 해당 모델이 어떤 작업을 수행해야 하는지 알려주는 것으로 다양한 작업을 통일된 Text-to-Text 형식으로 만들 수 있는 주된 이유입니다.

Ⅳ. REFERENCES

  1. google-research/text-to-text-transfer-transformer github
  2. Pytorch T5
  3. huggingface T5 github



This post is licensed under CC BY 4.0 by the author.