| <!--Copyright 2022 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. |
|
|
| --> |
|
|
| # AutoClassλ‘ μ¬μ νμ΅λ μΈμ€ν΄μ€ λ‘λ[[load-pretrained-instances-with-an-autoclass]] |
|
|
| νΈλμ€ν¬λ¨Έ μν€ν
μ²κ° λ§€μ° λ€μνκΈ° λλ¬Έμ 체ν¬ν¬μΈνΈμ λ§λ μν€ν
μ²λ₯Ό μμ±νλ κ²μ΄ μ΄λ €μΈ μ μμ΅λλ€. λΌμ΄λΈλ¬λ¦¬λ₯Ό μ½κ³ κ°λ¨νλ©° μ μ°νκ² μ¬μ©νκΈ° μν Transformer ν΅μ¬ μ² νμ μΌνμΌλ‘, `AutoClass`λ μ£Όμ΄μ§ 체ν¬ν¬μΈνΈμμ μ¬λ°λ₯Έ μν€ν
μ²λ₯Ό μλμΌλ‘ μΆλ‘ νμ¬ λ‘λν©λλ€. `from_pretrained()` λ©μλλ₯Ό μ¬μ©νλ©΄ λͺ¨λ μν€ν
μ²μ λν΄ μ¬μ νμ΅λ λͺ¨λΈμ λΉ λ₯΄κ² λ‘λν μ μμΌλ―λ‘ λͺ¨λΈμ μ²μλΆν° νμ΅νλ λ° μκ°κ³Ό 리μμ€λ₯Ό ν¬μ
ν νμκ° μμ΅λλ€. |
| 체ν¬ν¬μΈνΈμ ꡬμ λ°μ§ μλ μ½λλ₯Ό μμ±νλ€λ κ²μ μ½λκ° ν 체ν¬ν¬μΈνΈμμ μλνλ©΄ μν€ν
μ²κ° λ€λ₯΄λλΌλ λ€λ₯Έ 체ν¬ν¬μΈνΈ(μ μ¬ν μμ
μ λν΄ νμ΅λ κ²½μ°)μμλ μλνλ€λ κ²μ μλ―Έν©λλ€. |
|
|
| <Tip> |
|
|
| μν€ν
μ²λ λͺ¨λΈμ 골격μ μλ―Ένλ©° 체ν¬ν¬μΈνΈλ μ£Όμ΄μ§ μν€ν
μ²μ λν κ°μ€μΉμ
λλ€. μλ₯Ό λ€μ΄, [BERT](https://huggingface.co/google-bert/bert-base-uncased)λ μν€ν
μ²μ΄κ³ , `google-bert/bert-base-uncased`λ 체ν¬ν¬μΈνΈμ
λλ€. λͺ¨λΈμ μν€ν
μ² λλ 체ν¬ν¬μΈνΈλ₯Ό μλ―Έν μ μλ μΌλ°μ μΈ μ©μ΄μ
λλ€. |
|
|
| </Tip> |
|
|
| μ΄ νν 리μΌμμλ λ€μμ νμ΅ν©λλ€: |
|
|
| * μ¬μ νμ΅λ ν ν¬λμ΄μ λ‘λνκΈ°. |
| * μ¬μ νμ΅λ μ΄λ―Έμ§ νλ‘μΈμ λ‘λνκΈ°. |
| * μ¬μ νμ΅λ νΉμ§ μΆμΆκΈ° λ‘λνκΈ°. |
| * μ¬μ νλ ¨λ νλ‘μΈμ λ‘λνκΈ°. |
| * μ¬μ νμ΅λ λͺ¨λΈ λ‘λνκΈ°. |
|
|
| ## AutoTokenizer[[autotokenizer]] |
|
|
| κ±°μ λͺ¨λ NLP μμ
μ ν ν¬λμ΄μ λ‘ μμλ©λλ€. ν ν¬λμ΄μ λ μ¬μ©μμ μ
λ ₯μ λͺ¨λΈμμ μ²λ¦¬ν μ μλ νμμΌλ‘ λ³νν©λλ€. |
| [`AutoTokenizer.from_pretrained`]λ‘ ν ν¬λμ΄μ λ₯Ό λ‘λν©λλ€: |
|
|
| ```py |
| >>> from transformers import AutoTokenizer |
| |
| >>> tokenizer = AutoTokenizer.from_pretrained("google-bert/bert-base-uncased") |
| ``` |
|
|
| κ·Έλ¦¬κ³ μλμ κ°μ΄ μ
λ ₯μ ν ν°νν©λλ€: |
|
|
| ```py |
| >>> sequence = "In a hole in the ground there lived a hobbit." |
| >>> print(tokenizer(sequence)) |
| {'input_ids': [101, 1999, 1037, 4920, 1999, 1996, 2598, 2045, 2973, 1037, 7570, 10322, 4183, 1012, 102], |
| 'token_type_ids': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], |
| 'attention_mask': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} |
| ``` |
|
|
| ## AutoImageProcessor[[autoimageprocessor]] |
|
|
| λΉμ μμ
μ κ²½μ° μ΄λ―Έμ§ νλ‘μΈμκ° μ΄λ―Έμ§λ₯Ό μ¬λ°λ₯Έ μ
λ ₯ νμμΌλ‘ μ²λ¦¬ν©λλ€. |
|
|
| ```py |
| >>> from transformers import AutoImageProcessor |
| |
| >>> image_processor = AutoImageProcessor.from_pretrained("google/vit-base-patch16-224") |
| ``` |
|
|
|
|
| ## AutoFeatureExtractor[[autofeatureextractor]] |
|
|
| μ€λμ€ μμ
μ κ²½μ° νΉμ§ μΆμΆκΈ°κ° μ€λμ€ μ νΈλ₯Ό μ¬λ°λ₯Έ μ
λ ₯ νμμΌλ‘ μ²λ¦¬ν©λλ€. |
|
|
| [`AutoFeatureExtractor.from_pretrained`]λ‘ νΉμ§ μΆμΆκΈ°λ₯Ό λ‘λν©λλ€: |
|
|
| ```py |
| >>> from transformers import AutoFeatureExtractor |
| |
| >>> feature_extractor = AutoFeatureExtractor.from_pretrained( |
| ... "ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition" |
| ... ) |
| ``` |
|
|
| ## AutoProcessor[[autoprocessor]] |
|
|
| λ©ν°λͺ¨λ¬ μμ
μλ λ κ°μ§ μ νμ μ μ²λ¦¬ λꡬλ₯Ό κ²°ν©ν νλ‘μΈμκ° νμν©λλ€. μλ₯Ό λ€μ΄ LayoutLMV2 λͺ¨λΈμλ μ΄λ―Έμ§λ₯Ό μ²λ¦¬νλ μ΄λ―Έμ§ νλ‘μΈμμ ν
μ€νΈλ₯Ό μ²λ¦¬νλ ν ν¬λμ΄μ κ° νμνλ©°, νλ‘μΈμλ μ΄ λ κ°μ§λ₯Ό κ²°ν©ν©λλ€. |
|
|
| [`AutoProcessor.from_pretrained()`]λ‘ νλ‘μΈμλ₯Ό λ‘λν©λλ€: |
|
|
| ```py |
| >>> from transformers import AutoProcessor |
| |
| >>> processor = AutoProcessor.from_pretrained("microsoft/layoutlmv2-base-uncased") |
| ``` |
|
|
| ## AutoModel[[automodel]] |
|
|
| <frameworkcontent> |
| <pt> |
| λ§μ§λ§μΌλ‘ AutoModelForν΄λμ€λ₯Ό μ¬μ©νλ©΄ μ£Όμ΄μ§ μμ
μ λν΄ λ―Έλ¦¬ νμ΅λ λͺ¨λΈμ λ‘λν μ μμ΅λλ€ (μ¬μ© κ°λ₯ν μμ
μ μ 체 λͺ©λ‘μ [μ¬κΈ°](model_doc/auto)λ₯Ό μ°Έμ‘°νμΈμ). μλ₯Ό λ€μ΄, [`AutoModelForSequenceClassification.from_pretrained`]λ₯Ό μ¬μ©νμ¬ μνμ€ λΆλ₯μ© λͺ¨λΈμ λ‘λν μ μμ΅λλ€: |
|
|
| ```py |
| >>> from transformers import AutoModelForSequenceClassification |
| |
| >>> model = AutoModelForSequenceClassification.from_pretrained("distilbert/distilbert-base-uncased") |
| ``` |
|
|
| λμΌν 체ν¬ν¬μΈνΈλ₯Ό μ½κ² μ¬μ¬μ©νμ¬ λ€λ₯Έ μμ
μ μν€ν
μ²λ₯Ό λ‘λν μ μμ΅λλ€: |
|
|
| ```py |
| >>> from transformers import AutoModelForTokenClassification |
| |
| >>> model = AutoModelForTokenClassification.from_pretrained("distilbert/distilbert-base-uncased") |
| ``` |
|
|
| <Tip warning={true}> |
|
|
| PyTorchλͺ¨λΈμ κ²½μ° `from_pretrained()` λ©μλλ λ΄λΆμ μΌλ‘ νΌν΄μ μ¬μ©νμ¬ μμ νμ§ μμ κ²μΌλ‘ μλ €μ§ `torch.load()`λ₯Ό μ¬μ©ν©λλ€. |
| μΌλ°μ μΌλ‘ μ λ’°ν μ μλ μμ€μμ κ°μ Έμκ±°λ λ³μ‘°λμμ μ μλ λͺ¨λΈμ λ‘λνμ§ λ§μΈμ. νκΉ
νμ΄μ€ νλΈμμ νΈμ€ν
λλ κ³΅κ° λͺ¨λΈμ κ²½μ° μ΄λ¬ν 보μ μνμ΄ λΆλΆμ μΌλ‘ μνλλ©°, κ° μ»€λ° μ λ©μ¨μ΄λ₯Ό [κ²μ¬ν©λλ€](https://huggingface.co/docs/hub/security-malware). GPGλ₯Ό μ¬μ©ν΄ μλͺ
λ [μ»€λ° κ²μ¦](https://huggingface.co/docs/hub/security-gpg#signing-commits-with-gpg)κ³Ό κ°μ λͺ¨λ²μ¬λ‘λ [λ¬Έμ](https://huggingface.co/docs/hub/security)λ₯Ό μ°Έμ‘°νμΈμ. |
|
|
| ν
μνλ‘μ°μ Flax 체ν¬ν¬μΈνΈλ μν₯μ λ°μ§ μμΌλ©°, `from_pretrained`λ©μλμ `from_tf` μ `from_flax` ν€μλ κ°λ³ μΈμλ₯Ό μ¬μ©νμ¬ μ΄ λ¬Έμ λ₯Ό μ°νν μ μμ΅λλ€. |
|
|
| </Tip> |
|
|
| μΌλ°μ μΌλ‘ AutoTokenizer ν΄λμ€μ AutoModelFor ν΄λμ€λ₯Ό μ¬μ©νμ¬ λ―Έλ¦¬ νμ΅λ λͺ¨λΈ μΈμ€ν΄μ€λ₯Ό λ‘λνλ κ²μ΄ μ’μ΅λλ€. μ΄λ κ² νλ©΄ λ§€λ² μ¬λ°λ₯Έ μν€ν
μ²λ₯Ό λ‘λν μ μμ΅λλ€. λ€μ [νν 리μΌ](preprocessing)μμλ μλ‘κ² λ‘λν ν ν¬λμ΄μ , μ΄λ―Έμ§ νλ‘μΈμ, νΉμ§ μΆμΆκΈ°λ₯Ό μ¬μ©νμ¬ λ―ΈμΈ νλμ© λ°μ΄ν° μΈνΈλ₯Ό μ μ²λ¦¬νλ λ°©λ²μ λν΄ μμλ΄
λλ€. |
| </pt> |
| <tf> |
| λ§μ§λ§μΌλ‘ `TFAutoModelFor` ν΄λμ€λ₯Ό μ¬μ©νλ©΄ μ£Όμ΄μ§ μμ
μ λν΄ μ¬μ νλ ¨λ λͺ¨λΈμ λ‘λν μ μμ΅λλ€. (μ¬μ© κ°λ₯ν μμ
μ μ 체 λͺ©λ‘μ [μ¬κΈ°](model_doc/auto)λ₯Ό μ°Έμ‘°νμΈμ. μλ₯Ό λ€μ΄, [`TFAutoModelForSequenceClassification.from_pretrained`]λ‘ μνμ€ λΆλ₯λ₯Ό μν λͺ¨λΈμ λ‘λν©λλ€: |
|
|
| ```py |
| >>> from transformers import TFAutoModelForSequenceClassification |
| |
| >>> model = TFAutoModelForSequenceClassification.from_pretrained("distilbert/distilbert-base-uncased") |
| ``` |
|
|
| μ½κ² λμΌν 체ν¬ν¬μΈνΈλ₯Ό μ¬μ¬μ©νμ¬ λ€λ₯Έ μμ
μ μν€ν
μ²λ₯Ό λ‘λν μ μμ΅λλ€: |
|
|
| ```py |
| >>> from transformers import TFAutoModelForTokenClassification |
| |
| >>> model = TFAutoModelForTokenClassification.from_pretrained("distilbert/distilbert-base-uncased") |
| ``` |
|
|
| μΌλ°μ μΌλ‘, `AutoTokenizer`ν΄λμ€μ `TFAutoModelFor` ν΄λμ€λ₯Ό μ¬μ©νμ¬ λ―Έλ¦¬ νμ΅λ λͺ¨λΈ μΈμ€ν΄μ€λ₯Ό λ‘λνλ κ²μ΄ μ’μ΅λλ€. μ΄λ κ² νλ©΄ λ§€λ² μ¬λ°λ₯Έ μν€ν
μ²λ₯Ό λ‘λν μ μμ΅λλ€. λ€μ [νν 리μΌ](preprocessing)μμλ μλ‘κ² λ‘λν ν ν¬λμ΄μ , μ΄λ―Έμ§ νλ‘μΈμ, νΉμ§ μΆμΆκΈ°λ₯Ό μ¬μ©νμ¬ λ―ΈμΈ νλμ© λ°μ΄ν° μΈνΈλ₯Ό μ μ²λ¦¬νλ λ°©λ²μ λν΄ μμλ΄
λλ€. |
| </tf> |
| </frameworkcontent> |
|
|