| <!--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. | |
| --> | |
| # ๐ค Transformers๋ก ํ ์ ์๋ ๊ฒ[[what__transformers_can_do]] | |
| ๐ค Transformers๋ ์์ฐ์ด์ฒ๋ฆฌ(NLP), ์ปดํจํฐ ๋น์ , ์ค๋์ค ๋ฐ ์์ฑ ์ฒ๋ฆฌ ์์ ์ ๋ํ ์ฌ์ ํ๋ จ๋ ์ต์ฒจ๋จ ๋ชจ๋ธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋๋ค. | |
| ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ํธ๋์คํฌ๋จธ ๋ชจ๋ธ๋ฟ๋ง ์๋๋ผ ์ปดํจํฐ ๋น์ ์์ ์ ์ํ ํ๋์ ์ธ ํฉ์ฑ๊ณฑ ์ ๊ฒฝ๋ง๊ณผ ๊ฐ์ ํธ๋์คํฌ๋จธ๊ฐ ์๋ ๋ชจ๋ธ๋ ํฌํจํ๊ณ ์์ต๋๋ค. | |
| ์ค๋งํธํฐ, ์ฑ, ํ ๋ ๋น์ ๊ณผ ๊ฐ์ ์ค๋๋ ๊ฐ์ฅ ์ธ๊ธฐ ์๋ ์๋น์ ์ ํ์ ์ดํด๋ณด๋ฉด, ๋ฅ๋ฌ๋ ๊ธฐ์ ์ด ๊ทธ ๋ค์ ์ฌ์ฉ๋๊ณ ์์ ํ๋ฅ ์ด ๋์ต๋๋ค. | |
| ์ค๋งํธํฐ์ผ๋ก ์ดฌ์ํ ์ฌ์ง์์ ๋ฐฐ๊ฒฝ ๊ฐ์ฒด๋ฅผ ์ ๊ฑฐํ๊ณ ์ถ๋ค๋ฉด ์ด๋ป๊ฒ ํ ๊น์? ์ด๋ ํ๋ํฑ ์ธ๊ทธ๋ฉํ ์ด์ ์์ ์ ์์ ๋๋ค(์์ง ์ด๊ฒ ๋ฌด์์ธ์ง ๋ชจ๋ฅธ๋ค๋ฉด, ๋ค์ ์น์ ์์ ์ค๋ช ํ๊ฒ ์ต๋๋ค!). | |
| ์ด ํ์ด์ง๋ ๋ค์ํ ์์ฑ ๋ฐ ์ค๋์ค, ์ปดํจํฐ ๋น์ , NLP ์์ ์ ๐ค Transformers ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ํ์ฉํ์ฌ ๋ค๋ฃจ๋ ๊ฐ๋จํ ์์ ๋ฅผ 3์ค์ ์ฝ๋๋ก ์ ๊ณตํฉ๋๋ค. | |
| ## ์ค๋์ค[[audio]] | |
| ์์ฑ ๋ฐ ์ค๋์ค ์ฒ๋ฆฌ ์์ ์ ๋ค๋ฅธ ๋ชจ๋ฌ๋ฆฌํฐ์ ์ฝ๊ฐ ๋ค๋ฆ ๋๋ค. ์ด๋ ์ฃผ๋ก ์ค๋์ค๊ฐ ์ฐ์์ ์ธ ์ ํธ๋ก ์ ๋ ฅ๋๊ธฐ ๋๋ฌธ์ ๋๋ค. | |
| ํ ์คํธ์ ๋ฌ๋ฆฌ ์๋ณธ ์ค๋์ค ํํ(waveform)์ ๋ฌธ์ฅ์ด ๋จ์ด๋ก ๋๋ ์ง๋ ๊ฒ์ฒ๋ผ ๊น๋ํ๊ฒ ์ด์ฐ์ ์ธ ๋ฌถ์์ผ๋ก ๋๋ ์ ์์ต๋๋ค. | |
| ์ด๋ฅผ ๊ทน๋ณตํ๊ธฐ ์ํด ์๋ณธ ์ค๋์ค ์ ํธ๋ ์ผ์ ํ ๊ฐ๊ฒฉ์ผ๋ก ์ํ๋ง๋ฉ๋๋ค. ํด๋น ๊ฐ๊ฒฉ ๋ด์์ ๋ ๋ง์ ์ํ์ ์ทจํ ๊ฒฝ์ฐ ์ํ๋ง๋ฅ ์ด ๋์์ง๋ฉฐ, ์ค๋์ค๋ ์๋ณธ ์ค๋์ค ์์ค์ ๋ ๊ฐ๊น์์ง๋๋ค. | |
| ๊ณผ๊ฑฐ์ ์ ๊ทผ ๋ฐฉ์์ ์ค๋์ค์์ ์ ์ฉํ ํน์ง์ ์ถ์ถํ๊ธฐ ์ํด ์ค๋์ค๋ฅผ ์ ์ฒ๋ฆฌํ๋ ๊ฒ์ด์์ต๋๋ค. | |
| ํ์ง๋ง ํ์ฌ๋ ์๋ณธ ์ค๋์ค ํํ์ ํน์ฑ ์ธ์ฝ๋์ ์ง์ ๋ฃ์ด์ ์ค๋์ค ํํ(representation)์ ์ถ์ถํ๋ ๊ฒ์ด ๋ ์ผ๋ฐ์ ์ ๋๋ค. | |
| ์ด๋ ๊ฒ ํ๋ฉด ์ ์ฒ๋ฆฌ ๋จ๊ณ๊ฐ ๋จ์ํด์ง๊ณ ๋ชจ๋ธ์ด ๊ฐ์ฅ ์ค์ํ ํน์ง์ ํ์ตํ ์ ์์ต๋๋ค. | |
| ### ์ค๋์ค ๋ถ๋ฅ[[audio_classification]] | |
| ์ค๋์ค ๋ถ๋ฅ๋ ์ค๋์ค ๋ฐ์ดํฐ์ ๋ฏธ๋ฆฌ ์ ์๋ ํด๋์ค ์งํฉ์ ๋ ์ด๋ธ์ ์ง์ ํ๋ ์์ ์ ๋๋ค. ์ด๋ ๋ง์ ๊ตฌ์ฒด์ ์ธ ์์ฉ ํ๋ก๊ทธ๋จ์ ํฌํจํ ๋์ ๋ฒ์ฃผ์ ๋๋ค. | |
| ์ผ๋ถ ์์๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค: | |
| * ์ํฅ ์ฅ๋ฉด ๋ถ๋ฅ: ์ค๋์ค์ ์ฅ๋ฉด ๋ ์ด๋ธ("์ฌ๋ฌด์ค", "ํด๋ณ", "๊ฒฝ๊ธฐ์ฅ")์ ์ง์ ํฉ๋๋ค. | |
| * ์ํฅ ์ด๋ฒคํธ ๊ฐ์ง: ์ค๋์ค์ ์๋ฆฌ ์ด๋ฒคํธ ๋ ์ด๋ธ("์ฐจ ๊ฒฝ์ ", "๊ณ ๋ ์ธ์์๋ฆฌ", "์ ๋ฆฌ ํ์")์ ์ง์ ํฉ๋๋ค. | |
| * ํ๊น : ์ฌ๋ฌ ๊ฐ์ง ์๋ฆฌ(์ ์ง์ ๊ท, ํ์์์์ ํ์ ์๋ณ)๊ฐ ํฌํจ๋ ์ค๋์ค์ ๋ ์ด๋ธ์ ์ง์ ํฉ๋๋ค. | |
| * ์์ ๋ถ๋ฅ: ์์ ์ ์ฅ๋ฅด ๋ ์ด๋ธ("๋ฉํ", "ํํฉ", "์ปจํธ๋ฆฌ")์ ์ง์ ํฉ๋๋ค. | |
| ```py | |
| >>> from transformers import pipeline | |
| >>> classifier = pipeline(task="audio-classification", model="superb/hubert-base-superb-er") | |
| >>> preds = classifier("https://huggingface.co/datasets/Narsil/asr_dummy/resolve/main/mlk.flac") | |
| >>> preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds] | |
| >>> preds | |
| [{'score': 0.4532, 'label': 'hap'}, | |
| {'score': 0.3622, 'label': 'sad'}, | |
| {'score': 0.0943, 'label': 'neu'}, | |
| {'score': 0.0903, 'label': 'ang'}] | |
| ``` | |
| ### ์๋ ์์ฑ ์ธ์[[automatic_speech_recognition]] | |
| ์๋ ์์ฑ ์ธ์(ASR)์ ์์ฑ์ ํ ์คํธ๋ก ๋ณํํ๋ ์์ ์ ๋๋ค. | |
| ์์ฑ์ ์ธ๊ฐ์ ์์ฐ์ค๋ฌ์ด ์์ฌ์ํต ํํ์ด๊ธฐ ๋๋ฌธ์ ASR์ ๊ฐ์ฅ ์ผ๋ฐ์ ์ธ ์ค๋์ค ์์ ์ค ํ๋์ ๋๋ค. | |
| ์ค๋๋ ASR ์์คํ ์ ์คํผ์ปค, ์ ํ ๋ฐ ์๋์ฐจ์ ๊ฐ์ "์ค๋งํธ" ๊ธฐ์ ์ ํ์ ๋ด์ฅ๋์ด ์์ต๋๋ค. | |
| ์ฐ๋ฆฌ๋ ๊ฐ์ ๋น์์๊ฒ ์์ ์ฌ์, ์๋ฆผ ์ค์ ๋ฐ ๋ ์จ ์ ๋ณด๋ฅผ ์์ฒญํ ์ ์์ต๋๋ค. | |
| ํ์ง๋ง ํธ๋์คํฌ๋จธ ์ํคํ ์ฒ๊ฐ ํด๊ฒฐํ๋ ๋ฐ ๋์์ ์ค ํต์ฌ ๋์ ๊ณผ์ ์ค ํ๋๋ ์์ด ๋ฐ์ดํฐ ์์ด ์ ์ ์ธ์ด(low-resource language)์ ๋ํ ๊ฒ์ ๋๋ค. ๋๋์ ์์ฑ ๋ฐ์ดํฐ๋ก ์ฌ์ ํ๋ จํ ํ ๋ฐ์ดํฐ ์์ด ์ ์ ์ธ์ด์์ ๋ ์ด๋ธ์ด ์ง์ ๋ ์์ฑ ๋ฐ์ดํฐ 1์๊ฐ๋ง์ผ๋ก ๋ชจ๋ธ์ ๋ฏธ์ธ ์กฐ์ ํ๋ฉด ์ด์ ์ 100๋ฐฐ ๋ง์ ๋ ์ด๋ธ์ด ์ง์ ๋ ๋ฐ์ดํฐ๋ก ํ๋ จ๋ ASR ์์คํ ๋ณด๋ค ํจ์ฌ ๋ ๋์ ํ์ง์ ๊ฒฐ๊ณผ๋ฅผ ์ป์ ์ ์์ต๋๋ค. | |
| ```py | |
| >>> from transformers import pipeline | |
| >>> transcriber = pipeline(task="automatic-speech-recognition", model="openai/whisper-small") | |
| >>> transcriber("https://huggingface.co/datasets/Narsil/asr_dummy/resolve/main/mlk.flac") | |
| {'text': ' I have a dream that one day this nation will rise up and live out the true meaning of its creed.'} | |
| ``` | |
| ## ์ปดํจํฐ ๋น์ [[computer_vision]] | |
| ์ปดํจํฐ ๋น์ ์์ ์ค ๊ฐ์ฅ ์ด๊ธฐ์ ์ฑ๊ณต์ ์ธ ์์ ์ค ํ๋๋ [ํฉ์ฑ๊ณฑ ์ ๊ฒฝ๋ง(CNN)](glossary#convolution)์ ์ฌ์ฉํ์ฌ ์ฐํธ๋ฒํธ ์ซ์ ์ด๋ฏธ์ง๋ฅผ ์ธ์ํ๋ ๊ฒ์ด์์ต๋๋ค. ์ด๋ฏธ์ง๋ ํฝ์ ๋ก ๊ตฌ์ฑ๋์ด ์์ผ๋ฉฐ ๊ฐ ํฝ์ ์ ์ซ์ ๊ฐ์ผ๋ก ํํ๋ฉ๋๋ค. ์ด๋ก์จ ์ด๋ฏธ์ง๋ฅผ ํฝ์ ๊ฐ์ ํ๋ ฌ๋ก ๋ํ๋ด๋ ๊ฒ์ด ์ฌ์์ง๋๋ค. ํน์ ํ ํฝ์ ๊ฐ์ ์กฐํฉ์ ์ด๋ฏธ์ง์ ์์์ ์๋ฏธํฉ๋๋ค. | |
| ์ปดํจํฐ ๋น์ ์์ ์ ์ผ๋ฐ์ ์ผ๋ก ๋ค์ ๋ ๊ฐ์ง ๋ฐฉ๋ฒ์ผ๋ก ์ ๊ทผ ๊ฐ๋ฅํฉ๋๋ค: | |
| 1. ํฉ์ฑ๊ณฑ์ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง์ ๋ฎ์ ์์ค ํน์ง์์ ๋์ ์์ค์ ์ถ์์ ์ธ ์์๊น์ง ๊ณ์ธต์ ์ผ๋ก ํ์ตํฉ๋๋ค. | |
| 2. ์ด๋ฏธ์ง๋ฅผ ํจ์น๋ก ๋๋๊ณ ํธ๋์คํฌ๋จธ๋ฅผ ์ฌ์ฉํ์ฌ ์ ์ง์ ์ผ๋ก ๊ฐ ์ด๋ฏธ์ง ํจ์น๊ฐ ์๋ก ์ด๋ ํ ๋ฐฉ์์ผ๋ก ์ฐ๊ด๋์ด ์ด๋ฏธ์ง๋ฅผ ํ์ฑํ๋์ง ํ์ตํฉ๋๋ค. `CNN`์์ ์ ํธํ๋ ์ํฅ์ ์ ๊ทผ๋ฒ๊ณผ๋ ๋ฌ๋ฆฌ, ์ด ๋ฐฉ์์ ํ๋ฆฟํ ์ด๋ฏธ์ง๋ก ์ด์์ ๊ทธ๋ฆฌ๊ณ ์ ์ง์ ์ผ๋ก ์ ๋ช ํ ์ด๋ฏธ์ง๋ก ๋ง๋ค์ด๊ฐ๋ ๊ฒ๊ณผ ์ ์ฌํฉ๋๋ค. | |
| ### ์ด๋ฏธ์ง ๋ถ๋ฅ[[image_classification]] | |
| ์ด๋ฏธ์ง ๋ถ๋ฅ๋ ํ ๊ฐ์ ์ ์ฒด ์ด๋ฏธ์ง์ ๋ฏธ๋ฆฌ ์ ์๋ ํด๋์ค ์งํฉ์ ๋ ์ด๋ธ์ ์ง์ ํ๋ ์์ ์ ๋๋ค. | |
| ๋๋ถ๋ถ์ ๋ถ๋ฅ ์์ ๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก, ์ด๋ฏธ์ง ๋ถ๋ฅ์๋ ๋ค์ํ ์ค์ฉ์ ์ธ ์ฉ๋๊ฐ ์์ผ๋ฉฐ, ์ผ๋ถ ์์๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค: | |
| * ์๋ฃ: ์ง๋ณ์ ๊ฐ์งํ๊ฑฐ๋ ํ์ ๊ฑด๊ฐ์ ๋ชจ๋ํฐ๋งํ๊ธฐ ์ํด ์๋ฃ ์ด๋ฏธ์ง์ ๋ ์ด๋ธ์ ์ง์ ํฉ๋๋ค. | |
| * ํ๊ฒฝ: ์์ฑ ์ด๋ฏธ์ง๋ฅผ ๋ถ๋ฅํ์ฌ ์ฐ๋ฆผ ๋ฒ์ฑ๋ฅผ ๊ฐ์ํ๊ณ ์ผ์ ์ง์ญ ๊ด๋ฆฌ๋ฅผ ์ํ ์ ๋ณด๋ฅผ ์ ๊ณตํ๊ฑฐ๋ ์ฐ๋ถ์ ๊ฐ์งํฉ๋๋ค. | |
| * ๋์ : ์๋ฌผ ์ด๋ฏธ์ง๋ฅผ ๋ถ๋ฅํ์ฌ ์๋ฌผ ๊ฑด๊ฐ์ ํ์ธํ๊ฑฐ๋ ์์ฑ ์ด๋ฏธ์ง๋ฅผ ๋ถ๋ฅํ์ฌ ํ ์ง ์ด์ฉ ๊ด์ฐฐ์ ์ฌ์ฉํฉ๋๋ค. | |
| * ์ํํ: ๋๋ฌผ์ด๋ ์๋ฌผ ์ข ์ด๋ฏธ์ง๋ฅผ ๋ถ๋ฅํ์ฌ ์ผ์ ๋๋ฌผ ๊ฐ์ฒด๊ตฐ์ ์กฐ์ฌํ๊ฑฐ๋ ๋ฉธ์ข ์๊ธฐ์ ์ฒํ ์ข ์ ์ถ์ ํฉ๋๋ค. | |
| ```py | |
| >>> from transformers import pipeline | |
| >>> classifier = pipeline(task="image-classification") | |
| >>> preds = classifier( | |
| ... "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg" | |
| ... ) | |
| >>> preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds] | |
| >>> print(*preds, sep="\n") | |
| {'score': 0.4335, 'label': 'lynx, catamount'} | |
| {'score': 0.0348, 'label': 'cougar, puma, catamount, mountain lion, painter, panther, Felis concolor'} | |
| {'score': 0.0324, 'label': 'snow leopard, ounce, Panthera uncia'} | |
| {'score': 0.0239, 'label': 'Egyptian cat'} | |
| {'score': 0.0229, 'label': 'tiger cat'} | |
| ``` | |
| ### ๊ฐ์ฒด ํ์ง[[object_detection]] | |
| ์ด๋ฏธ์ง ๋ถ๋ฅ์ ๋ฌ๋ฆฌ ๊ฐ์ฒด ํ์ง๋ ์ด๋ฏธ์ง ๋ด์์ ์ฌ๋ฌ ๊ฐ์ฒด๋ฅผ ์๋ณํ๊ณ ๋ฐ์ด๋ฉ ๋ฐ์ค๋ก ์ ์๋ ๊ฐ์ฒด์ ์์น๋ฅผ ํ์ ํฉ๋๋ค. | |
| ๊ฐ์ฒด ํ์ง์ ๋ช ๊ฐ์ง ์์ฉ ์์๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค: | |
| * ์์จ ์ฃผํ ์ฐจ๋: ๋ค๋ฅธ ์ฐจ๋, ๋ณดํ์ ๋ฐ ์ ํธ๋ฑ๊ณผ ๊ฐ์ ์ผ์์ ์ธ ๊ตํต ๊ฐ์ฒด๋ฅผ ๊ฐ์งํฉ๋๋ค. | |
| * ์๊ฒฉ ๊ฐ์ง: ์ฌ๋ ๋ชจ๋ํฐ๋ง, ๋์ ๊ณํ ๋ฐ ๊ธฐ์ ์์ธก ๋ฑ์ ์ํํฉ๋๋ค. | |
| * ๊ฒฐํจ ํ์ง: ๊ฑด๋ฌผ์ ๊ท ์ด์ด๋ ๊ตฌ์กฐ์ ์์, ์ ์กฐ ๊ฒฐํจ ๋ฑ์ ํ์งํฉ๋๋ค. | |
| ```py | |
| >>> from transformers import pipeline | |
| >>> detector = pipeline(task="object-detection") | |
| >>> preds = detector( | |
| ... "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg" | |
| ... ) | |
| >>> preds = [{"score": round(pred["score"], 4), "label": pred["label"], "box": pred["box"]} for pred in preds] | |
| >>> preds | |
| [{'score': 0.9865, | |
| 'label': 'cat', | |
| 'box': {'xmin': 178, 'ymin': 154, 'xmax': 882, 'ymax': 598}}] | |
| ``` | |
| ### ์ด๋ฏธ์ง ๋ถํ [[image_segmentation]] | |
| ์ด๋ฏธ์ง ๋ถํ ์ ํฝ์ ์ฐจ์์ ์์ ์ผ๋ก, ์ด๋ฏธ์ง ๋ด์ ๋ชจ๋ ํฝ์ ์ ํด๋์ค์ ํ ๋นํฉ๋๋ค. ์ด๋ ๊ฐ์ฒด ํ์ง์ ๋ค๋ฆ ๋๋ค. ๊ฐ์ฒด ํ์ง๋ ๋ฐ์ด๋ฉ ๋ฐ์ค๋ฅผ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง ๋ด์ ๊ฐ์ฒด๋ฅผ ๋ ์ด๋ธ๋งํ๊ณ ์์ธกํ๋ ๋ฐ๋ฉด, ๋ถํ ์ ๋ ์ธ๋ถํ๋ ์์ ์ ๋๋ค. ๋ถํ ์ ํฝ์ ์์ค์์ ๊ฐ์ฒด๋ฅผ ๊ฐ์งํ ์ ์์ต๋๋ค. | |
| ์ด๋ฏธ์ง ๋ถํ ์๋ ์ฌ๋ฌ ์ ํ์ด ์์ต๋๋ค: | |
| * ์ธ์คํด์ค ๋ถํ : ๊ฐ์ฒด์ ํด๋์ค๋ฅผ ๋ ์ด๋ธ๋งํ๋ ๊ฒ ์ธ์๋, ๊ฐ์ฒด์ ๊ฐ ๊ตฌ๋ถ๋ ์ธ์คํด์ค์๋ ๋ ์ด๋ธ์ ์ง์ ํฉ๋๋ค ("๊ฐ-1", "๊ฐ-2" ๋ฑ). | |
| * ํ๋ํฑ ๋ถํ : ์๋ฏธ์ ๋ถํ ๊ณผ ์ธ์คํด์ค ๋ถํ ์ ์กฐํฉ์ ๋๋ค. ๊ฐ ํฝ์ ์ ์๋ฏธ์ ํด๋์ค๋ก ๋ ์ด๋ธ๋งํ๋ **๋์์** ๊ฐ์ฒด์ ๊ฐ๊ฐ ๊ตฌ๋ถ๋ ์ธ์คํด์ค๋ก๋ ๋ ์ด๋ธ์ ์ง์ ํฉ๋๋ค. | |
| ๋ถํ ์์ ์ ์์จ ์ฃผํ ์ฐจ๋์์ ์ ์ฉํ๋ฉฐ, ์ฃผ๋ณ ํ๊ฒฝ์ ํฝ์ ์์ค ์ง๋๋ฅผ ์์ฑํ์ฌ ๋ณดํ์์ ๋ค๋ฅธ ์ฐจ๋ ์ฃผ๋ณ์์ ์์ ํ๊ฒ ํ์ํ ์ ์์ต๋๋ค. ๋ํ ์๋ฃ ์์์์๋ ์ ์ฉํฉ๋๋ค. ๋ถํ ์์ ์ด ํฝ์ ์์ค์์ ๊ฐ์ฒด๋ฅผ ๊ฐ์งํ ์ ์๊ธฐ ๋๋ฌธ์ ๋น์ ์์ ์ธ ์ธํฌ๋ ์ฅ๊ธฐ์ ํน์ง์ ์๋ณํ๋ ๋ฐ ๋์์ด ๋ ์ ์์ต๋๋ค. ์ด๋ฏธ์ง ๋ถํ ์ ์๋ฅ ๊ฐ์ ์์ฐฉ์ด๋ ์นด๋ฉ๋ผ๋ฅผ ํตํด ์ค์ ์ธ๊ณ์ ๊ฐ์ ๊ฐ์ฒด๋ฅผ ๋ง์์ ์ฆ๊ฐ ํ์ค ๊ฒฝํ์ ๋ง๋๋ ๋ฑ ์ ์ ์๊ฑฐ๋ ๋ถ์ผ์์๋ ์ฌ์ฉ๋ ์ ์์ต๋๋ค. | |
| ```py | |
| >>> from transformers import pipeline | |
| >>> segmenter = pipeline(task="image-segmentation") | |
| >>> preds = segmenter( | |
| ... "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg" | |
| ... ) | |
| >>> preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds] | |
| >>> print(*preds, sep="\n") | |
| {'score': 0.9879, 'label': 'LABEL_184'} | |
| {'score': 0.9973, 'label': 'snow'} | |
| {'score': 0.9972, 'label': 'cat'} | |
| ``` | |
| ### ๊น์ด ์ถ์ [[depth_estimation]] | |
| ๊น์ด ์ถ์ ์ ์นด๋ฉ๋ผ๋ก๋ถํฐ ์ด๋ฏธ์ง ๋ด๋ถ์ ๊ฐ ํฝ์ ์ ๊ฑฐ๋ฆฌ๋ฅผ ์์ธกํฉ๋๋ค. ์ด ์ปดํจํฐ ๋น์ ์์ ์ ํนํ ์ฅ๋ฉด ์ดํด์ ์ฌ๊ตฌ์ฑ์ ์ค์ํฉ๋๋ค. ์๋ฅผ ๋ค์ด, ์์จ ์ฃผํ ์ฐจ๋์ ๋ณดํ์, ๊ตํต ํ์งํ ๋ฐ ๋ค๋ฅธ ์ฐจ๋๊ณผ ๊ฐ์ ๊ฐ์ฒด์์ ๊ฑฐ๋ฆฌ๋ฅผ ์ดํดํ์ฌ ์ฅ์ ๋ฌผ๊ณผ ์ถฉ๋์ ํผํด์ผ ํฉ๋๋ค. ๊น์ด ์ ๋ณด๋ ๋ํ 2D ์ด๋ฏธ์ง์์ 3D ํํ์ ๊ตฌ์ฑํ๋ ๋ฐ ๋์์ด ๋๋ฉฐ ์๋ฌผํ์ ๊ตฌ์กฐ๋ ๊ฑด๋ฌผ์ ๊ณ ํ์ง 3D ํํ์ ์์ฑํ๋ ๋ฐ ์ฌ์ฉ๋ ์ ์์ต๋๋ค. | |
| ๊น์ด ์ถ์ ์๋ ๋ ๊ฐ์ง ์ ๊ทผ ๋ฐฉ์์ด ์์ต๋๋ค: | |
| * ์คํ ๋ ์ค: ์ฝ๊ฐ ๋ค๋ฅธ ๊ฐ๋์์ ์ดฌ์๋ ๋์ผํ ์ด๋ฏธ์ง ๋ ์ฅ์ ๋น๊ตํ์ฌ ๊น์ด๋ฅผ ์ถ์ ํฉ๋๋ค. | |
| * ๋จ์: ๋จ์ผ ์ด๋ฏธ์ง์์ ๊น์ด๋ฅผ ์ถ์ ํฉ๋๋ค. | |
| ```py | |
| >>> from transformers import pipeline | |
| >>> depth_estimator = pipeline(task="depth-estimation") | |
| >>> preds = depth_estimator( | |
| ... "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg" | |
| ... ) | |
| ``` | |
| ## ์์ฐ์ด์ฒ๋ฆฌ[[natural_language_processing]] | |
| ํ ์คํธ๋ ์ธ๊ฐ์ด ์์ฌ ์ํตํ๋ ์์ฐ์ค๋ฌ์ด ๋ฐฉ์ ์ค ํ๋์ด๊ธฐ ๋๋ฌธ์ ์์ฐ์ด์ฒ๋ฆฌ ์ญ์ ๊ฐ์ฅ ์ผ๋ฐ์ ์ธ ์์ ์ ํ ์ค ํ๋์ ๋๋ค. ๋ชจ๋ธ์ด ์ธ์ํ๋ ํ์์ผ๋ก ํ ์คํธ๋ฅผ ๋ณํํ๋ ค๋ฉด ํ ํฐํํด์ผ ํฉ๋๋ค. ์ด๋ ํ ์คํธ ์ํ์ค๋ฅผ ๊ฐ๋ณ ๋จ์ด ๋๋ ํ์ ๋จ์ด(ํ ํฐ)๋ก ๋ถํ ํ ๋ค์ ์ด๋ฌํ ํ ํฐ์ ์ซ์๋ก ๋ณํํ๋ ๊ฒ์ ์๋ฏธํฉ๋๋ค. ๊ฒฐ๊ณผ์ ์ผ๋ก ํ ์คํธ ์ํ์ค๋ฅผ ์ซ์ ์ํ์ค๋ก ํํํ ์ ์์ผ๋ฉฐ, ์ซ์ ์ํ์ค๋ฅผ ๋ค์ํ ์์ฐ์ด์ฒ๋ฆฌ ์์ ์ ํด๊ฒฐํ๊ธฐ ์ํ ๋ชจ๋ธ์ ์ ๋ ฅํ ์ ์์ต๋๋ค! | |
| ### ํ ์คํธ ๋ถ๋ฅ[[text_classification]] | |
| ๋ค๋ฅธ ๋ชจ๋ฌ๋ฆฌํฐ์์์ ๋ถ๋ฅ ์์ ๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก ํ ์คํธ ๋ถ๋ฅ๋ ๋ฏธ๋ฆฌ ์ ์๋ ํด๋์ค ์งํฉ์์ ํ ์คํธ ์ํ์ค(๋ฌธ์ฅ ์์ค, ๋จ๋ฝ ๋๋ ๋ฌธ์ ๋ฑ)์ ๋ ์ด๋ธ์ ์ง์ ํฉ๋๋ค. ํ ์คํธ ๋ถ๋ฅ์๋ ๋ค์ํ ์ค์ฉ์ ์ธ ์์ฉ ์ฌ๋ก๊ฐ ์์ผ๋ฉฐ, ์ผ๋ถ ์์๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค: | |
| * ๊ฐ์ฑ ๋ถ์: ํ ์คํธ๋ฅผ `๊ธ์ ` ๋๋ `๋ถ์ `๊ณผ ๊ฐ์ ์ด๋ค ๊ทน์ฑ์ ๋ฐ๋ผ ๋ ์ด๋ธ๋งํ์ฌ ์ ์น, ๊ธ์ต, ๋ง์ผํ ๊ณผ ๊ฐ์ ๋ถ์ผ์์ ์์ฌ ๊ฒฐ์ ์ ์ ๋ณด๋ฅผ ์ ๊ณตํ๊ณ ์ง์ํ ์ ์์ต๋๋ค. | |
| * ์ฝํ ์ธ ๋ถ๋ฅ: ํ ์คํธ๋ฅผ ์ฃผ์ ์ ๋ฐ๋ผ ๋ ์ด๋ธ๋ง(๋ ์จ, ์คํฌ์ธ , ๊ธ์ต ๋ฑ)ํ์ฌ ๋ด์ค ๋ฐ ์์ ๋ฏธ๋์ด ํผ๋์์ ์ ๋ณด๋ฅผ ๊ตฌ์ฑํ๊ณ ํํฐ๋งํ๋ ๋ฐ ๋์์ด ๋ ์ ์์ต๋๋ค. | |
| ```py | |
| >>> from transformers import pipeline | |
| >>> classifier = pipeline(task="sentiment-analysis") | |
| >>> preds = classifier("Hugging Face is the best thing since sliced bread!") | |
| >>> preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds] | |
| >>> preds | |
| [{'score': 0.9991, 'label': 'POSITIVE'}] | |
| ``` | |
| ### ํ ํฐ ๋ถ๋ฅ[[token_classification]] | |
| ๋ชจ๋ ์์ฐ์ด์ฒ๋ฆฌ ์์ ์์๋ ํ ์คํธ๊ฐ ๊ฐ๋ณ ๋จ์ด๋ ํ์ ๋จ์ด๋ก ๋ถ๋ฆฌ๋์ด ์ ์ฒ๋ฆฌ๋ฉ๋๋ค. ๋ถ๋ฆฌ๋ ๋จ์ด๋ฅผ [ํ ํฐ](/glossary#token)์ด๋ผ๊ณ ํฉ๋๋ค. ํ ํฐ ๋ถ๋ฅ๋ ๊ฐ ํ ํฐ์ ๋ฏธ๋ฆฌ ์ ์๋ ํด๋์ค ์งํฉ์ ๋ ์ด๋ธ์ ํ ๋นํฉ๋๋ค. | |
| ํ ํฐ ๋ถ๋ฅ์ ๋ ๊ฐ์ง ์ผ๋ฐ์ ์ธ ์ ํ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค: | |
| * ๊ฐ์ฒด๋ช ์ธ์ (NER): ํ ํฐ์ ์กฐ์ง, ์ธ๋ฌผ, ์์น ๋๋ ๋ ์ง์ ๊ฐ์ ๊ฐ์ฒด ๋ฒ์ฃผ์ ๋ฐ๋ผ ๋ ์ด๋ธ๋งํฉ๋๋ค. NER์ ํนํ ์ ์ ์ฒดํ์ ์ธ ํ๊ฒฝ์์ ์ ์ ์, ๋จ๋ฐฑ์ง ๋ฐ ์ฝ๋ฌผ ์ด๋ฆ์ ๋ ์ด๋ธ์ ์ง์ ํ๋ ๋ฐ ๋๋ฆฌ ์ฌ์ฉ๋ฉ๋๋ค. | |
| * ํ์ฌ ํ๊น (POS): ๋ช ์ฌ, ๋์ฌ, ํ์ฉ์ฌ์ ๊ฐ์ ํ์ฌ์ ๋ฐ๋ผ ํ ํฐ์ ๋ ์ด๋ธ์ ํ ๋นํฉ๋๋ค. POS๋ ๋ฒ์ญ ์์คํ ์ด ๋์ผํ ๋จ์ด๊ฐ ๋ฌธ๋ฒ์ ์ผ๋ก ์ด๋ป๊ฒ ๋ค๋ฅธ์ง ์ดํดํ๋ ๋ฐ ๋์์ด ๋ฉ๋๋ค (๋ช ์ฌ๋ก ์ฌ์ฉ๋๋ "bank(์ํ)"๊ณผ ๋์ฌ๋ก ์ฌ์ฉ๋๋ "bank(์๊ธ์ ์์นํ๋ค)"๊ณผ ๊ฐ์ ๊ฒฝ์ฐ). | |
| ```py | |
| >>> from transformers import pipeline | |
| >>> classifier = pipeline(task="ner") | |
| >>> preds = classifier("Hugging Face is a French company based in New York City.") | |
| >>> preds = [ | |
| ... { | |
| ... "entity": pred["entity"], | |
| ... "score": round(pred["score"], 4), | |
| ... "index": pred["index"], | |
| ... "word": pred["word"], | |
| ... "start": pred["start"], | |
| ... "end": pred["end"], | |
| ... } | |
| ... for pred in preds | |
| ... ] | |
| >>> print(*preds, sep="\n") | |
| {'entity': 'I-ORG', 'score': 0.9968, 'index': 1, 'word': 'Hu', 'start': 0, 'end': 2} | |
| {'entity': 'I-ORG', 'score': 0.9293, 'index': 2, 'word': '##gging', 'start': 2, 'end': 7} | |
| {'entity': 'I-ORG', 'score': 0.9763, 'index': 3, 'word': 'Face', 'start': 8, 'end': 12} | |
| {'entity': 'I-MISC', 'score': 0.9983, 'index': 6, 'word': 'French', 'start': 18, 'end': 24} | |
| {'entity': 'I-LOC', 'score': 0.999, 'index': 10, 'word': 'New', 'start': 42, 'end': 45} | |
| {'entity': 'I-LOC', 'score': 0.9987, 'index': 11, 'word': 'York', 'start': 46, 'end': 50} | |
| {'entity': 'I-LOC', 'score': 0.9992, 'index': 12, 'word': 'City', 'start': 51, 'end': 55} | |
| ``` | |
| ### ์ง์์๋ต[[question_answering]] | |
| ์ง์์๋ต์ ๋ ํ๋์ ํ ํฐ ์ฐจ์์ ์์ ์ผ๋ก, ๋ฌธ๋งฅ์ด ์์ ๋(๊ฐ๋ฐฉํ ๋๋ฉ์ธ)์ ๋ฌธ๋งฅ์ด ์์ ๋(ํ์ํ ๋๋ฉ์ธ) ์ง๋ฌธ์ ๋ํ ๋ต๋ณ์ ๋ฐํํฉ๋๋ค. ์ด ์์ ์ ๊ฐ์ ๋น์์๊ฒ ์๋น์ด ์์ ์ค์ธ์ง์ ๊ฐ์ ์ง๋ฌธ์ ํ ๋๋ง๋ค ๋ฐ์ํ ์ ์์ต๋๋ค. ๊ณ ๊ฐ ์ง์ ๋๋ ๊ธฐ์ ์ง์์ ์ ๊ณตํ๊ฑฐ๋ ๊ฒ์ ์์ง์ด ์์ฒญํ ์ ๋ณด๋ฅผ ๊ฒ์ํ๋ ๋ฐ ๋์์ ์ค ์ ์์ต๋๋ค. | |
| ์ง๋ฌธ ๋ต๋ณ์๋ ์ผ๋ฐ์ ์ผ๋ก ๋ ๊ฐ์ง ์ ํ์ด ์์ต๋๋ค: | |
| * ์ถ์ถํ: ์ง๋ฌธ๊ณผ ๋ฌธ๋งฅ์ด ์ฃผ์ด์ก์ ๋, ๋ชจ๋ธ์ด ์ฃผ์ด์ง ๋ฌธ๋งฅ์ ์ผ๋ถ์์ ๊ฐ์ ธ์จ ํ ์คํธ์ ๋ฒ์๋ฅผ ๋ต๋ณ์ผ๋ก ํฉ๋๋ค. | |
| * ์์ฑํ: ์ง๋ฌธ๊ณผ ๋ฌธ๋งฅ์ด ์ฃผ์ด์ก์ ๋, ์ฃผ์ด์ง ๋ฌธ๋งฅ์ ํตํด ๋ต๋ณ์ ์์ฑํฉ๋๋ค. ์ด ์ ๊ทผ ๋ฐฉ์์ [`QuestionAnsweringPipeline`] ๋์ [`Text2TextGenerationPipeline`]์ ํตํด ์ฒ๋ฆฌ๋ฉ๋๋ค. | |
| ```py | |
| >>> from transformers import pipeline | |
| >>> question_answerer = pipeline(task="question-answering") | |
| >>> preds = question_answerer( | |
| ... question="What is the name of the repository?", | |
| ... context="The name of the repository is huggingface/transformers", | |
| ... ) | |
| >>> print( | |
| ... f"score: {round(preds['score'], 4)}, start: {preds['start']}, end: {preds['end']}, answer: {preds['answer']}" | |
| ... ) | |
| score: 0.9327, start: 30, end: 54, answer: huggingface/transformers | |
| ``` | |
| ### ์์ฝ[[summarization]] | |
| ์์ฝ์ ์๋ณธ ๋ฌธ์์ ์๋ฏธ๋ฅผ ์ต๋ํ ๋ณด์กดํ๋ฉด์ ๊ธด ๋ฌธ์๋ฅผ ์งง์ ๋ฌธ์๋ก ๋ง๋๋ ์์ ์ ๋๋ค. ์์ฝ์ `sequence-to-sequence` ์์ ์ ๋๋ค. ์ ๋ ฅ๋ณด๋ค ์งง์ ํ ์คํธ ์ํ์ค๋ฅผ ์ถ๋ ฅํฉ๋๋ค. ์์ฝ ์์ ์ ๋ ์๊ฐ ์ฅ๋ฌธ ๋ฌธ์๋ค์ ์ฃผ์ ํฌ์ธํธ๋ฅผ ๋น ๋ฅด๊ฒ ์ดํดํ๋ ๋ฐ ๋์์ ์ค ์ ์์ต๋๋ค. ์ ๋ฒ์, ๋ฒ๋ฅ ๋ฐ ๊ธ์ต ๋ฌธ์, ํนํ ๋ฐ ๊ณผํ ๋ ผ๋ฌธ์ ์์ฝ ์์ ์ด ๋ ์์ ์๊ฐ์ ์ ์ฝํ๊ณ ๋ ์ ๋ณด์กฐ ๋๊ตฌ๋ก ์ฌ์ฉ๋ ์ ์๋ ๋ช ๊ฐ์ง ์์์ ๋๋ค. | |
| ์ง๋ฌธ ๋ต๋ณ๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก ์์ฝ์๋ ๋ ๊ฐ์ง ์ ํ์ด ์์ต๋๋ค: | |
| * ์ถ์ถํ: ์๋ณธ ํ ์คํธ์์ ๊ฐ์ฅ ์ค์ํ ๋ฌธ์ฅ์ ์๋ณํ๊ณ ์ถ์ถํฉ๋๋ค. | |
| * ์์ฑํ: ์๋ณธ ํ ์คํธ์์ ๋ชฉํ ์์ฝ์ ์์ฑํฉ๋๋ค. ์ ๋ ฅ ๋ฌธ์์ ์๋ ์๋ก์ด ๋จ์ด๋ฅผ ํฌํจํ ์๋ ์์ต๋๋ค. [`SummarizationPipeline`]์ ์์ฑํ ์ ๊ทผ ๋ฐฉ์์ ์ฌ์ฉํฉ๋๋ค. | |
| ```py | |
| >>> from transformers import pipeline | |
| >>> summarizer = pipeline(task="summarization") | |
| >>> summarizer( | |
| ... "In this work, we presented the Transformer, the first sequence transduction model based entirely on attention, replacing the recurrent layers most commonly used in encoder-decoder architectures with multi-headed self-attention. For translation tasks, the Transformer can be trained significantly faster than architectures based on recurrent or convolutional layers. On both WMT 2014 English-to-German and WMT 2014 English-to-French translation tasks, we achieve a new state of the art. In the former task our best model outperforms even all previously reported ensembles." | |
| ... ) | |
| [{'summary_text': ' The Transformer is the first sequence transduction model based entirely on attention . It replaces the recurrent layers most commonly used in encoder-decoder architectures with multi-headed self-attention . For translation tasks, the Transformer can be trained significantly faster than architectures based on recurrent or convolutional layers .'}] | |
| ``` | |
| ### ๋ฒ์ญ[[translation]] | |
| ๋ฒ์ญ์ ํ ์ธ์ด๋ก ๋ ํ ์คํธ ์ํ์ค๋ฅผ ๋ค๋ฅธ ์ธ์ด๋ก ๋ณํํ๋ ์์ ์ ๋๋ค. ์ด๋ ์๋ก ๋ค๋ฅธ ๋ฐฐ๊ฒฝ์ ๊ฐ์ง ์ฌ๋๋ค์ด ์๋ก ์ํตํ๋ ๋ฐ ๋์์ ์ฃผ๋ ์ค์ํ ์ญํ ์ ํฉ๋๋ค. ๋ ๋์ ๋์ค์๊ฒ ์ฝํ ์ธ ๋ฅผ ๋ฒ์ญํ์ฌ ์ ๋ฌํ๊ฑฐ๋, ์๋ก์ด ์ธ์ด๋ฅผ ๋ฐฐ์ฐ๋ ๋ฐ ๋์์ด ๋๋ ํ์ต ๋๊ตฌ๊ฐ ๋ ์๋ ์์ต๋๋ค. ์์ฝ๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก, ๋ฒ์ญ์ `sequence-to-sequence` ์์ ์ ๋๋ค. ์ฆ, ๋ชจ๋ธ์ ์ ๋ ฅ ์ํ์ค๋ฅผ ๋ฐ์์ ์ถ๋ ฅ์ด ๋๋ ๋ชฉํ ์ํ์ค๋ฅผ ๋ฐํํฉ๋๋ค. | |
| ์ด๊ธฐ์ ๋ฒ์ญ ๋ชจ๋ธ์ ๋๋ถ๋ถ ๋จ์ผ ์ธ์ด๋ก ์ด๋ฃจ์ด์ ธ ์์์ง๋ง, ์ต๊ทผ์๋ ๋ง์ ์ธ์ด ์ ๊ฐ์ ๋ฒ์ญ์ ์ํํ ์ ์๋ ๋ค์ค ์ธ์ด ๋ชจ๋ธ์ ๋ํ ๊ด์ฌ์ด ๋์์ง๊ณ ์์ต๋๋ค. | |
| ```py | |
| >>> from transformers import pipeline | |
| >>> text = "translate English to French: Hugging Face is a community-based open-source platform for machine learning." | |
| >>> translator = pipeline(task="translation", model="t5-small") | |
| >>> translator(text) | |
| [{'translation_text': "Hugging Face est une tribune communautaire de l'apprentissage des machines."}] | |
| ``` | |
| ### ์ธ์ด ๋ชจ๋ธ๋ง[[language_modeling]] | |
| ์ธ์ด ๋ชจ๋ธ๋ง์ ํ ์คํธ ์ํ์ค์์ ๋จ์ด๋ฅผ ์์ธกํ๋ ์์ ์ ๋๋ค. ์ฌ์ ํ๋ จ๋ ์ธ์ด ๋ชจ๋ธ์ ๋ง์ ๋ค๋ฅธ ํ์ ์์ ์ ๋ฐ๋ผ ๋ฏธ์ธ ์กฐ์ ๋ ์ ์๊ธฐ ๋๋ฌธ์ ๋งค์ฐ ์ธ๊ธฐ ์๋ ์์ฐ์ด์ฒ๋ฆฌ ์์ ์ด ๋์์ต๋๋ค. ์ต๊ทผ์๋ ์ ๋ก ์ท(zero-shot) ๋๋ ํจ ์ท(few-shot) ํ์ต์ด ๊ฐ๋ฅํ ๋๊ท๋ชจ ์ธ์ด ๋ชจ๋ธ(Large Language Models, LLM)์ ๋ํ ๋ง์ ๊ด์ฌ์ด ๋ฐ์ํ๊ณ ์์ต๋๋ค. ์ด๋ ๋ชจ๋ธ์ด ๋ช ์์ ์ผ๋ก ํ๋ จ๋์ง ์์ ์์ ๋ ํด๊ฒฐํ ์ ์๋ค๋ ๊ฒ์ ์๋ฏธํฉ๋๋ค! ์ธ์ด ๋ชจ๋ธ์ ์ ์ฐฝํ๊ณ ์ค๋๋ ฅ ์๋ ํ ์คํธ๋ฅผ ์์ฑํ๋ ๋ฐ ์ฌ์ฉ๋ ์ ์์ง๋ง, ํ ์คํธ๊ฐ ํญ์ ์ ํํ์ง๋ ์์ ์ ์์ผ๋ฏ๋ก ์ฃผ์๊ฐ ํ์ํฉ๋๋ค. | |
| ์ธ์ด ๋ชจ๋ธ๋ง์๋ ๋ ๊ฐ์ง ์ ํ์ด ์์ต๋๋ค: | |
| * ์ธ๊ณผ์ ์ธ์ด ๋ชจ๋ธ๋ง: ์ด ๋ชจ๋ธ์ ๋ชฉ์ ์ ์ํ์ค์์ ๋ค์ ํ ํฐ์ ์์ธกํ๋ ๊ฒ์ด๋ฉฐ, ๋ฏธ๋ ํ ํฐ์ด ๋ง์คํน ๋ฉ๋๋ค. | |
| ```py | |
| >>> from transformers import pipeline | |
| >>> prompt = "Hugging Face is a community-based open-source platform for machine learning." | |
| >>> generator = pipeline(task="text-generation") | |
| >>> generator(prompt) # doctest: +SKIP | |
| ``` | |
| * ๋ง์คํน๋ ์ธ์ด ๋ชจ๋ธ๋ง: ์ด ๋ชจ๋ธ์ ๋ชฉ์ ์ ์ํ์ค ๋ด์ ๋ง์คํน๋ ํ ํฐ์ ์์ธกํ๋ ๊ฒ์ด๋ฉฐ, ์ํ์ค ๋ด์ ๋ชจ๋ ํ ํฐ์ ๋ํ ์ ๊ทผ์ด ์ ๊ณต๋ฉ๋๋ค. | |
| ```py | |
| >>> text = "Hugging Face is a community-based open-source <mask> for machine learning." | |
| >>> fill_mask = pipeline(task="fill-mask") | |
| >>> preds = fill_mask(text, top_k=1) | |
| >>> preds = [ | |
| ... { | |
| ... "score": round(pred["score"], 4), | |
| ... "token": pred["token"], | |
| ... "token_str": pred["token_str"], | |
| ... "sequence": pred["sequence"], | |
| ... } | |
| ... for pred in preds | |
| ... ] | |
| >>> preds | |
| [{'score': 0.2236, | |
| 'token': 1761, | |
| 'token_str': ' platform', | |
| 'sequence': 'Hugging Face is a community-based open-source platform for machine learning.'}] | |
| ``` | |
| ์ด ํ์ด์ง๋ฅผ ํตํด ๊ฐ ๋ชจ๋ฌ๋ฆฌํฐ์ ๋ค์ํ ์์ ์ ํ๊ณผ ๊ฐ ์์ ์ ์ค์ฉ์ ์ค์์ฑ์ ๋ํด ์ถ๊ฐ์ ์ธ ๋ฐฐ๊ฒฝ ์ ๋ณด๋ฅผ ์ป์ผ์ จ๊ธฐ๋ฅผ ๋ฐ๋๋๋ค. ๋ค์ [์น์ ](tasks_explained)์์๋ ๐ค Transformer๊ฐ ์ด๋ฌํ ์์ ์ ํด๊ฒฐํ๋ **๋ฐฉ๋ฒ**์ ๋ํด ์์๋ณด์ค ์ ์์ต๋๋ค. |