Tokenization의 개념

토큰화, 주어진 text를 Token 단위로 분리하는 방법

대표적인 Tokenization 방법론의 종류와 개념

Word-level Tokenization

Token을 단어(Word) 단위로 구분

입력 – “The devil is in the details”

출력 – [‘The’, ‘devil’, ‘is’, ‘in’, ‘the’, ‘details’]

단점: 사전에 없는 단어가 등장할 경우, 모두 Unknown 토큰으로 처리. Out-of-vocabulary(OOV) 문제

Chartacter-level Tokenization

Token을 철자 (Character) 단위로 구분

입력 – “The devil is in the details” 출력 – [‘T’, ‘h’, ‘e’, ‘ ‘, ‘d’, ‘e’, ‘v’, ‘i’, ‘l’, ‘ ’, ‘i’, ‘s’, ‘ ’, ‘i’, ‘n’, ‘ ’, ‘t’, ‘h’, ‘e’, ‘ ’, ‘d’, ‘e’, ‘t’, ‘a’, ‘i’, ‘l’, 's’]

단점: 주어진 텍스트에 대한 Token의 개수가 지나치게 많아짐. 낮은 성능

Subword-level Tokenization

Token을 Subword 단위로 구분

입력 – “The devil is in the details” 출력 – [‘The’, ‘ ’, ‘de’, ‘vil’, ‘ ’, ‘is’, ‘ ’, ‘in’, ‘ ’, ‘the’, ‘ ’, ‘de’, ‘tail’, ‘s’]

장점: 철자 단위 Tokenization 방식에 비해 사용되는 Token의 평균 개수가 적다. OOV 문제가 없다. 뛰어난 성능

BPE(Byte Pair Encoding)

Subword-level Tokenization의 예시

철자 단위의 단어 목록을 만든다.

가장 빈도 수가 높은 단어 pair를 token으로 추가한다.