File size: 25,372 Bytes
0e9a03e |
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
<!---
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.
-->
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://huggingface.co/datasets/huggingface/documentation-images/raw/main/transformers-logo-dark.svg">
<source media="(prefers-color-scheme: light)" srcset="https://huggingface.co/datasets/huggingface/documentation-images/raw/main/transformers-logo-light.svg">
<img alt="Hugging Face Transformers Library" src="https://huggingface.co/datasets/huggingface/documentation-images/raw/main/transformers-logo-light.svg" width="352" height="59" style="max-width: 100%;">
</picture>
<br/>
<br/>
</p>
<p align="center">
<a href="https://circleci.com/gh/huggingface/transformers"><img alt="Build" src="https://img.shields.io/circleci/build/github/huggingface/transformers/main"></a>
<a href="https://github.com/huggingface/transformers/blob/main/LICENSE"><img alt="GitHub" src="https://img.shields.io/github/license/huggingface/transformers.svg?color=blue"></a>
<a href="https://huggingface.co/docs/transformers/index"><img alt="Documentation" src="https://img.shields.io/website/http/huggingface.co/docs/transformers/index.svg?down_color=red&down_message=offline&up_message=online"></a>
<a href="https://github.com/huggingface/transformers/releases"><img alt="GitHub release" src="https://img.shields.io/github/release/huggingface/transformers.svg"></a>
<a href="https://github.com/huggingface/transformers/blob/main/CODE_OF_CONDUCT.md"><img alt="Contributor Covenant" src="https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg"></a>
<a href="https://zenodo.org/badge/latestdoi/155220641"><img src="https://zenodo.org/badge/155220641.svg" alt="DOI"></a>
</p>
<h4 align="center">
<p>
<a href="https://github.com/huggingface/transformers/">English</a> |
<a href="https://github.com/huggingface/transformers/blob/main/i18n/README_zh-hans.md">็ฎไฝไธญๆ</a> |
<a href="https://github.com/huggingface/transformers/blob/main/i18n/README_zh-hant.md">็น้ซไธญๆ</a> |
<b>ํ๊ตญ์ด</b> |
<a href="https://github.com/huggingface/transformers/blob/main/i18n/README_es.md">Espaรฑol</a> |
<a href="https://github.com/huggingface/transformers/blob/main/i18n/README_ja.md">ๆฅๆฌ่ช</a> |
<a href="https://github.com/huggingface/transformers/blob/main/i18n/README_hd.md">เคนเคฟเคจเฅเคฆเฅ</a> |
<a href="https://github.com/huggingface/transformers/blob/main/i18n/README_ru.md">ะ ัััะบะธะน</a> |
<a href="https://github.com/huggingface/transformers/blob/main/i18n/README_pt-br.md">ะ ortuguรชs</a> |
<a href="https://github.com/huggingface/transformers/blob/main/i18n/README_te.md">เฐคเฑเฐฒเฑเฐเฑ</a> |
<a href="https://github.com/huggingface/transformers/blob/main/i18n/README_fr.md">Franรงais</a> |
<a href="https://github.com/huggingface/transformers/blob/main/i18n/README_de.md">Deutsch</a> |
<a href="https://github.com/huggingface/transformers/blob/main/i18n/README_vi.md">Tiแบฟng Viแปt</a> |
<a href="https://github.com/huggingface/transformers/blob/main/i18n/README_ar.md">ุงูุนุฑุจูุฉ</a> |
<a href="https://github.com/huggingface/transformers/blob/main/i18n/README_ur.md">ุงุฑุฏู</a> |
</p>
</h4>
<h3 align="center">
<p> Jax, Pytorch, TensorFlow๋ฅผ ์ํ ์ต์ฒจ๋จ ๋จธ์ ๋ฌ๋</p>
</h3>
<h3 align="center">
<a href="https://hf.co/course"><img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/course_banner.png"></a>
</h3>
๐ค Transformers๋ ํ
์คํธ, ๋น์ , ์ค๋์ค์ ๊ฐ์ ๋ค์ํ ๋ถ์ผ์์ ์ฌ๋ฌ ๊ณผ์ ๋ฅผ ์ํํ๋ ์์ฒ ๊ฐ์ ์ฌ์ ํ์ต๋ ๋ชจ๋ธ์ ์ ๊ณตํฉ๋๋ค.
์ ๊ณต๋๋ ๋ชจ๋ธ์ ํตํด ๋ค์ ๊ณผ์ ๋ฅผ ์ํํ ์ ์์ต๋๋ค.
- ๐ ํ
์คํธ: 100๊ฐ ์ด์์ ์ธ์ด๋ค๋ก, ํ
์คํธ ๋ถ๋ฅ, ์ ๋ณด ์ถ์ถ, ์ง๋ฌธ ๋ต๋ณ, ์์ฝ, ๋ฒ์ญ ๋ฐ ๋ฌธ์ฅ ์์ฑ
- ๐ผ๏ธ ์ด๋ฏธ์ง: ์ด๋ฏธ์ง ๋ถ๋ฅ(Image Classification), ๊ฐ์ฒด ํ์ง(Object Detection) ๋ฐ ๋ถํ (Segmentation)
- ๐ฃ๏ธ ์ค๋์ค: ์์ฑ ์ธ์(Speech Recognition) ๋ฐ ์ค๋์ค ๋ถ๋ฅ(Audio Classification)
Transformer์ ๋ชจ๋ธ์ ํ๋ฅผ ํตํ ์ง์์๋ต(Table QA), ๊ดํ ๋ฌธ์ ์ธ์(Optical Character Recognition), ์ค์บ ํ ๋ฌธ์์์ ์ ๋ณด ์ถ์ถ, ๋น๋์ค ๋ถ๋ฅ ๋ฐ ์๊ฐ์ ์ง์์๋ต๊ณผ ๊ฐ์ **์ฌ๋ฌ ๋ถ์ผ๊ฐ ๊ฒฐํฉ๋** ๊ณผ์ ๋ํ ์ํํ ์ ์์ต๋๋ค.
๐ค Transformers๋ ์ด๋ฌํ ์ฌ์ ํ์ต ๋ชจ๋ธ์ ๋น ๋ฅด๊ฒ ๋ค์ด๋ก๋ํด ํน์ ํ
์คํธ์ ์ฌ์ฉํ๊ณ , ์ํ๋ ๋ฐ์ดํฐ๋ก fine-tuningํด ์ปค๋ฎค๋ํฐ๋ ์ฐ๋ฆฌ์ [๋ชจ๋ธ ํ๋ธ](https://huggingface.co/models)์ ๊ณต์ ํ ์ ์๋๋ก API๋ฅผ ์ ๊ณตํฉ๋๋ค. ๋ํ, ๋ชจ๋ธ ๊ตฌ์กฐ๋ฅผ ์ ์ํ๋ ๊ฐ ํ์ด์ฌ ๋ชจ๋์ ์์ ํ ๋
๋ฆฝ์ ์ด์ฌ์ ์ฐ๊ตฌ ์คํ์ ์ํด ์์ฝ๊ฒ ์์ ํ ์ ์์ต๋๋ค.
๐ค Transformers๋ ๊ฐ์ฅ ์ ๋ช
ํ 3๊ฐ์ ๋ฅ๋ฌ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ง์ํฉ๋๋ค. ์ด๋ค์ ์๋ก ์๋ฒฝํ ์ฐ๋๋ฉ๋๋ค โ [Jax](https://jax.readthedocs.io/en/latest/), [PyTorch](https://pytorch.org/), [TensorFlow](https://www.tensorflow.org/). ๊ฐ๋จํ๊ฒ ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค ํ๋๋ก ๋ชจ๋ธ์ ํ์ตํ๊ณ , ๋ ๋ค๋ฅธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก ์ถ๋ก ์ ์ํด ๋ชจ๋ธ์ ๋ถ๋ฌ์ฌ ์ ์์ต๋๋ค.
## ์จ๋ผ์ธ ๋ฐ๋ชจ
๋๋ถ๋ถ์ ๋ชจ๋ธ์ [๋ชจ๋ธ ํ๋ธ](https://huggingface.co/models) ํ์ด์ง์์ ๋ฐ๋ก ํ
์คํธํด ๋ณผ ์ ์์ต๋๋ค. ๊ณต๊ฐ ๋ฐ ๋น๊ณต๊ฐ ๋ชจ๋ธ์ ์ํ [๋น๊ณต๊ฐ ๋ชจ๋ธ ํธ์คํ
, ๋ฒ์ ๊ด๋ฆฌ, ์ถ๋ก API](https://huggingface.co/pricing)๋ ์ ๊ณตํฉ๋๋ค.
์๋ ๋ช ๊ฐ์ง ์์๊ฐ ์์ต๋๋ค:
์์ฐ์ด ์ฒ๋ฆฌ:
- [BERT๋ก ๋ง์คํน๋ ๋จ์ด ์์ฑํ๊ธฐ](https://huggingface.co/google-bert/bert-base-uncased?text=Paris+is+the+%5BMASK%5D+of+France)
- [Electra๋ฅผ ์ด์ฉํ ๊ฐ์ฒด๋ช
์ธ์](https://huggingface.co/dbmdz/electra-large-discriminator-finetuned-conll03-english?text=My+name+is+Sarah+and+I+live+in+London+city)
- [GPT-2๋ก ํ
์คํธ ์์ฑํ๊ธฐ](https://huggingface.co/openai-community/gpt2?text=A+long+time+ago%2C+)
- [RoBERTa๋ก ์์ฐ์ด ์ถ๋ก ํ๊ธฐ](https://huggingface.co/FacebookAI/roberta-large-mnli?text=The+dog+was+lost.+Nobody+lost+any+animal)
- [BART๋ฅผ ์ด์ฉํ ์์ฝ](https://huggingface.co/facebook/bart-large-cnn?text=The+tower+is+324+metres+%281%2C063+ft%29+tall%2C+about+the+same+height+as+an+81-storey+building%2C+and+the+tallest+structure+in+Paris.+Its+base+is+square%2C+measuring+125+metres+%28410+ft%29+on+each+side.+During+its+construction%2C+the+Eiffel+Tower+surpassed+the+Washington+Monument+to+become+the+tallest+man-made+structure+in+the+world%2C+a+title+it+held+for+41+years+until+the+Chrysler+Building+in+New+York+City+was+finished+in+1930.+It+was+the+first+structure+to+reach+a+height+of+300+metres.+Due+to+the+addition+of+a+broadcasting+aerial+at+the+top+of+the+tower+in+1957%2C+it+is+now+taller+than+the+Chrysler+Building+by+5.2+metres+%2817+ft%29.+Excluding+transmitters%2C+the+Eiffel+Tower+is+the+second+tallest+free-standing+structure+in+France+after+the+Millau+Viaduct)
- [DistilBERT๋ฅผ ์ด์ฉํ ์ง๋ฌธ ๋ต๋ณ](https://huggingface.co/distilbert/distilbert-base-uncased-distilled-squad?text=Which+name+is+also+used+to+describe+the+Amazon+rainforest+in+English%3F&context=The+Amazon+rainforest+%28Portuguese%3A+Floresta+Amaz%C3%B4nica+or+Amaz%C3%B4nia%3B+Spanish%3A+Selva+Amaz%C3%B3nica%2C+Amazon%C3%ADa+or+usually+Amazonia%3B+French%3A+For%C3%AAt+amazonienne%3B+Dutch%3A+Amazoneregenwoud%29%2C+also+known+in+English+as+Amazonia+or+the+Amazon+Jungle%2C+is+a+moist+broadleaf+forest+that+covers+most+of+the+Amazon+basin+of+South+America.+This+basin+encompasses+7%2C000%2C000+square+kilometres+%282%2C700%2C000+sq+mi%29%2C+of+which+5%2C500%2C000+square+kilometres+%282%2C100%2C000+sq+mi%29+are+covered+by+the+rainforest.+This+region+includes+territory+belonging+to+nine+nations.+The+majority+of+the+forest+is+contained+within+Brazil%2C+with+60%25+of+the+rainforest%2C+followed+by+Peru+with+13%25%2C+Colombia+with+10%25%2C+and+with+minor+amounts+in+Venezuela%2C+Ecuador%2C+Bolivia%2C+Guyana%2C+Suriname+and+French+Guiana.+States+or+departments+in+four+nations+contain+%22Amazonas%22+in+their+names.+The+Amazon+represents+over+half+of+the+planet%27s+remaining+rainforests%2C+and+comprises+the+largest+and+most+biodiverse+tract+of+tropical+rainforest+in+the+world%2C+with+an+estimated+390+billion+individual+trees+divided+into+16%2C000+species)
- [T5๋ก ๋ฒ์ญํ๊ธฐ](https://huggingface.co/google-t5/t5-base?text=My+name+is+Wolfgang+and+I+live+in+Berlin)
์ปดํจํฐ ๋น์ :
- [ViT์ ํจ๊ปํ๋ ์ด๋ฏธ์ง ๋ถ๋ฅ](https://huggingface.co/google/vit-base-patch16-224)
- [DETR๋ก ๊ฐ์ฒด ํ์งํ๊ธฐ](https://huggingface.co/facebook/detr-resnet-50)
- [SegFormer๋ก ์๋ฏธ์ ๋ถํ (semantic segmentation)ํ๊ธฐ](https://huggingface.co/nvidia/segformer-b0-finetuned-ade-512-512)
- [Mask2Former๋ก ํ์ตํฑ ๋ถํ (panoptic segmentation)ํ๊ธฐ](https://huggingface.co/facebook/mask2former-swin-large-coco-panoptic)
- [Depth Anything์ผ๋ก ๊น์ด ์ถ์ (depth estimation)ํ๊ธฐ](https://huggingface.co/docs/transformers/main/model_doc/depth_anything)
- [VideoMAE์ ํจ๊ปํ๋ ๋น๋์ค ๋ถ๋ฅ](https://huggingface.co/docs/transformers/model_doc/videomae)
- [OneFormer๋ก ์ ๋๋ฒ์ค ๋ถํ (universal segmentation)ํ๊ธฐ](https://huggingface.co/shi-labs/oneformer_ade20k_dinat_large)
์ค๋์ค:
- [Whisper์ ํจ๊ปํ๋ ์๋ ์์ฑ ์ธ์](https://huggingface.co/openai/whisper-large-v3)
- [Wav2Vec2๋ก ํค์๋ ๊ฒ์ถ(keyword spotting)ํ๊ธฐ](https://huggingface.co/superb/wav2vec2-base-superb-ks)
- [Audio Spectrogram Transformer๋ก ์ค๋์ค ๋ถ๋ฅํ๊ธฐ](https://huggingface.co/MIT/ast-finetuned-audioset-10-10-0.4593)
๋ฉํฐ ๋ชจ๋ฌ(Multimodal Task):
- [TAPAS๋ก ํ ์์์ ์ง๋ฌธ ๋ต๋ณํ๊ธฐ](https://huggingface.co/google/tapas-base-finetuned-wtq)
- [ViLT์ ํจ๊ปํ๋ ์๊ฐ์ ์ง์์๋ต](https://huggingface.co/dandelin/vilt-b32-finetuned-vqa)
- [LLaVa๋ก ์ด๋ฏธ์ง์ ์ค๋ช
๋ฃ๊ธฐ](https://huggingface.co/llava-hf/llava-1.5-7b-hf)
- [SigLIP์ ํจ๊ปํ๋ ์ ๋ก ์ท(zero-shot) ์ด๋ฏธ์ง ๋ถ๋ฅ](https://huggingface.co/google/siglip-so400m-patch14-384)
- [LayoutLM์ผ๋ก ๋ฌธ์ ์์์ ์ง๋ฌธ ๋ต๋ณํ๊ธฐ](https://huggingface.co/impira/layoutlm-document-qa)
- [X-CLIP๊ณผ ํจ๊ปํ๋ ์ ๋ก ์ท(zero-shot) ๋น๋์ค ๋ถ๋ฅ](https://huggingface.co/docs/transformers/model_doc/xclip)
- [OWLv2๋ก ์งํํ๋ ์ ๋ก ์ท(zero-shot) ๊ฐ์ฒด ํ์ง](https://huggingface.co/docs/transformers/en/model_doc/owlv2)
- [CLIPSeg๋ก ์งํํ๋ ์ ๋ก ์ท(zero-shot) ์ด๋ฏธ์ง ๋ถํ ](https://huggingface.co/docs/transformers/model_doc/clipseg)
- [SAM๊ณผ ํจ๊ปํ๋ ์๋ ๋ง์คํฌ ์์ฑ](https://huggingface.co/docs/transformers/model_doc/sam)
**[Transformer์ ๊ธ์ฐ๊ธฐ](https://transformer.huggingface.co)** ๋ ์ด ์ ์ฅ์์ ํ
์คํธ ์์ฑ ๋ฅ๋ ฅ์ ๊ดํ Hugging Face ํ์ ๊ณต์ ๋ฐ๋ชจ์
๋๋ค.
## Transformers๋ฅผ ์ฌ์ฉํ 100๊ฐ์ ํ๋ก์ ํธ
Transformers๋ ์ฌ์ ํ์ต๋ ๋ชจ๋ธ๋ค์ ์ด์ฉํ๋ ๋๊ตฌ๋ฅผ ๋์ด Transformers์ ํจ๊ป ๋น๋ ๋ ํ๋ก์ ํธ ๋ฐ Hugging Face Hub๋ฅผ ์ํ ํ๋์ ์ปค๋ฎค๋ํฐ์
๋๋ค. ์ฐ๋ฆฌ๋ Transformers๋ฅผ ํตํด ๊ฐ๋ฐ์, ์ฐ๊ตฌ์, ํ์, ๊ต์, ์์ง๋์ด ๋ฐ ๋ชจ๋ ์ด๋ค์ด ๊ฟ์ ํ์ ํ๋ก์ ํธ(Dream Project)๋ฅผ ๋น๋ ํ ์ ์๊ธธ ๋ฐ๋๋๋ค.
Transformers์ ๋ฌ๋ฆฐ 100,000๊ฐ์ ๋ณ์ ์ถํํ๊ธฐ ์ํด, ์ฐ๋ฆฌ๋ ์ปค๋ฎค๋ํฐ๋ฅผ ์ฃผ๋ชฉํ๊ณ ์ Transformers๋ฅผ ํ๊ณ ๋น๋ ๋ 100๊ฐ์ ์ด๋ง์ด๋งํ ํ๋ก์ ํธ๋ค์ ์ ๋ณํ์ฌ [awesome-transformers](https://github.com/huggingface/transformers/blob/main/awesome-transformers.md) ํ์ด์ง์ ๋์ดํ์์ต๋๋ค.
๋ง์ผ ์์ ํ ํน์ ์ฌ์ฉํ๊ณ ๊ณ์ ํ๋ก์ ํธ๊ฐ ์ด ๋ฆฌ์คํธ์ ๊ผญ ๋ฑ์ฌ๋์ด์ผ ํ๋ค๊ณ ๋ฏฟ์ผ์ ๋ค๋ฉด, PR์ ์ด๊ณ ์ถ๊ฐํ์ฌ ์ฃผ์ธ์!
## ์กฐ์ง ์์์ AI ์ฌ์ฉ์ ๋ํด ์ง์งํ๊ฒ ๊ณ ๋ฏผ ์ค์ด์ ๊ฐ์? Hugging Face Enterprise Hub์ ํตํด ๋ ๋นจ๋ฆฌ ๊ตฌ์ถํด ๋ณด์ธ์.
<a target="_blank" href="https://huggingface.co/enterprise">
<img alt="Hugging Face Enterprise Hub" src="https://github.com/user-attachments/assets/247fb16d-d251-4583-96c4-d3d76dda4925">
</a><br>
## ํต ํฌ์ด
์ฃผ์ด์ง ์
๋ ฅ(ํ
์คํธ, ์ด๋ฏธ์ง, ์ค๋์ค, ...)์ ๋ฐ๋ก ๋ชจ๋ธ์ ์ฌ์ฉํ ์ ์๋๋ก, ์ฐ๋ฆฌ๋ `pipeline` API๋ฅผ ์ ๊ณตํฉ๋๋ค. Pipeline์ ์ฌ์ ํ์ต ๋ชจ๋ธ๊ณผ ๊ทธ ๋ชจ๋ธ์ ํ์ตํ ๋ ์ ์ฉํ ์ ์ฒ๋ฆฌ ๋ฐฉ์์ ํ๋๋ก ํฉ์นฉ๋๋ค. ๋ค์์ ๊ธ์ ์ ์ธ ํ
์คํธ์ ๋ถ์ ์ ์ธ ํ
์คํธ๋ฅผ ๋ถ๋ฅํ๊ธฐ ์ํด pipeline์ ์ฌ์ฉํ ๊ฐ๋จํ ์์์
๋๋ค:
```python
>>> from transformers import pipeline
# ๊ฐ์ ๋ถ์ ํ์ดํ๋ผ์ธ์ ํ ๋นํ์ธ์
>>> classifier = pipeline('sentiment-analysis')
>>> classifier('We are very happy to introduce pipeline to the transformers repository.')
[{'label': 'POSITIVE', 'score': 0.9996980428695679}]
```
์ฝ๋์ ๋ ๋ฒ์งธ ์ค์ pipeline์ด ์ฌ์ฉํ๋ ์ฌ์ ํ์ต ๋ชจ๋ธ์ ๋ค์ด๋ก๋ํ๊ณ ์บ์๋ก ์ ์ฅํฉ๋๋ค. ์ธ ๋ฒ์งธ ์ค์์ ๊ทธ ๋ชจ๋ธ์ด ์ฃผ์ด์ง ํ
์คํธ๋ฅผ ํ๊ฐํฉ๋๋ค. ์ฌ๊ธฐ์ ๋ชจ๋ธ์ 99.97%์ ํ๋ฅ ๋ก ํ
์คํธ๊ฐ ๊ธ์ ์ ์ด๋ผ๊ณ ํ๊ฐํ์ต๋๋ค.
์์ฐ์ด ์ฒ๋ฆฌ(NLP) ๋ฟ๋ง ์๋๋ผ ์ปดํจํฐ ๋น์ , ๋ฐํ(Speech) ๊ณผ์ ๋ค์ ์ฌ์ ํ์ต๋ `pipeline`์ผ๋ก ๋ฐ๋ก ์ํํ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด, ์ฌ์ง์์ ์์ฝ๊ฒ ๊ฐ์ฒด๋ค์ ํ์งํ ์ ์์ต๋๋ค.:
``` python
>>> import requests
>>> from PIL import Image
>>> from transformers import pipeline
# ๊ท์ฌ์ด ๊ณ ์์ด๊ฐ ์๋ ์ด๋ฏธ์ง๋ฅผ ๋ค์ด๋ก๋ํ์ธ์
>>> url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/coco_sample.png"
>>> image_data = requests.get(url, stream=True).raw
>>> image = Image.open(image_data)
# ๊ฐ์ฒด ๊ฐ์ง๋ฅผ ์ํ ํ์ดํ๋ผ์ธ์ ํ ๋นํ์ธ์
>>> object_detector = pipeline('object-detection')
>>> object_detector(image)
[{'score': 0.9982201457023621,
'label': 'remote',
'box': {'xmin': 40, 'ymin': 70, 'xmax': 175, 'ymax': 117}},
{'score': 0.9960021376609802,
'label': 'remote',
'box': {'xmin': 333, 'ymin': 72, 'xmax': 368, 'ymax': 187}},
{'score': 0.9954745173454285,
'label': 'couch',
'box': {'xmin': 0, 'ymin': 1, 'xmax': 639, 'ymax': 473}},
{'score': 0.9988006353378296,
'label': 'cat',
'box': {'xmin': 13, 'ymin': 52, 'xmax': 314, 'ymax': 470}},
{'score': 0.9986783862113953,
'label': 'cat',
'box': {'xmin': 345, 'ymin': 23, 'xmax': 640, 'ymax': 368}}]
```
์์ ๊ฐ์ด, ์ฐ๋ฆฌ๋ ์ด๋ฏธ์ง์์ ํ์ง๋ ๊ฐ์ฒด๋ค์ ๋ํ์ฌ ๊ฐ์ฒด๋ฅผ ๊ฐ์ธ๋ ๋ฐ์ค์ ํ๋ฅ ๋ฆฌ์คํธ๋ฅผ ์ป์ ์ ์์ต๋๋ค. ์ผ์ชฝ์ด ์๋ณธ ์ด๋ฏธ์ง์ด๋ฉฐ ์ค๋ฅธ์ชฝ์ ํด๋น ์ด๋ฏธ์ง์ ํ์ง๋ ๊ฒฐ๊ณผ๋ฅผ ํ์ํ์์ต๋๋ค.
<h3 align="center">
<a><img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/coco_sample.png" width="400"></a>
<a><img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/coco_sample_post_processed.png" width="400"></a>
</h3>
[์ด ํํ ๋ฆฌ์ผ](https://huggingface.co/docs/transformers/ko/task_summary)์์ `pipeline` API๊ฐ ์ง์ํ๋ ๋ค์ํ ๊ณผ์ ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค.
์ฝ๋ 3์ค๋ก ์ํ๋ ๊ณผ์ ์ ๋ง๊ฒ ์ฌ์ ํ์ต ๋ชจ๋ธ์ ๋ค์ด๋ก๋ ๋ฐ๊ณ ์ฌ์ฉํ ์ ์์ต๋๋ค. ๋ค์์ PyTorch ๋ฒ์ ์
๋๋ค:
```python
>>> from transformers import AutoTokenizer, AutoModel
>>> tokenizer = AutoTokenizer.from_pretrained("google-bert/bert-base-uncased")
>>> model = AutoModel.from_pretrained("google-bert/bert-base-uncased")
>>> inputs = tokenizer("Hello world!", return_tensors="pt")
>>> outputs = model(**inputs)
```
๋ค์์ TensorFlow ๋ฒ์ ์
๋๋ค:
```python
>>> from transformers import AutoTokenizer, TFAutoModel
>>> tokenizer = AutoTokenizer.from_pretrained("google-bert/bert-base-uncased")
>>> model = TFAutoModel.from_pretrained("google-bert/bert-base-uncased")
>>> inputs = tokenizer("Hello world!", return_tensors="tf")
>>> outputs = model(**inputs)
```
ํ ํฌ๋์ด์ ๋ ์ฌ์ ํ์ต ๋ชจ๋ธ์ ๋ชจ๋ ์ ์ฒ๋ฆฌ๋ฅผ ์ฑ
์์ง๋๋ค. ๊ทธ๋ฆฌ๊ณ (์์ ์์์ฒ๋ผ) 1๊ฐ์ ์คํธ๋ง์ด๋ ๋ฆฌ์คํธ๋ ์ฒ๋ฆฌํ ์ ์์ต๋๋ค. ํ ํฌ๋์ด์ ๋ ๋์
๋๋ฆฌ๋ฅผ ๋ฐํํ๋๋ฐ, ์ด๋ ๋ค์ด์คํธ๋ฆผ ์ฝ๋์ ์ฌ์ฉํ๊ฑฐ๋ ์ธํจํน ์ฐ์ฐ์ ** ๋ฅผ ์ด์ฉํด ๋ชจ๋ธ์ ๋ฐ๋ก ์ ๋ฌํ ์๋ ์์ต๋๋ค.
๋ชจ๋ธ ์์ฒด๋ ์ผ๋ฐ์ ์ผ๋ก ์ฌ์ฉ๋๋ [Pytorch `nn.Module`](https://pytorch.org/docs/stable/nn.html#torch.nn.Module)์ด๋ [TensorFlow `tf.keras.Model`](https://www.tensorflow.org/api_docs/python/tf/keras/Model)์
๋๋ค. [์ด ํํ ๋ฆฌ์ผ](https://huggingface.co/docs/transformers/ko/training)์ ์ด๋ฌํ ๋ชจ๋ธ์ ํ์ค์ ์ธ PyTorch๋ TensorFlow ํ์ต ๊ณผ์ ์์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ, ๋๋ ์๋ก์ด ๋ฐ์ดํฐ๋ก ํ์ธ ํ๋ํ๊ธฐ ์ํด `Trainer` API๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ์ค๋ช
ํด ์ค๋๋ค.
## ์ transformers๋ฅผ ์ฌ์ฉํด์ผ ํ ๊น์?
1. ์์ฝ๊ฒ ์ฌ์ฉํ ์ ์๋ ์ต์ฒจ๋จ ๋ชจ๋ธ:
- ์์ฐ์ด ์ดํด(NLU)์ ์์ฑ(NLG), ์ปดํจํฐ ๋น์ , ์ค๋์ค ๊ณผ์ ์์ ๋ฐ์ด๋ ์ฑ๋ฅ์ ๋ณด์
๋๋ค.
- ๊ต์ก์์ ์ค๋ฌด์์๊ฒ ์ง์
์ฅ๋ฒฝ์ด ๋ฎ์ต๋๋ค.
- 3๊ฐ์ ํด๋์ค๋ง ๋ฐฐ์ฐ๋ฉด ๋ฐ๋ก ์ฌ์ฉํ ์ ์์ต๋๋ค.
- ํ๋์ API๋ก ๋ชจ๋ ์ฌ์ ํ์ต ๋ชจ๋ธ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
1. ๋ ์ ์ ๊ณ์ฐ ๋น์ฉ, ๋ ์ ์ ํ์ ๋ฐ์๊ตญ:
- ์ฐ๊ตฌ์๋ค์ ๋ชจ๋ธ์ ๊ณ์ ๋ค์ ํ์ต์ํค๋ ๋์ ํ์ต๋ ๋ชจ๋ธ์ ๊ณต์ ํ ์ ์์ต๋๋ค.
- ์ค๋ฌด์๋ค์ ํ์ต์ ํ์ํ ์๊ฐ๊ณผ ๋น์ฉ์ ์ ์ฝํ ์ ์์ต๋๋ค.
- ๋ชจ๋ ๋ถ์ผ๋ฅผ ํตํ์ด์ 400,000๊ฐ ์ด์์ ์ฌ์ ํ์ต๋ ๋ชจ๋ธ์ด ์๋ ์์ญ ๊ฐ์ ์ํคํ
์ฒ.
1. ๋ชจ๋ธ์ ๊ฐ ์์ ์ฃผ๊ธฐ์ ์ ํฉํ ํ๋ ์์ํฌ:
- ์ฝ๋ 3์ค๋ก ์ต์ฒจ๋จ ๋ชจ๋ธ์ ํ์ตํ์ธ์.
- ๋ชฉ์ ์ ์๋ง๊ฒ ๋ชจ๋ธ์ TF2.0/Pytorch/Jax ํ๋ ์ ์ํฌ ์ค ํ๋๋ก ์ด๋์ํค์ธ์.
- ํ์ต, ํ๊ฐ, ๊ณต๊ฐ ๋ฑ ๊ฐ ๋จ๊ณ์ ๋ง๋ ํ๋ ์์ํฌ๋ฅผ ์ํ๋๋๋ก ์ ํํ์ธ์.
1. ํ์ํ ๋๋ก ๋ชจ๋ธ์ด๋ ์์๋ฅผ ์ปค์คํฐ๋ง์ด์ฆํ์ธ์:
- ์ฐ๋ฆฌ๋ ์ ์๊ฐ ๊ณต๊ฐํ ๊ฒฐ๊ณผ๋ฅผ ์ฌํํ๊ธฐ ์ํด ๊ฐ ๋ชจ๋ธ ๊ตฌ์กฐ์ ์์๋ฅผ ์ ๊ณตํฉ๋๋ค.
- ๋ชจ๋ธ ๋ด๋ถ ๊ตฌ์กฐ๋ ๊ฐ๋ฅํ ์ผ๊ด์ ์ผ๋ก ๊ณต๊ฐ๋์ด ์์ต๋๋ค.
- ๋น ๋ฅธ ์คํ์ ์ํด ๋ชจ๋ธ ํ์ผ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋
๋ฆฝ์ ์ผ๋ก ์ฌ์ฉ๋ ์ ์์ต๋๋ค.
## ์ transformers๋ฅผ ์ฌ์ฉํ์ง ๋ง์์ผ ํ ๊น์?
- ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ์ ๊ฒฝ๋ง ๋ธ๋ก์ ๋ง๋ค๊ธฐ ์ํ ๋ชจ๋์ด ์๋๋๋ค. ์ฐ๊ตฌ์๋ค์ด ์ฌ๋ฌ ํ์ผ์ ์ดํด๋ณด์ง ์๊ณ ๋ฐ๋ก ๊ฐ ๋ชจ๋ธ์ ์ฌ์ฉํ ์ ์๋๋ก, ๋ชจ๋ธ ํ์ผ ์ฝ๋์ ์ถ์ํ ์์ค์ ์ ์ ํ๊ฒ ์ ์งํ์ต๋๋ค.
- ํ์ต API๋ ๋ชจ๋ ๋ชจ๋ธ์ ์ ์ฉํ ์ ์๋๋ก ๋ง๋ค์ด์ง์ง ์์์ง๋ง, ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์ ๊ณตํ๋ ๋ชจ๋ธ๋ค์ ์ ์ฉํ ์ ์๋๋ก ์ต์ ํ๋์์ต๋๋ค. ์ผ๋ฐ์ ์ธ ๋จธ์ ๋ฌ๋์ ์ํด์ , ๋ค๋ฅธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ์ธ์(์๋ฅผ ๋ค๋ฉด, [Accelerate](https://huggingface.co/docs/accelerate/index)).
- ๊ฐ๋ฅํ ๋ง์ ์ฌ์ฉ ์์๋ฅผ ๋ณด์ฌ๋๋ฆฌ๊ณ ์ถ์ด์, [์์ ํด๋](https://github.com/huggingface/transformers/tree/main/examples)์ ์คํฌ๋ฆฝํธ๋ฅผ ์ค๋นํ์ต๋๋ค. ์ด ์คํฌ๋ฆฝํธ๋ค์ ์์ ์์ด ํน์ ํ ๋ฌธ์ ์ ๋ฐ๋ก ์ ์ฉํ์ง ๋ชปํ ์ ์์ต๋๋ค. ํ์์ ๋ง๊ฒ ์ผ๋ถ ์ฝ๋๋ฅผ ์์ ํด์ผ ํ ์ ์์ต๋๋ค.
## ์ค์น
### pip๋ก ์ค์นํ๊ธฐ
์ด ์ ์ฅ์๋ Python 3.9+, Flax 0.4.1+, PyTorch 2.1+, TensorFlow 2.6+์์ ํ
์คํธ ๋์์ต๋๋ค.
[๊ฐ์ ํ๊ฒฝ](https://docs.python.org/3/library/venv.html)์ ๐ค Transformers๋ฅผ ์ค์นํ์ธ์. Python ๊ฐ์ ํ๊ฒฝ์ ์ต์ํ์ง ์๋ค๋ฉด, [์ฌ์ฉ์ ๊ฐ์ด๋](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/)๋ฅผ ํ์ธํ์ธ์.
์ฐ์ , ์ฌ์ฉํ Python ๋ฒ์ ์ผ๋ก ๊ฐ์ ํ๊ฒฝ์ ๋ง๋ค๊ณ ์คํํ์ธ์.
๊ทธ ๋ค์, Flax, PyTorch, TensorFlow ์ค ์ ์ด๋ ํ๋๋ ์ค์นํด์ผ ํฉ๋๋ค.
ํ๋ซํผ์ ๋ง๋ ์ค์น ๋ช
๋ น์ด๋ฅผ ํ์ธํ๊ธฐ ์ํด [TensorFlow ์ค์น ํ์ด์ง](https://www.tensorflow.org/install/), [PyTorch ์ค์น ํ์ด์ง](https://pytorch.org/get-started/locally/#start-locally), [Flax ์ค์น ํ์ด์ง](https://github.com/google/flax#quick-install)๋ฅผ ํ์ธํ์ธ์.
์ด๋ค ์ค ์ ์ด๋ ํ๋๊ฐ ์ค์น๋์๋ค๋ฉด, ๐ค Transformers๋ ๋ค์๊ณผ ๊ฐ์ด pip์ ์ด์ฉํด ์ค์นํ ์ ์์ต๋๋ค:
```bash
pip install transformers
```
์์๋ค์ ์ฒดํํด๋ณด๊ณ ์ถ๊ฑฐ๋, ์ต์ต์ต์ฒจ๋จ ์ฝ๋๋ฅผ ์ํ๊ฑฐ๋, ์๋ก์ด ๋ฒ์ ์ด ๋์ฌ ๋๊น์ง ๊ธฐ๋ค๋ฆด ์ ์๋ค๋ฉด [๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์์ค์์ ๋ฐ๋ก ์ค์น](https://huggingface.co/docs/transformers/ko/installation#install-from-source)ํ์
์ผ ํฉ๋๋ค.
### conda๋ก ์ค์นํ๊ธฐ
๐ค Transformers๋ ๋ค์๊ณผ ๊ฐ์ด conda๋ก ์ค์นํ ์ ์์ต๋๋ค:
```shell script
conda install conda-forge::transformers
```
> **_๋
ธํธ:_** `huggingface` ์ฑ๋์์ `transformers`๋ฅผ ์ค์นํ๋ ๊ฒ์ ์ฌ์ฉ์ด ์ค๋จ๋์์ต๋๋ค.
Flax, PyTorch, TensorFlow ์ค์น ํ์ด์ง์์ ์ด๋ค์ conda๋ก ์ค์นํ๋ ๋ฐฉ๋ฒ์ ํ์ธํ์ธ์.
> **_๋
ธํธ:_** ์๋์ฐ ํ๊ฒฝ์์ ์บ์ฑ์ ์ด์ ์ ์ํด ๊ฐ๋ฐ์ ๋ชจ๋๋ฅผ ํ์ฑํํ ์ ์์ต๋๋ค. ๋ง์ฝ ์ฌ๋ฌ๋ถ์๊ฒ ์์ด์ ์ ํ์ด ์๋ ํ์๋ผ๋ฉด [์ด ์ด์](https://github.com/huggingface/huggingface_hub/issues/1062)๋ฅผ ํตํด ์๋ ค์ฃผ์ธ์.
## ๋ชจ๋ธ ๊ตฌ์กฐ
**๐ค Transformers๊ฐ ์ ๊ณตํ๋ [๋ชจ๋ ๋ชจ๋ธ ์ฒดํฌํฌ์ธํธ](https://huggingface.co/models)** ๋ huggingface.co [๋ชจ๋ธ ํ๋ธ](https://huggingface.co/models)์ ์๋ฒฝํ ์ฐ๋๋์ด ์์ต๋๋ค. [๊ฐ์ธ](https://huggingface.co/users)๊ณผ [๊ธฐ๊ด](https://huggingface.co/organizations)์ด ๋ชจ๋ธ ํ๋ธ์ ์ง์ ์
๋ก๋ํ ์ ์์ต๋๋ค.
ํ์ฌ ์ฌ์ฉ ๊ฐ๋ฅํ ๋ชจ๋ธ ์ฒดํฌํฌ์ธํธ์ ๊ฐ์: 
๐ค Transformers๋ ๋ค์ ๋ชจ๋ธ๋ค์ ์ ๊ณตํฉ๋๋ค: ๊ฐ ๋ชจ๋ธ์ ์์ฝ์ [์ฌ๊ธฐ](https://huggingface.co/docs/transformers/ko/model_summary)์ ํ์ธํ์ธ์.
๊ฐ ๋ชจ๋ธ์ด Flax, PyTorch, TensorFlow์ผ๋ก ๊ตฌํ๋์๋์ง ๋๋ ๐ค Tokenizers ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์ง์ํ๋ ํ ํฌ๋์ด์ ๋ฅผ ์ฌ์ฉํ๋์ง ํ์ธํ๋ ค๋ฉด, [์ด ํ](https://huggingface.co/docs/transformers/ko/index#supported-framework)๋ฅผ ํ์ธํ์ธ์.
์ด ๊ตฌํ์ ์ฌ๋ฌ ๋ฐ์ดํฐ๋ก ๊ฒ์ฆ๋์๊ณ (์์ ์คํฌ๋ฆฝํธ๋ฅผ ์ฐธ๊ณ ํ์ธ์) ์ค๋ฆฌ์ง๋ ๊ตฌํ์ ์ฑ๋ฅ๊ณผ ๊ฐ์์ผ ํฉ๋๋ค. [๋ํ๋จผํธ](https://github.com/huggingface/transformers/tree/main/examples)์ Examples ์น์
์์ ์ฑ๋ฅ์ ๋ํ ์์ธํ ์ค๋ช
์ ํ์ธํ ์ ์์ต๋๋ค.
## ๋ ์์๋ณด๊ธฐ
| ์น์
| ์ค๋ช
|
|-|-|
| [๋ํ๋จผํธ](https://huggingface.co/transformers/ko/) | ์ ์ฒด API ๋ํ๋จผํธ์ ํํ ๋ฆฌ์ผ |
| [๊ณผ์ ์์ฝ](https://huggingface.co/docs/transformers/ko/task_summary) | ๐ค Transformers๊ฐ ์ง์ํ๋ ๊ณผ์ ๋ค |
| [์ ์ฒ๋ฆฌ ํํ ๋ฆฌ์ผ](https://huggingface.co/docs/transformers/ko/preprocessing) | `Tokenizer` ํด๋์ค๋ฅผ ์ด์ฉํด ๋ชจ๋ธ์ ์ํ ๋ฐ์ดํฐ ์ค๋นํ๊ธฐ |
| [ํ์ต๊ณผ ํ์ธ ํ๋](https://huggingface.co/docs/transformers/ko/training) | ๐ค Transformers๊ฐ ์ ๊ณตํ๋ ๋ชจ๋ธ PyTorch/TensorFlow ํ์ต ๊ณผ์ ๊ณผ `Trainer` API์์ ์ฌ์ฉํ๊ธฐ |
| [ํต ํฌ์ด: ํ์ธ ํ๋/์ฌ์ฉ ์คํฌ๋ฆฝํธ](https://github.com/huggingface/transformers/tree/main/examples) | ๋ค์ํ ๊ณผ์ ์์ ๋ชจ๋ธ์ ํ์ธ ํ๋ํ๋ ์์ ์คํฌ๋ฆฝํธ |
| [๋ชจ๋ธ ๊ณต์ ๋ฐ ์
๋ก๋](https://huggingface.co/docs/transformers/ko/model_sharing) | ์ปค๋ฎค๋ํฐ์ ํ์ธ ํ๋๋ ๋ชจ๋ธ์ ์
๋ก๋ ๋ฐ ๊ณต์ ํ๊ธฐ |
## ์ธ์ฉ
๐ค Transformers ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ธ์ฉํ๊ณ ์ถ๋ค๋ฉด, ์ด [๋
ผ๋ฌธ](https://www.aclweb.org/anthology/2020.emnlp-demos.6/)์ ์ธ์ฉํด ์ฃผ์ธ์:
```bibtex
@inproceedings{wolf-etal-2020-transformers,
title = "Transformers: State-of-the-Art Natural Language Processing",
author = "Thomas Wolf and Lysandre Debut and Victor Sanh and Julien Chaumond and Clement Delangue and Anthony Moi and Pierric Cistac and Tim Rault and Rรฉmi Louf and Morgan Funtowicz and Joe Davison and Sam Shleifer and Patrick von Platen and Clara Ma and Yacine Jernite and Julien Plu and Canwen Xu and Teven Le Scao and Sylvain Gugger and Mariama Drame and Quentin Lhoest and Alexander M. Rush",
booktitle = "Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing: System Demonstrations",
month = oct,
year = "2020",
address = "Online",
publisher = "Association for Computational Linguistics",
url = "https://www.aclweb.org/anthology/2020.emnlp-demos.6",
pages = "38--45"
}
```
|