@@ -20,8 +20,8 @@ specific language governing permissions and limitations under the License.
2020
2121์ด ๊ฐ์ด๋์์ ํ์ตํ ๋ด์ฉ์:
2222
23- 1 . [ IMDb] ( https://huggingface.co/datasets/imdb ) ๋ฐ์ดํฐ์
์์ [ DistilBERT] ( https://huggingface.co/distilbert-base-uncased ) ๋ฅผ ๋ฏธ์ธ ์กฐ์ ํ์ฌ ์ํ ๋ฆฌ๋ทฐ๊ฐ ๊ธ์ ์ ์ธ์ง ๋ถ์ ์ ์ธ์ง ํ๋จํฉ๋๋ค.
24- 2 . ์ถ๋ก ์ ์ํด ๋ฏธ์ธ ์กฐ์ ๋ชจ๋ธ์ ์ฌ์ฉํฉ๋๋ค.
23+ 1 . [ IMDb] ( https://huggingface.co/datasets/imdb ) ๋ฐ์ดํฐ์
์์ [ DistilBERT] ( https://huggingface.co/distilbert-base-uncased ) ๋ฅผ ํ์ธ ํ๋ํ์ฌ ์ํ ๋ฆฌ๋ทฐ๊ฐ ๊ธ์ ์ ์ธ์ง ๋ถ์ ์ ์ธ์ง ํ๋จํฉ๋๋ค.
24+ 2 . ์ถ๋ก ์ ์ํด ํ์ธ ํ๋ ๋ชจ๋ธ์ ์ฌ์ฉํฉ๋๋ค.
2525
2626<Tip >
2727์ด ํํ ๋ฆฌ์ผ์์ ์ค๋ช
ํ๋ ์์
์ ๋ค์ ๋ชจ๋ธ ์ํคํ
์ฒ์ ์ํด ์ง์๋ฉ๋๋ค:
@@ -118,7 +118,7 @@ tokenized_imdb = imdb.map(preprocess_function, batched=True)
118118
119119## ํ๊ฐํ๊ธฐ[[ evaluate]]
120120
121- ํ์ต ์ค ๋ชจ๋ธ์ ์ฑ๋ฅ์ ํ๊ฐํ๊ธฐ ์ํด ๋ฉํธ๋ฆญ์ ํฌํจํ๋ ๊ฒ์ด ์ ์ฉํฉ๋๋ค. ๐ค [ Evaluate] ( https://huggingface.co/docs/evaluate/index ) ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ์ฌ ๋น ๋ฅด๊ฒ ํ๊ฐ ๋ฐฉ๋ฒ์ ๋ก๋ํ ์ ์์ต๋๋ค. ์ด ์์
์์๋ [ accuracy] ( https://huggingface.co/spaces/evaluate-metric/accuracy ) ๋ฉํธ๋ฆญ์ ๊ฐ์ ธ์ต๋๋ค. (๋ฉํธ๋ฆญ์ ๊ฐ์ ธ์ค๊ณ ๊ณ์ฐํ๋ ๋ฐฉ๋ฒ์ ๋ํด์๋ ๐ค Evaluate [ quick tour] ( https://huggingface.co/docs/evaluate/a_quick_tour ) ๋ฅผ ์ฐธ์กฐํ์ธ์):
121+ ํ๋ จ ์ค ๋ชจ๋ธ์ ์ฑ๋ฅ์ ํ๊ฐํ๊ธฐ ์ํด ๋ฉํธ๋ฆญ์ ํฌํจํ๋ ๊ฒ์ด ์ ์ฉํฉ๋๋ค. ๐ค [ Evaluate] ( https://huggingface.co/docs/evaluate/index ) ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ์ฌ ๋น ๋ฅด๊ฒ ํ๊ฐ ๋ฐฉ๋ฒ์ ๋ก๋ํ ์ ์์ต๋๋ค. ์ด ์์
์์๋ [ accuracy] ( https://huggingface.co/spaces/evaluate-metric/accuracy ) ๋ฉํธ๋ฆญ์ ๊ฐ์ ธ์ต๋๋ค. (๋ฉํธ๋ฆญ์ ๊ฐ์ ธ์ค๊ณ ๊ณ์ฐํ๋ ๋ฐฉ๋ฒ์ ๋ํด์๋ ๐ค Evaluate [ quick tour] ( https://huggingface.co/docs/evaluate/a_quick_tour ) ๋ฅผ ์ฐธ์กฐํ์ธ์):
122122
123123``` py
124124>> > import evaluate
@@ -140,9 +140,9 @@ tokenized_imdb = imdb.map(preprocess_function, batched=True)
140140
141141์ด์ ` compute_metrics ` ํจ์๋ ์ค๋น๋์๊ณ , ํ๋ จ ๊ณผ์ ์ ์ค์ ํ ๋ ๋ค์ ์ดํด๋ณผ ์์ ์
๋๋ค.
142142
143- ## ํ์ต [[ train]]
143+ ## ํ๋ จ [[ train]]
144144
145- ๋ชจ๋ธ์ ํ์ตํ๊ธฐ ์ ์, ` id2label ` ์ ` label2id ` ๋ฅผ ์ฌ์ฉํ์ฌ ์์๋๋ id์ ๋ ์ด๋ธ์ ๋งต์ ์์ฑํ์ธ์:
145+ ๋ชจ๋ธ์ ํ๋ จํ๊ธฐ ์ ์, ` id2label ` ์ ` label2id ` ๋ฅผ ์ฌ์ฉํ์ฌ ์์๋๋ id์ ๋ ์ด๋ธ์ ๋งต์ ์์ฑํ์ธ์:
146146
147147``` py
148148>> > id2label = {0 : " NEGATIVE" , 1 : " POSITIVE" }
@@ -153,11 +153,11 @@ tokenized_imdb = imdb.map(preprocess_function, batched=True)
153153<pt >
154154<Tip >
155155
156- [ ` Trainer ` ] ๋ฅผ ์ฌ์ฉํ์ฌ ๋ชจ๋ธ์ ๋ฏธ์ธ ์กฐ์ ํ๋ ๋ฐฉ๋ฒ์ ์ต์ํ์ง ์์ ๊ฒฝ์ฐ, [ ์ฌ๊ธฐ] ( ../training#train-with-pytorch-trainer ) ์ ๊ธฐ๋ณธ ํํ ๋ฆฌ์ผ์ ํ์ธํ์ธ์!
156+ [ ` Trainer ` ] ๋ฅผ ์ฌ์ฉํ์ฌ ๋ชจ๋ธ์ ํ์ธ ํ๋ํ๋ ๋ฐฉ๋ฒ์ ์ต์ํ์ง ์์ ๊ฒฝ์ฐ, [ ์ฌ๊ธฐ] ( ../training#train-with-pytorch-trainer ) ์ ๊ธฐ๋ณธ ํํ ๋ฆฌ์ผ์ ํ์ธํ์ธ์!
157157
158158</Tip >
159159
160- ์ด์ ๋ชจ๋ธ์ ํ์ต์ํฌ ์ค๋น๊ฐ ๋์์ต๋๋ค! [ ` AutoModelForSequenceClassification ` ] ๋ก DistilBERT๋ฅผ ๊ฐ์ณ์ค๊ณ ์์๋๋ ๋ ์ด๋ธ ์์ ๋ ์ด๋ธ ๋งคํ์ ์ง์ ํ์ธ์:
160+ ์ด์ ๋ชจ๋ธ์ ํ๋ จ์ํฌ ์ค๋น๊ฐ ๋์์ต๋๋ค! [ ` AutoModelForSequenceClassification ` ] ๋ก DistilBERT๋ฅผ ๊ฐ์ณ์ค๊ณ ์์๋๋ ๋ ์ด๋ธ ์์ ๋ ์ด๋ธ ๋งคํ์ ์ง์ ํ์ธ์:
161161
162162``` py
163163>> > from transformers import AutoModelForSequenceClassification, TrainingArguments, Trainer
@@ -169,9 +169,9 @@ tokenized_imdb = imdb.map(preprocess_function, batched=True)
169169
170170์ด์ ์ธ ๋จ๊ณ๋ง ๊ฑฐ์น๋ฉด ๋์
๋๋ค:
171171
172- 1 . [ ` TrainingArguments ` ] ์์ ํ์ดํผํ๋ผ๋ฏธํฐ๋ฅผ ์ ์ํ์ธ์. ` output_dir ` ๋ ๋ชจ๋ธ์ ์ ์ฅํ ์์น๋ฅผ ์ง์ ํ๋ ์ ์ผํ ํ๋ผ๋ฏธํฐ์
๋๋ค. ์ด ๋ชจ๋ธ์ Hub์ ์
๋ก๋ํ๊ธฐ ์ํด ` push_to_hub=True ` ๋ฅผ ์ค์ ํฉ๋๋ค. (๋ชจ๋ธ์ ์
๋ก๋ํ๊ธฐ ์ํด Hugging Face์ ๋ก๊ทธ์ธํด์ผํฉ๋๋ค.) ๊ฐ ์ํญ์ด ๋๋ ๋๋ง๋ค, [ ` Trainer ` ] ๋ ์ ํ๋๋ฅผ ํ๊ฐํ๊ณ ํ์ต ์ฒดํฌํฌ์ธํธ๋ฅผ ์ ์ฅํฉ๋๋ค.
173- 2 . [ ` Trainer ` ] ์ ํ์ต ์ธ์์ ๋ชจ๋ธ, ๋ฐ์ดํฐ์
, ํ ํฌ๋์ด์ , ๋ฐ์ดํฐ ์์ง๊ธฐ ๋ฐ ` compute_metrics ` ํจ์๋ฅผ ์ ๋ฌํ์ธ์.
174- 3 . [ ` ~Trainer.train ` ] ๋ฅผ ํธ์ถํ์ฌ ๋ชจ๋ธ์ ๋ฏธ์ธ ์กฐ์ ํ์ธ์ .
172+ 1 . [ ` TrainingArguments ` ] ์์ ํ์ดํผํ๋ผ๋ฏธํฐ๋ฅผ ์ ์ํ์ธ์. ` output_dir ` ๋ ๋ชจ๋ธ์ ์ ์ฅํ ์์น๋ฅผ ์ง์ ํ๋ ์ ์ผํ ํ๋ผ๋ฏธํฐ์
๋๋ค. ์ด ๋ชจ๋ธ์ Hub์ ์
๋ก๋ํ๊ธฐ ์ํด ` push_to_hub=True ` ๋ฅผ ์ค์ ํฉ๋๋ค. (๋ชจ๋ธ์ ์
๋ก๋ํ๊ธฐ ์ํด Hugging Face์ ๋ก๊ทธ์ธํด์ผํฉ๋๋ค.) ๊ฐ ์ํญ์ด ๋๋ ๋๋ง๋ค, [ ` Trainer ` ] ๋ ์ ํ๋๋ฅผ ํ๊ฐํ๊ณ ํ๋ จ ์ฒดํฌํฌ์ธํธ๋ฅผ ์ ์ฅํฉ๋๋ค.
173+ 2 . [ ` Trainer ` ] ์ ํ๋ จ ์ธ์์ ๋ชจ๋ธ, ๋ฐ์ดํฐ์
, ํ ํฌ๋์ด์ , ๋ฐ์ดํฐ ์์ง๊ธฐ ๋ฐ ` compute_metrics ` ํจ์๋ฅผ ์ ๋ฌํ์ธ์.
174+ 3 . [ ` ~Trainer.train ` ] ๋ฅผ ํธ์ถํ์ฌ ๋ชจ๋ธ์ ํ์ธ ํ๋ํ์ธ์ .
175175
176176``` py
177177>> > training_args = TrainingArguments(
@@ -206,7 +206,7 @@ tokenized_imdb = imdb.map(preprocess_function, batched=True)
206206
207207</Tip >
208208
209- ํ์ต์ด ์๋ฃ๋๋ฉด, [ ` ~transformers.Trainer.push_to_hub ` ] ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ ๋ชจ๋ธ์ Hub์ ๊ณต์ ํ ์ ์์ต๋๋ค.
209+ ํ๋ จ์ด ์๋ฃ๋๋ฉด, [ ` ~transformers.Trainer.push_to_hub ` ] ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ ๋ชจ๋ธ์ Hub์ ๊ณต์ ํ ์ ์์ต๋๋ค.
210210
211211``` py
212212>> > trainer.push_to_hub()
@@ -215,10 +215,10 @@ tokenized_imdb = imdb.map(preprocess_function, batched=True)
215215<tf >
216216<Tip >
217217
218- Keras๋ฅผ ์ฌ์ฉํ์ฌ ๋ชจ๋ธ์ ๋ฏธ์ธ ์กฐ์ ํ๋ ๋ฐฉ๋ฒ์ ์ต์ํ์ง ์์ ๊ฒฝ์ฐ, [ ์ฌ๊ธฐ] ( ../training#train-a-tensorflow-model-with-keras ) ์ ๊ธฐ๋ณธ ํํ ๋ฆฌ์ผ์ ํ์ธํ์ธ์!
218+ Keras๋ฅผ ์ฌ์ฉํ์ฌ ๋ชจ๋ธ์ ํ์ธ ํ๋ํ๋ ๋ฐฉ๋ฒ์ ์ต์ํ์ง ์์ ๊ฒฝ์ฐ, [ ์ฌ๊ธฐ] ( ../training#train-a-tensorflow-model-with-keras ) ์ ๊ธฐ๋ณธ ํํ ๋ฆฌ์ผ์ ํ์ธํ์ธ์!
219219
220220</Tip >
221- TensorFlow์์ ๋ชจ๋ธ์ ๋ฏธ์ธ ์กฐ์ ํ๋ ค๋ฉด , ๋จผ์ ์ตํฐ๋ง์ด์ ํจ์์ ํ์ต๋ฅ ์ค์ผ์ฅด, ๊ทธ๋ฆฌ๊ณ ์ผ๋ถ ํ์ต ํ์ดํผํ๋ผ๋ฏธํฐ๋ฅผ ์ค์ ํด์ผ ํฉ๋๋ค:
221+ TensorFlow์์ ๋ชจ๋ธ์ ํ์ธ ํ๋ํ๋ ค๋ฉด , ๋จผ์ ์ตํฐ๋ง์ด์ ํจ์์ ํ์ต๋ฅ ์ค์ผ์ฅด, ๊ทธ๋ฆฌ๊ณ ์ผ๋ถ ํ๋ จ ํ์ดํผํ๋ผ๋ฏธํฐ๋ฅผ ์ค์ ํด์ผ ํฉ๋๋ค:
222222
223223``` py
224224>> > from transformers import create_optimizer
@@ -259,15 +259,15 @@ TensorFlow์์ ๋ชจ๋ธ์ ๋ฏธ์ธ ์กฐ์ ํ๋ ค๋ฉด, ๋จผ์ ์ตํฐ๋ง์ด์ ํจ์
259259... )
260260```
261261
262- [ ` compile ` ] ( https://keras.io/api/models/model_training_apis/#compile-method ) ๋ฅผ ์ฌ์ฉํ์ฌ ํ์ตํ ๋ชจ๋ธ์ ๊ตฌ์ฑํฉ๋๋ค:
262+ [ ` compile ` ] ( https://keras.io/api/models/model_training_apis/#compile-method ) ๋ฅผ ์ฌ์ฉํ์ฌ ํ๋ จํ ๋ชจ๋ธ์ ๊ตฌ์ฑํฉ๋๋ค:
263263
264264``` py
265265>> > import tensorflow as tf
266266
267267>> > model.compile(optimizer = optimizer)
268268```
269269
270- ํ์ต์ ์์ํ๊ธฐ ์ ์ ์ค์ ํด์ผํ ๋ง์ง๋ง ๋ ๊ฐ์ง๋ ์์ธก์์ ์ ํ๋๋ฅผ ๊ณ์ฐํ๊ณ , ๋ชจ๋ธ์ Hub์ ์
๋ก๋ํ ๋ฐฉ๋ฒ์ ์ ๊ณตํ๋ ๊ฒ์
๋๋ค. ๋ชจ๋ [ Keras callbacks] ( ../main_classes/keras_callbacks ) ๋ฅผ ์ฌ์ฉํ์ฌ ์ํ๋ฉ๋๋ค.
270+ ํ๋ จ์ ์์ํ๊ธฐ ์ ์ ์ค์ ํด์ผํ ๋ง์ง๋ง ๋ ๊ฐ์ง๋ ์์ธก์์ ์ ํ๋๋ฅผ ๊ณ์ฐํ๊ณ , ๋ชจ๋ธ์ Hub์ ์
๋ก๋ํ ๋ฐฉ๋ฒ์ ์ ๊ณตํ๋ ๊ฒ์
๋๋ค. ๋ชจ๋ [ Keras callbacks] ( ../main_classes/keras_callbacks ) ๋ฅผ ์ฌ์ฉํ์ฌ ์ํ๋ฉ๋๋ค.
271271
272272[ ` ~transformers.KerasMetricCallback ` ] ์ ` compute_metrics ` ๋ฅผ ์ ๋ฌํ์ฌ ์ ํ๋๋ฅผ ๋์
๋๋ค.
273273
@@ -294,33 +294,33 @@ TensorFlow์์ ๋ชจ๋ธ์ ๋ฏธ์ธ ์กฐ์ ํ๋ ค๋ฉด, ๋จผ์ ์ตํฐ๋ง์ด์ ํจ์
294294>> > callbacks = [metric_callback, push_to_hub_callback]
295295```
296296
297- ๋๋์ด, ๋ชจ๋ธ ํ์ต์ ์์ํ ์ค๋น๊ฐ ๋์์ต๋๋ค! [ ` fit ` ] ( https://keras.io/api/models/model_training_apis/#fit-method ) ์ ํ์ต ๋ฐ์ดํฐ์
, ๊ฒ์ฆ ๋ฐ์ดํฐ์
, ์ํญ์ ์ ๋ฐ ์ฝ๋ฐฑ์ ์ ๋ฌํ์ฌ ๋ฏธ์ธ ์กฐ์ ํฉ๋๋ค :
297+ ๋๋์ด, ๋ชจ๋ธ ํ๋ จ์ ์์ํ ์ค๋น๊ฐ ๋์์ต๋๋ค! [ ` fit ` ] ( https://keras.io/api/models/model_training_apis/#fit-method ) ์ ํ๋ จ ๋ฐ์ดํฐ์
, ๊ฒ์ฆ ๋ฐ์ดํฐ์
, ์ํญ์ ์ ๋ฐ ์ฝ๋ฐฑ์ ์ ๋ฌํ์ฌ ํ์ธ ํ๋ํฉ๋๋ค :
298298
299299``` py
300300>> > model.fit(x = tf_train_set, validation_data = tf_validation_set, epochs = 3 , callbacks = callbacks)
301301```
302302
303- ํ์ต์ด ์๋ฃ๋๋ฉด, ๋ชจ๋ธ์ด ์๋์ผ๋ก Hub์ ์
๋ก๋๋์ด ๋ชจ๋ ์ฌ๋์ด ์ฌ์ฉํ ์ ์์ต๋๋ค!
303+ ํ๋ จ์ด ์๋ฃ๋๋ฉด, ๋ชจ๋ธ์ด ์๋์ผ๋ก Hub์ ์
๋ก๋๋์ด ๋ชจ๋ ์ฌ๋์ด ์ฌ์ฉํ ์ ์์ต๋๋ค!
304304</tf >
305305</frameworkcontent >
306306
307307<Tip >
308308
309- ํ
์คํธ ๋ถ๋ฅ๋ฅผ ์ํ ๋ชจ๋ธ์ ๋ฏธ์ธ ์กฐ์ ํ๋ ์์ธํ ์์ ๋ ๋ค์ [ PyTorch notebook] ( https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/text_classification.ipynb ) ๋๋ [ TensorFlow notebook] ( https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/text_classification-tf.ipynb ) ๋ฅผ ์ฐธ์กฐํ์ธ์.
309+ ํ
์คํธ ๋ถ๋ฅ๋ฅผ ์ํ ๋ชจ๋ธ์ ํ์ธ ํ๋ํ๋ ์์ธํ ์์ ๋ ๋ค์ [ PyTorch notebook] ( https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/text_classification.ipynb ) ๋๋ [ TensorFlow notebook] ( https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/text_classification-tf.ipynb ) ๋ฅผ ์ฐธ์กฐํ์ธ์.
310310
311311</Tip >
312312
313313## ์ถ๋ก [[ inference]]
314314
315- ์ข์์, ์ด์ ๋ชจ๋ธ์ ๋ฏธ์ธ ์กฐ์ ํ์ผ๋ ์ถ๋ก ์ ์ฌ์ฉํ ์ ์์ต๋๋ค!
315+ ์ข์์, ์ด์ ๋ชจ๋ธ์ ํ์ธ ํ๋ํ์ผ๋ ์ถ๋ก ์ ์ฌ์ฉํ ์ ์์ต๋๋ค!
316316
317317์ถ๋ก ์ ์ํํ๊ณ ์ ํ๋ ํ
์คํธ๋ฅผ ๊ฐ์ ธ์๋ด
์๋ค:
318318
319319``` py
320320>> > text = " This was a masterpiece. Not completely faithful to the books, but enthralling from beginning to end. Might be my favorite of the three."
321321```
322322
323- ๋ฏธ์ธ ์กฐ์ ๋ ๋ชจ๋ธ๋ก ์ถ๋ก ์ ์๋ํ๋ ๊ฐ์ฅ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ [ ` pipeline ` ] ๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์
๋๋ค. ๋ชจ๋ธ๋ก ๊ฐ์ ๋ถ์์ ์ํ ` pipeline ` ์ ์ธ์คํด์คํํ๊ณ , ํ
์คํธ๋ฅผ ์ ๋ฌํด๋ณด์ธ์:
323+ ํ์ธ ํ๋๋ ๋ชจ๋ธ๋ก ์ถ๋ก ์ ์๋ํ๋ ๊ฐ์ฅ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ [ ` pipeline ` ] ๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์
๋๋ค. ๋ชจ๋ธ๋ก ๊ฐ์ ๋ถ์์ ์ํ ` pipeline ` ์ ์ธ์คํด์คํํ๊ณ , ํ
์คํธ๋ฅผ ์ ๋ฌํด๋ณด์ธ์:
324324
325325``` py
326326>> > from transformers import pipeline
0 commit comments