1. Sentece Piece
설치
초기화
2. Sentencepiece in Python
2.1 Train with text File
- input: 학습 파일 위치
- model_prefix: 모델이름
- vocab_size: vocabulary 단어 크기
-
model_type: unigram (default) |
bpe |
char |
word |
- max_sentence_length: 문장 최대 길이
- pad_id: pad token ID
- unk_id: unknown token ID
- bos_id: Begin of sentence token ID
- eos_id: End of sentence token ID
- user_defined_symbols: 사용자 정의 토큰
2.2 Encoding and Decoding
텍스트 한개의 경우
- sentencepiece.Encode(text) 는 EncodeAsIds 와 동일
- sentencepiece.EncodeAsIds(text) -> [12, 14, 2, 3, …]
- sentencepiece.EncodeAsPieces(text) -> [‘▁잼있’, ‘고’, ‘▁신나’, ‘는’, …]
- sentencepiece.Encode(encoded_text) -> “잼있고 신나는 …”
텍스트가 여러개인 경우