huggingface--transformers
e06fe8e8c6
Secret Leaks / trufflehog (push) Failing after 1s
Build documentation / build (push) Failing after 1s
Build documentation / build_other_lang (push) Failing after 0s
CodeQL Security Analysis / CodeQL Analysis (push) Failing after 0s
PR CI / pr-ci (push) Failing after 1s
Slow tests on important models (on Push - A10) / Get all modified files (push) Failing after 1s
Slow tests on important models (on Push - A10) / Model CI (push) Has been skipped
Self-hosted runner (benchmark) / Benchmark (aws-g5-4xlarge-cache) (push) Has been cancelled
New model PR merged notification / Notify new model (push) Has been cancelled
Update Transformers metadata / build_and_package (push) Has been cancelled
67 ่ก
7.0 KiB
Markdown
67 ่ก
7.0 KiB
Markdown
<!--Copyright 2020 The HuggingFace Team. All rights reserved.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
|
the License. You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
|
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
specific language governing permissions and limitations under the License.
|
|
|
|
โ ๏ธ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
|
rendered properly in your Markdown viewer.
|
|
|
|
-->
|
|
|
|
# ์ด๋
๊ณผ ๋ชฉํ [[philosophy]]
|
|
|
|
๐ค Transformers๋ ๋ค์๊ณผ ๊ฐ์ ๋ชฉ์ ์ผ๋ก ๋ง๋ค์ด์ง ๋
์์ ์ธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์
๋๋ค:
|
|
|
|
- ๋๊ท๋ชจ Transformers ๋ชจ๋ธ์ ์ฌ์ฉํ๊ฑฐ๋ ์ฐ๊ตฌํ๊ฑฐ๋ ํ์ฅํ๋ ค๋ ๊ธฐ๊ณ ํ์ต ์ฐ๊ตฌ์ ๋ฐ ๊ต์ก์๋ฅผ ์ํ ๊ฒ์
๋๋ค.
|
|
- ๋ชจ๋ธ์ ๋ฏธ์ธ ์กฐ์ ํ๊ฑฐ๋ ์ ์์ฉ์ผ๋ก ์ฌ์ฉํ๊ณ ์ ํ๋ ์ค์ ๊ฐ๋ฐ์๋ฅผ ์ํ ๊ฒ์
๋๋ค.
|
|
- ํน์ ๊ธฐ๊ณ ํ์ต ์์
์ ํด๊ฒฐํ๊ธฐ ์ํด ์ฌ์ ํ๋ จ๋ ๋ชจ๋ธ์ ๋ค์ด๋ก๋ํ๊ณ ์ฌ์ฉํ๊ธฐ๋ง ํ๋ ค๋ ์์ง๋์ด๋ฅผ ์ํ ๊ฒ์
๋๋ค.
|
|
|
|
์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ๋ ๊ฐ์ง ์ฃผ์ ๋ชฉํ๋ฅผ ๊ฐ์ง๊ณ ์ค๊ณ๋์์ต๋๋ค:
|
|
|
|
1. ์ฌ์ฉํ๊ธฐ ์ฝ๊ณ ๋น ๋ฅด๊ฒ ๋ง๋๋ ๊ฒ:
|
|
|
|
- ํ์ตํด์ผ ํ ์ฌ์ฉ์ ๋์ ์ถ์ํ์ ์๋ฅผ ์ ํํ์ต๋๋ค. ์ค์ ๋ก ๊ฑฐ์ ์ถ์ํ๊ฐ ์์ผ๋ฉฐ, ๊ฐ ๋ชจ๋ธ์ ์ฌ์ฉํ๊ธฐ ์ํด ํ์ํ ์ธ ๊ฐ์ง ํ์ค ํด๋์ค์ธ [configuration](main_classes/configuration), [models](main_classes/model) ๋ฐ ์ ์ฒ๋ฆฌ ํด๋์ค์ธ ([tokenizer](main_classes/tokenizer)๋ NLP์ฉ, [image processor](main_classes/image_processor)๋ ๋น์ ์ฉ, [feature extractor](main_classes/feature_extractor)๋ ์ค๋์ค์ฉ, [processor](main_classes/processors)๋ ๋ฉํฐ๋ชจ๋ฌ ์
๋ ฅ์ฉ)๋ง ์ฌ์ฉํฉ๋๋ค.
|
|
- ์ด๋ฌํ ํด๋์ค๋ ๊ณตํต์ ์ธ `from_pretrained()` ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ ๋ฏธ๋ฆฌ ํ๋ จ๋ ์ธ์คํด์ค์์ ๊ฐ๋จํ๊ณ ํต์ผ๋ ๋ฐฉ์์ผ๋ก ์ด๊ธฐํํ ์ ์์ต๋๋ค. ์ด ๋ฉ์๋๋ ๋ฏธ๋ฆฌ ํ๋ จ๋ ์ฒดํฌํฌ์ธํธ์์ ๊ด๋ จ ํด๋์ค ์ธ์คํด์ค์ ๊ด๋ จ ๋ฐ์ดํฐ(๊ตฌ์ฑ์ ํ์ดํผํ๋ผ๋ฏธํฐ, ํ ํฌ๋์ด์ ์ ์ดํ, ๋ชจ๋ธ์ ๊ฐ์ค์น)๋ฅผ (ํ์ํ ๊ฒฝ์ฐ) ๋ค์ด๋ก๋ํ๊ณ ์บ์ํ๋ฉฐ ๊ฐ์ ธ์ต๋๋ค. ์ฒดํฌํฌ์ธํธ๋ [Hugging Face Hub](https://huggingface.co/models)์์ ์ ๊ณต๋๊ฑฐ๋ ์ฌ์ฉ์ ์์ฒด์ ์ ์ฅ๋ ์ฒดํฌํฌ์ธํธ์์ ์ ๊ณต๋ฉ๋๋ค.
|
|
- ์ด ์ธ ๊ฐ์ง ๊ธฐ๋ณธ ํด๋์ค ์์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ [`pipeline`] API๋ฅผ ์ ๊ณตํ์ฌ ์ฃผ์ด์ง ์์
์ ๋ํด ๋ชจ๋ธ์ ๋น ๋ฅด๊ฒ ์ถ๋ก ํ๋ ๋ฐ ์ฌ์ฉํ๊ณ , [`Trainer`]๋ฅผ ์ ๊ณตํ์ฌ PyTorch ๋ชจ๋ธ์ ๋น ๋ฅด๊ฒ ํ๋ จํ๊ฑฐ๋ ๋ฏธ์ธ ์กฐ์ ํ ์ ์๋๋ก ํฉ๋๋ค(๋ชจ๋ TensorFlow ๋ชจ๋ธ์ `Keras.fit`๊ณผ ํธํ๋ฉ๋๋ค).
|
|
- ๊ฒฐ๊ณผ์ ์ผ๋ก, ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ์ ๊ฒฝ๋ง์ ๊ตฌ์ถํ๊ธฐ ์ํ ๋ชจ๋์ ๋๊ตฌ ์์๊ฐ ์๋๋๋ค. ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ํ์ฅํ๊ฑฐ๋ ๊ตฌ์ถํ๋ ค๋ฉด ์ผ๋ฐ์ ์ธ Python, PyTorch, TensorFlow, Keras ๋ชจ๋์ ์ฌ์ฉํ๊ณ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๊ธฐ๋ณธ ํด๋์ค๋ฅผ ์์ํ์ฌ ๋ชจ๋ธ ๋ก๋ฉ ๋ฐ ์ ์ฅ๊ณผ ๊ฐ์ ๊ธฐ๋ฅ์ ์ฌ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค. ๋ชจ๋ธ์ ๋ํ ์ฝ๋ฉ ์ฒ ํ์ ๋ํด ๋ ์์ธํ ์๊ณ ์ถ๋ค๋ฉด [Repeat Yourself](https://huggingface.co/blog/transformers-design-philosophy) ๋ธ๋ก๊ทธ ๊ธ์ ํ์ธํด๋ณด์ธ์.
|
|
|
|
2. ์๋ ๋ชจ๋ธ๊ณผ ๊ฐ๋ฅํ ํ ๊ทผ์ ํ ์ฑ๋ฅ์ ์ ๊ณตํ๋ ์ต์ ๋ชจ๋ธ์ ์ ๊ณตํ๋ ๊ฒ:
|
|
|
|
- ๊ฐ ์ํคํ
์ฒ์ ๋ํด ๊ณต์ ์ ์๊ฐ ์ ๊ณตํ ๊ฒฐ๊ณผ๋ฅผ ์ฌํํ๋ ์ ์ด๋ ํ ๊ฐ์ง ์์ ๋ฅผ ์ ๊ณตํฉ๋๋ค.
|
|
- ์ฝ๋๋ ์๋ ์ฝ๋์ ๊ฐ๋ฅํ ํ ์ ์ฌํ๊ฒ ์ ์ง๋๋ฏ๋ก PyTorch ์ฝ๋๋ TensorFlow ์ฝ๋๋ก ๋ณํ๋์ด *pytorchic*ํ์ง ์์ ์ ์๊ณ , ๊ทธ ๋ฐ๋์ ๊ฒฝ์ฐ๋ ๋ง์ฐฌ๊ฐ์ง์
๋๋ค.
|
|
|
|
๊ธฐํ ๋ชฉํ ๋ช ๊ฐ์ง:
|
|
|
|
- ๋ชจ๋ธ์ ๋ด๋ถ๋ฅผ ๊ฐ๋ฅํ ์ผ๊ด๋๊ฒ ๋
ธ์ถ์ํค๊ธฐ:
|
|
|
|
- ์ ์ฒด ์๋ ์ํ์ ์ดํ
์
๊ฐ์ค์น์ ๋ํ ์ก์ธ์ค๋ฅผ ๋จ์ผ API๋ฅผ ์ฌ์ฉํ์ฌ ์ ๊ณตํฉ๋๋ค.
|
|
- ์ ์ฒ๋ฆฌ ํด๋์ค ๋ฐ ๊ธฐ๋ณธ ๋ชจ๋ธ API๋ ๋ชจ๋ธ ๊ฐ์ ์ฝ๊ฒ ์ ํํ ์ ์๋๋ก ํ์คํ๋์ด ์์ต๋๋ค.
|
|
|
|
- ๋ฏธ์ธ ์กฐ์ ๋ฐ ๋ชจ๋ธ ํ์์ ์ํ ์ ๋งํ ๋๊ตฌ๋ค์ ์ฃผ๊ด์ ์ผ๋ก ์ ํํ๊ธฐ:
|
|
|
|
- ๋ฏธ์ธ ์กฐ์ ์ ์ํด ์ดํ ๋ฐ ์๋ฒ ๋ฉ์ ์๋ก์ด ํ ํฐ์ ๊ฐ๋จํ๊ณ ์ผ๊ด๋ ๋ฐฉ์์ผ๋ก ์ถ๊ฐํ๋ ๋ฐฉ๋ฒ์ ์ ๊ณตํฉ๋๋ค.
|
|
- Transformer ํค๋๋ฅผ ๋ง์คํนํ๊ณ ๊ฐ์ง์น๊ธฐํ๋ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ ์ ๊ณตํฉ๋๋ค.
|
|
|
|
- PyTorch, TensorFlow 2.0 ๋ฐ Flax ๊ฐ์ ์ฝ๊ฒ ์ ํํ ์ ์๋๋ก ํ์ฌ ํ๋์ ํ๋ ์์ํฌ๋ก ํ๋ จํ๊ณ ๋ค๋ฅธ ํ๋ ์์ํฌ๋ก ์ถ๋ก ํ ์ ์๊ฒ ํฉ๋๋ค.
|
|
|
|
## ์ฃผ์ ๊ฐ๋
[[main-concepts]]
|
|
|
|
์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ๊ฐ ๋ชจ๋ธ์ ๋ํด ์ธ ๊ฐ์ง ์ ํ์ ํด๋์ค๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๊ตฌ์ถ๋์์ต๋๋ค:
|
|
|
|
- **๋ชจ๋ธ ํด๋์ค**๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์ ์ ๊ณตํ๋ ์ฌ์ ํ๋ จ๋ ๊ฐ์ค์น์ ํจ๊ป ์๋ํ๋ PyTorch ๋ชจ๋ธ([torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module)), Keras ๋ชจ๋ธ([tf.keras.Model](https://www.tensorflow.org/api_docs/python/tf/keras/Model)), JAX/Flax ๋ชจ๋ธ([flax.linen.Module](https://flax.readthedocs.io/en/latest/api_reference/flax.linen/module.html))์ผ ์ ์์ต๋๋ค.
|
|
- **๊ตฌ์ฑ ํด๋์ค**๋ ๋ชจ๋ธ์ ๊ตฌ์ถํ๋ ๋ฐ ํ์ํ ํ์ดํผํ๋ผ๋ฏธํฐ(์: ๋ ์ด์ด ์ ๋ฐ ์๋ ํฌ๊ธฐ)๋ฅผ ์ ์ฅํฉ๋๋ค. ๊ตฌ์ฑ ํด๋์ค๋ฅผ ์ง์ ์ธ์คํด์คํํ ํ์๋ ์์ต๋๋ค. ํนํ, ์์ ์์ด ๊ณ ์ฌ์ ํ์ต๋ ๋ชจ๋ธ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ๋ชจ๋ธ์ ์์ฑํ๋ฉด ๋ชจ๋ธ์ ์ผ๋ถ์ธ ๊ตฌ์ฑ์ ์๋์ผ๋ก ์ธ์คํด์คํ๋ฉ๋๋ค.
|
|
- **์ ์ฒ๋ฆฌ ํด๋์ค**๋ ์์ ๋ฐ์ดํฐ๋ฅผ ๋ชจ๋ธ์ด ์์ฉํ๋ ํ์์ผ๋ก ๋ณํํฉ๋๋ค. [Tokenizer](main_classes/tokenizer)๋ ๊ฐ ๋ชจ๋ธ์ ์ดํ๋ฅผ ์ ์ฅํ๊ณ , ๋ฌธ์์ด์ ํ ํฐ ์๋ฒ ๋ฉ ์ธ๋ฑ์ค ๋ฆฌ์คํธ๋ก ์ธ์ฝ๋ฉํ๊ณ ๋์ฝ๋ฉํ๊ธฐ ์ํ ๋ฉ์๋๋ฅผ ์ ๊ณตํฉ๋๋ค. [Image processors](main_classes/image_processor)๋ ๋น์ ์
๋ ฅ์ ์ ์ฒ๋ฆฌํ๊ณ , [feature extractors](main_classes/feature_extractor)๋ ์ค๋์ค ์
๋ ฅ์ ์ ์ฒ๋ฆฌํ๋ฉฐ, [processor](main_classes/processors)๋ ๋ฉํฐ๋ชจ๋ฌ ์
๋ ฅ์ ์ฒ๋ฆฌํฉ๋๋ค.
|
|
|
|
๋ชจ๋ ์ด๋ฌํ ํด๋์ค๋ ์ฌ์ ํ๋ จ๋ ์ธ์คํด์ค์์ ์ธ์คํด์คํํ๊ณ ๋ก์ปฌ๋ก ์ ์ฅํ๋ฉฐ, ์ธ ๊ฐ์ง ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ Hub์์ ๊ณต์ ํ ์ ์์ต๋๋ค:
|
|
|
|
- `from_pretrained()` ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ฉด ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์์ฒด์์ ์ ๊ณตํ๋ ์ฌ์ ํ๋ จ๋ ๋ฒ์ (์ง์๋๋ ๋ชจ๋ธ์ [Model Hub](https://huggingface.co/models)์์ ์ฐพ์ ์ ์์)์ด๋ ์ฌ์ฉ์๊ฐ ๋ก์ปฌ๋ก ์ ์ฅํ ๊ฒฝ์ฐ(๋๋ ์๋ฒ์ ์ ์ฅํ ๊ฒฝ์ฐ)์ ๋ชจ๋ธ, ๊ตฌ์ฑ ๋ฐ ์ ์ฒ๋ฆฌ ํด๋์ค๋ฅผ ์ธ์คํด์คํํ ์ ์์ต๋๋ค.
|
|
- `save_pretrained()` ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ฉด ๋ชจ๋ธ, ๊ตฌ์ฑ ๋ฐ ์ ์ฒ๋ฆฌ ํด๋์ค๋ฅผ ๋ก์ปฌ๋ก ์ ์ฅํ์ฌ `from_pretrained()`๋ฅผ ์ฌ์ฉํ์ฌ ๋ค์ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค.
|
|
- `push_to_hub()` ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ฉด ๋ชจ๋ธ, ๊ตฌ์ฑ ๋ฐ ์ ์ฒ๋ฆฌ ํด๋์ค๋ฅผ Hub์ ๊ณต์ ํ์ฌ ๋ชจ๋์๊ฒ ์ฝ๊ฒ ์ ๊ทผํ ์ ์์ต๋๋ค.
|
|
|