Spaces:
Paused
Paused
File size: 7,208 Bytes
ee6e328 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
<!--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.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μ 곡μ νμ¬ λͺ¨λμκ² μ½κ² μ κ·Όν μ μμ΅λλ€.
|