Skip to content

Commit f723117

Browse files
seoppyijun-lee
andauthored
🌐 [i18n-KO] Translated tokenizer.md to Korean (#39532)
* docs: ko: tokenizer.md * feat: nmt draft * fix: manual edits * fix: resolve suggestions Co-authored-by: Yijun Lee <[email protected]> Co-authored-by: Yijun Lee <[email protected]> * fix: resolve suggestions Co-authored-by: Yijun Lee <[email protected]> --------- Co-authored-by: Yijun Lee <[email protected]>
1 parent d346d46 commit f723117

File tree

2 files changed

+84
-2
lines changed

2 files changed

+84
-2
lines changed

docs/source/ko/_toctree.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@
336336
title: PEFT
337337
- local: in_translation
338338
title: (번역중) Pipelines
339-
- local: in_translation
340-
title: (번역중) Processors
339+
- local: main_classes/tokenizer
340+
title: 토크나이저
341341
- local: main_classes/quantization
342342
title: 양자화
343343
- local: in_translation
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<!--Copyright 2020 The HuggingFace Team. All rights reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4+
the License. You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
specific language governing permissions and limitations under the License.
11+
12+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
13+
rendered properly in your Markdown viewer.
14+
15+
-->
16+
17+
# 토크나이저[[tokenizer]]
18+
19+
토크나이저는 모델의 입력을 준비하는 역할을 담당합니다. 이 라이브러리에는 모든 모델을 위한 토크나이저가 포함되어 있습니다. 대부분의 토크나이저는 두 가지 버전으로 제공됩니다. 완전한 파이썬 구현과 Rust 라이브러리 [🤗 Tokenizers](https://github.com/huggingface/tokenizers)에 기반한 "Fast" 구현입니다. "Fast" 구현은 다음을 가능하게 합니다:
20+
21+
1. 특히 배치 토큰화를 수행할 때 속도가 크게 향상됩니다.
22+
2. 원본 문자열(문자 및 단어)과 토큰 공간 사이를 매핑하는 추가적인 메소드를 제공합니다. (예: 특정 문자를 포함하는 토큰의 인덱스를 얻거나, 특정 토큰에 해당하는 문자 범위를 가져오는 등).
23+
24+
기본 클래스인 [`PreTrainedTokenizer`][`PreTrainedTokenizerFast`]는 문자열 입력을 인코딩하는 메소드를 구현하며(아래 참조), 로컬 파일이나 디렉토리, 또는 라이브러리에서 제공하는 사전 훈련된 토크나이저(HuggingFace의 AWS S3 저장소에서 다운로드된)로부터 파이썬 및 "Fast" 토크나이저를 인스턴스화하거나 저장하는 기능을 제공합니다. 이 두 클래스는 공통 메소드를 포함하는 [`~tokenization_utils_base.PreTrainedTokenizerBase`][`~tokenization_utils_base.SpecialTokensMixin`]에 의존합니다.
25+
26+
[`PreTrainedTokenizer`][`PreTrainedTokenizerFast`]는 모든 토크나이저에서 사용되는 주요 메소드들을 구현합니다:
27+
28+
- 토큰화(문자열을 하위 단어 토큰 문자열로 분할), 토큰 문자열을 ID로 변환 및 그 반대 과정, 그리고 인코딩/디코딩(즉, 토큰화 및 정수로 변환)을 수행합니다.
29+
- 구조(BPE, SentencePiece 등)에 구애받지 않고 어휘에 새로운 토큰을 추가합니다.
30+
- 특수 토큰(마스크, 문장 시작 등) 관리: 토큰을 추가하고, 쉽게 접근할 수 있도록 토크나이저의 속성에 할당하며, 토큰화 과정에서 분리되지 않도록 보장합니다.
31+
32+
[`BatchEncoding`][`~tokenization_utils_base.PreTrainedTokenizerBase`]의 인코딩 메소드(`__call__`, `encode_plus`, `batch_encode_plus`)의 출력을 담고 있으며, 파이썬 딕셔너리를 상속받습니다. 토크나이저가 순수 파이썬 토크나이저인 경우 이 클래스는 표준 파이썬 딕셔너리처럼 동작하며, 이러한 메소드들로 계산된 다양한 모델 입력(`input_ids`, `attention_mask` 등)을 갖습니다. 토크나이저가 "Fast" 토크나이저일 경우(즉, HuggingFace [tokenizers 라이브러리](https://github.com/huggingface/tokenizers) 기반일 경우), 이 클래스는 추가적으로 원본 문자열(문자 및 단어)과 토큰 공간 사이를 매핑하는 데 사용할 수 있는 여러 고급 정렬 메소드를 제공합니다 (예: 특정 문자를 포함하는 토큰의 인덱스를 얻거나, 특정 토큰에 해당하는 문자 범위를 얻는 등).
33+
34+
35+
# 멀티모달 토크나이저[[multimodal-tokenizer]]
36+
37+
그 외에도 각 토크나이저는 "멀티모달" 토크나이저가 될 수 있으며, 이는 토크나이저가 모든 관련 특수 토큰을 토크나이저 속성의 일부로 저장하여 더 쉽게 접근할 수 있도록 한다는 것을 의미합니다. 예를 들어, LLaVA와 같은 비전-언어 모델에서 토크나이저를 가져오면, `tokenizer.image_token_id`에 접근하여 플레이스홀더로 사용되는 특수 이미지 토큰을 얻을 수 있습니다.
38+
39+
모든 유형의 토크나이저에 추가 특수 토큰을 활성화하려면, 다음 코드를 추가하고 토크나이저를 저장해야 합니다. 추가 특수 토큰은 반드시 특정 모달리티와 관련될 필요는 없으며, 모델이 자주 접근해야 하는 어떤 것이든 될 수 있습니다. 아래 코드에서 `output_dir`에 저장된 토크나이저는 세 개의 추가 특수 토큰에 직접 접근할 수 있게 됩니다.
40+
41+
```python
42+
vision_tokenizer = AutoTokenizer.from_pretrained(
43+
"llava-hf/llava-1.5-7b-hf",
44+
extra_special_tokens={"image_token": "<image>", "boi_token": "<image_start>", "eoi_token": "<image_end>"}
45+
)
46+
print(vision_tokenizer.image_token, vision_tokenizer.image_token_id)
47+
("<image>", 32000)
48+
```
49+
50+
## PreTrainedTokenizer[[transformers.PreTrainedTokenizer]]
51+
52+
[[autodoc]] PreTrainedTokenizer
53+
- __call__
54+
- add_tokens
55+
- add_special_tokens
56+
- apply_chat_template
57+
- batch_decode
58+
- decode
59+
- encode
60+
- push_to_hub
61+
- all
62+
63+
64+
## PreTrainedTokenizerFast[[transformers.PreTrainedTokenizerFast]]
65+
66+
[`PreTrainedTokenizerFast`][tokenizers](https://huggingface.co/docs/tokenizers) 라이브러리에 의존합니다. 🤗 tokenizers 라이브러리에서 얻은 토크나이저는
67+
🤗 transformers로 매우 간단하게 가져올 수 있습니다. 어떻게 하는지 알아보려면 [Using tokenizers from 🤗 tokenizers](../fast_tokenizers) 페이지를 참고하세요.
68+
69+
[[autodoc]] PreTrainedTokenizerFast
70+
- __call__
71+
- add_tokens
72+
- add_special_tokens
73+
- apply_chat_template
74+
- batch_decode
75+
- decode
76+
- encode
77+
- push_to_hub
78+
- all
79+
80+
## BatchEncoding[[transformers.BatchEncoding]]
81+
82+
[[autodoc]] BatchEncoding

0 commit comments

Comments
 (0)