본문 바로가기

논문

Neural Machine Translation of Rare Words with Subword Units(BPE) 리뷰

Abstract(초록)

  • 과거 - backing off(you go back to a n-1 gram level to calculate the probabilities when you encounter a word with prob=0 : 자연어처리에서 특정 상황을 처리할 수 없을 때 사전조회 같은 일반적인 방법으로 돌아가는 방식) 활용 -> 문제점 제시
  • open-vocabulary문제를 해결하는 신경망 기계번역 모델 소개
  • word segmentation 기술(서브워드 분리기술) 제시 - simple character n-gram model, BPE(byte pair encoding)

1. Introduction

  • rare words : 자주 사용되지 않아서 어휘 목록이나 사전에 포함되지 않는 단어들
    • productive word foramtion : 교착어, 합성어
      • 예시) 합성어 - 분리되고(segmented) 다양한 길이(variable-length)의 표현방식은 고정된 길이의 벡터로 표현할 때 유용
    • OOV단어 번역 처리 : back-off방식 -> 문제
      • Out-Of-Vocabulary : 어휘목록에 없는
  • subword 수준의 새로운 신경망번역 모델
    • 목표 : rare words에 대해 back-off model이 필요하지 않은 채로 open-vocabulary(subword 단위를 통해 (rare) words를 encoding) 번역을 수행
      • 개선점1 : 기존 large-vocabulary 모델과 back-off dictionary보다 좋은 정확도
      • 개선점2 : subword representation으로부터 compounding(합성어 형성)과 transliteration(발음중심 문자변환)을 학습
  • 해당 논문에서 사용한 알고리즘 : byte pair encoding(BPE) -> 고정된 크기의 character(어휘)로 다양한 길이의 문자 sequences(시퀀스)를 표현

2. Neural Machine Translation(NMT)

  • 신경기계망번역(NMT) system : RNN 중 encoder-decoder network로 구현
    • encoder : gated recurrent units(GRU)를 포함한 bidirectional neural network,
    • encoder방법 : input sequence를 forward sequence of hiddne states와 backward sequence를 계산 후, 각각의 hidden states를 이어붙여(concat) annotation vector(hj) 얻기
    • x = (x1, ..., xm) and calculates a forward sequence of hidden states ( −→h 1, ..., −→h m), and a backward sequence ( ←−h 1, ..., ←−h m). The hidden states −→h j and ←−h j are concatenated to obtain the annotation vector hj .
      • GRU : Hidden states와 Update gate(이전정보 얼마나 유지할지)-Reset gate(얼마나 초기화할지)를 통해 장기 의존성 문제 해결 및 시퀀스 데이터 처리  RNN
      • bidirectional neural network(양방향 신경망) : 두 가지 방향(앞뒤 양쪽 방향, 해당 시점 이전과 이후의 정보를 모두 고려할 수 있는)으로 처리하여 학습하는 신경망 구조
    •  decoder  : target sequence를 예측하는 RNN
      • target sequence의 각각의 원소는 recurrent hidden state(si), 이전에 예측된 단어(ci), annotation vector(hj)들의 가중합으로 계산되는 context vector(αij)에 의해 예측
        • recurrent hidden state(si) + previously predicted word(ci) + annotation vector(hj) = context vector(αij)

encoder
forward sequence of hidden states, backward sequence
annotation vector
decoder


3. Subword Translation

  • rare word가 rare token으로 분해되어 분석할 수 있는 가능성 -> subword 단위로 나누는것
  • the translation of some words is transparent in that they are translatable by a competent translator even if they are novel to him or her, based on a translation of known subword units such as morphemes or phonemes

3-1. Related Work

  • Statiscal Machine Translation(SMT, 통계적 기계번역)에서 나오는 unknown word(데이터셋에 없는 단어) 문제
    • unknown word대부분은 name
  • SMT에서 다양한 segmentation 알고리즘 활용
    • Phrase-based SMT의 segmentation은 알고리즘은 보수적 경향 (-)
    • back-off방식에 의지하지 않고, open-vocabulary번역을 가능하게 방법 사용 -> compact representation
      • compact representation(압축 표현) : text가 길어지면 정보전달 distance가 길어져 효율성이 떨어지는 문제 방지하기 위해, 간결하고 효율적인 방법 추구

3-2. Byte Pair Encoding(BPE)

  • BPE : byte pair을 사용하지 않는 simple data compression techinque(하나의 byte로 반복적으로 대체하는 data 압축기술) 사용
    • byte pair : 두 개의 바이트 쌍
  • symbol vocabulary -> character vocabulary로 초기화 후, sequence of characters(어휘 시퀀스)로 표현 후 붙이기,  symbol의 개수를 세어, iteratively count all symbol pairs(반복적으로 병합하는 과정) 시행
    • character vocabulary : 문자 어휘로 초기화,
      • 예) 'banana'라면 -> ['b', 'a', 'n', '・'] 표현
    • iteratively count all symbol pairs 과정 : 자주 등장하는 쌍을 찾고, 병합. 이 과정 반복
      • ('a', 'n')이 자주 등장, 'an'을 새로운 심볼로 병합, "banana" -> ['b', 'an', 'a', 'n', 'a', '・']
      • ('an', 'a')이 자주 등장, 'ana'를 새로운 심볼로 병합,  "banana" -> ['b', 'ana', 'na', '・']
      • 'na'가 자주 등장, 'na'를 새로운 심볼로 병합, "banana" -> ['b', 'ana', 'na', '・']
    • 최종 symbol vocabulary의 크기 = character vocabulary 크기 + 병합과정의 수(하이퍼파라미터)
      • 초기 어휘: ['b', 'a', 'n', '・']
      • 병합된 심볼: ['an', 'ana', 'na']
      • 최종 어휘 크기: 4 + 3 = 7

import re, collections

def get_status(vocab):
    pairs = collections.defaultdict(int)
    for word, freq in vocab.items():
        symbols = word.split()
        for i in range(len(symbols)-1):
            pairs[symbols[i], symbols[i+1]] += freq
    return pairs

def merge_vocab(pair, v_in):
    v_out = {}
    bigram = re.escape(' '.join(pair))
    p = re.compile(r'(?<!\S)' + bigram + r'(?!\S)') 
    for word in v_in:
        w_out = p.sub(''.join(pair), word)
        v_out[w_out] = v_in[word]
    return v_out

vocab = {'l o w </w>' : 5, 'l o w e r </w>' : 2,
         'n e w e s t </w>': 6, 'w i d e s t </w>': 3}
    
num_merges = 10
for i in range(num_merges):
    pairs = get_status(vocab)
    best = max(pairs, key=pairs.get)
    vocab = merge_vocab(best, vocab)
    print(best)

  • 기존 compression(압축) 알고리즘과 비교  : BPE를 사용한 방법은 subword units을 해석 가능하다는 점과 새로운 단어를 번역하고 만들어내는 것에 일반화 학습 가능

4. Evaluation

  • 목표 제시 : 
    • subword unit으로 표현된 rare, unseen 단어들을 NMT(신경망기계번역)으로 번역 성능을 높이는지
    • terms of vocabulary size, text size, and translation quality에서 어떤 segmentation이 가장 높은 성능을 보이는지
  • CHRF3 (Popovi´c, 2015), a character n-gram F3 score는 인간의 판단과 상관관계가 높다는 특징으로 사용

4-1. Subword statistics 

  • 번역의 질과 별개로 논문의 목적은 compact fixed-size subword vocabulary(서브워드 단위로 이뤄진 어휘집)를 통한 open vocabulary 표현과 훈련, decoding의 효율을 높이는 것

  • character n-gram : n의 값에 따라 sequence length(tokens)와 vocabulary size(types)사이의 trade-off(하나를 얻기 위해 다른 하나를 포기해야 하는) 발생, unknown문제 해결X
  • BPE로 학습된 merge operation은 test set에 적용되어 unknown symbol 발생하지 않으므로 segmentation 수행
    • shorter sequences 허용, attention model변화에 unit 적용

4-2. Translation experiments

  • WDict: back-off방식을 이용한 word-level모델, unigram F1값 높이는 방법
  • WUnk : OOV단어를 UNK(unknown) 토큰으로 표현
  • BPE : 논문에서 말하려는 방법
    • BPE-J90K : BPE symbol로 학습한 모델, 90,000BPE 단위 학습, rare단어 처리
    • BPE-60K : BPE 단위 학습 모델, 60,000 BPE 단위 학습
    • BPE-J90K > BPE-60K 의미 : J90K모델이 60K보다 rare 단어 처리에서 높은 Unigram F1 점수 획득, 서브워드 단위 처리에서 더 높은 성능을 보임

5. Analysis

5.1 Unigram accuracy

  • rare and unknown 단어 처리 문제에서 word-level NMT보다 subword이 번역 성능 더 높음
  • target-side 단어를 training set에 등장 빈도로 그래프 정렬

  • Figure2 : 영어 -> 독일어 unigram F1점수
  • Figure3 : 영어 -> 러시아어 unigram F1점수
  • 모델성능 그래프에서 보여주는 점 : 
    • WUnk < WDict < BPE 모델순으로 ungiram F1점수가 차이난다. 따라서 이 순서대로 모델의 성능을 평가\

5.2 Manual Analysis

  • Table 4 shows two translation examples for the translation direction English→German, Table 5 for English→Russian. The baseline system fails for all of the examples, either by deleting content (health), or by copying source words that should be translated or transliterated. The subword translations of health research institutes show that the subword systems are capable of learning translations when oversplitting (research→Fo|rs|ch|un|g), or when the segmentation does not match morpheme boundaries: the segmentation Forschungs|instituten would be linguistically more plausible, and simpler to align to the English research institutes, than the segmentation Forsch|ungsinstitu|ten in the BPE-60k system, but still, a correct translation is produced. If the systems have failed to learn a translation due to data sparseness, like for asinine, which should be translated as dumm, we see translations that are wrong, but could be plausible for (partial) loanwords (asinine Situation→Asinin-Situation).

6. Conclusion

  • Subword units를 사용한 NMT 방식이 rare and unknown 단어를 효과적으로 처리
  • Symbol vacabulary -> chracter vocabulary 초기화 -> sequence 표현 : 어휘 크기 줄이기가 모델 성능 향상에 도움 입증
  • Sequence를 어떻게 찾는지 추가 연구 시사