Skip to content

Latest commit

ย 

History

History
314 lines (238 loc) ยท 24.8 KB

README_ko.md

File metadata and controls

314 lines (238 loc) ยท 24.8 KB

Hugging Face Transformers Library

Build GitHub Documentation GitHub release Contributor Covenant DOI

Jax, Pytorch, TensorFlow๋ฅผ ์œ„ํ•œ ์ตœ์ฒจ๋‹จ ๋จธ์‹ ๋Ÿฌ๋‹

๐Ÿค— Transformers๋Š” ํ…์ŠคํŠธ, ๋น„์ „, ์˜ค๋””์˜ค์™€ ๊ฐ™์€ ๋‹ค์–‘ํ•œ ๋ถ„์•ผ์—์„œ ์—ฌ๋Ÿฌ ๊ณผ์ œ๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” ์ˆ˜์ฒœ ๊ฐœ์˜ ์‚ฌ์ „ ํ•™์Šต๋œ ๋ชจ๋ธ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

์ œ๊ณต๋˜๋Š” ๋ชจ๋ธ์„ ํ†ตํ•ด ๋‹ค์Œ ๊ณผ์ œ๋ฅผ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ๐Ÿ“ ํ…์ŠคํŠธ: 100๊ฐœ ์ด์ƒ์˜ ์–ธ์–ด๋“ค๋กœ, ํ…์ŠคํŠธ ๋ถ„๋ฅ˜, ์ •๋ณด ์ถ”์ถœ, ์งˆ๋ฌธ ๋‹ต๋ณ€, ์š”์•ฝ, ๋ฒˆ์—ญ ๋ฐ ๋ฌธ์žฅ ์ƒ์„ฑ
  • ๐Ÿ–ผ๏ธ ์ด๋ฏธ์ง€: ์ด๋ฏธ์ง€ ๋ถ„๋ฅ˜(Image Classification), ๊ฐ์ฒด ํƒ์ง€(Object Detection) ๋ฐ ๋ถ„ํ• (Segmentation)
  • ๐Ÿ—ฃ๏ธ ์˜ค๋””์˜ค: ์Œ์„ฑ ์ธ์‹(Speech Recognition) ๋ฐ ์˜ค๋””์˜ค ๋ถ„๋ฅ˜(Audio Classification)

Transformer์˜ ๋ชจ๋ธ์€ ํ‘œ๋ฅผ ํ†ตํ•œ ์งˆ์˜์‘๋‹ต(Table QA), ๊ด‘ํ•™ ๋ฌธ์ž ์ธ์‹(Optical Character Recognition), ์Šค์บ” ํ•œ ๋ฌธ์„œ์—์„œ ์ •๋ณด ์ถ”์ถœ, ๋น„๋””์˜ค ๋ถ„๋ฅ˜ ๋ฐ ์‹œ๊ฐ์  ์งˆ์˜์‘๋‹ต๊ณผ ๊ฐ™์€ ์—ฌ๋Ÿฌ ๋ถ„์•ผ๊ฐ€ ๊ฒฐํ•ฉ๋œ ๊ณผ์ œ ๋˜ํ•œ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๐Ÿค— Transformers๋Š” ์ด๋Ÿฌํ•œ ์‚ฌ์ „ํ•™์Šต ๋ชจ๋ธ์„ ๋น ๋ฅด๊ฒŒ ๋‹ค์šด๋กœ๋“œํ•ด ํŠน์ • ํ…์ŠคํŠธ์— ์‚ฌ์šฉํ•˜๊ณ , ์›ํ•˜๋Š” ๋ฐ์ดํ„ฐ๋กœ fine-tuningํ•ด ์ปค๋ฎค๋‹ˆํ‹ฐ๋‚˜ ์šฐ๋ฆฌ์˜ ๋ชจ๋ธ ํ—ˆ๋ธŒ์— ๊ณต์œ ํ•  ์ˆ˜ ์žˆ๋„๋ก API๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ, ๋ชจ๋ธ ๊ตฌ์กฐ๋ฅผ ์ •์˜ํ•˜๋Š” ๊ฐ ํŒŒ์ด์ฌ ๋ชจ๋“ˆ์€ ์™„์ „ํžˆ ๋…๋ฆฝ์ ์ด์—ฌ์„œ ์—ฐ๊ตฌ ์‹คํ—˜์„ ์œ„ํ•ด ์†์‰ฝ๊ฒŒ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๐Ÿค— Transformers๋Š” ๊ฐ€์žฅ ์œ ๋ช…ํ•œ 3๊ฐœ์˜ ๋”ฅ๋Ÿฌ๋‹ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. ์ด๋“ค์€ ์„œ๋กœ ์™„๋ฒฝํžˆ ์—ฐ๋™๋ฉ๋‹ˆ๋‹ค โ€” Jax, PyTorch, TensorFlow. ๊ฐ„๋‹จํ•˜๊ฒŒ ์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ค‘ ํ•˜๋‚˜๋กœ ๋ชจ๋ธ์„ ํ•™์Šตํ•˜๊ณ , ๋˜ ๋‹ค๋ฅธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ์ถ”๋ก ์„ ์œ„ํ•ด ๋ชจ๋ธ์„ ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜จ๋ผ์ธ ๋ฐ๋ชจ

๋Œ€๋ถ€๋ถ„์˜ ๋ชจ๋ธ์„ ๋ชจ๋ธ ํ—ˆ๋ธŒ ํŽ˜์ด์ง€์—์„œ ๋ฐ”๋กœ ํ…Œ์ŠคํŠธํ•ด ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ณต๊ฐœ ๋ฐ ๋น„๊ณต๊ฐœ ๋ชจ๋ธ์„ ์œ„ํ•œ ๋น„๊ณต๊ฐœ ๋ชจ๋ธ ํ˜ธ์ŠคํŒ…, ๋ฒ„์ „ ๊ด€๋ฆฌ, ์ถ”๋ก  API๋„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

์•„๋ž˜ ๋ช‡ ๊ฐ€์ง€ ์˜ˆ์‹œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค:

์ž์—ฐ์–ด ์ฒ˜๋ฆฌ:

์ปดํ“จํ„ฐ ๋น„์ „:

์˜ค๋””์˜ค:

๋ฉ€ํ‹ฐ ๋ชจ๋‹ฌ(Multimodal Task):

Transformer์™€ ๊ธ€์“ฐ๊ธฐ ๋Š” ์ด ์ €์žฅ์†Œ์˜ ํ…์ŠคํŠธ ์ƒ์„ฑ ๋Šฅ๋ ฅ์— ๊ด€ํ•œ Hugging Face ํŒ€์˜ ๊ณต์‹ ๋ฐ๋ชจ์ž…๋‹ˆ๋‹ค.

Transformers๋ฅผ ์‚ฌ์šฉํ•œ 100๊ฐœ์˜ ํ”„๋กœ์ ํŠธ

Transformers๋Š” ์‚ฌ์ „ ํ•™์Šต๋œ ๋ชจ๋ธ๋“ค์„ ์ด์šฉํ•˜๋Š” ๋„๊ตฌ๋ฅผ ๋„˜์–ด Transformers์™€ ํ•จ๊ป˜ ๋นŒ๋“œ ๋œ ํ”„๋กœ์ ํŠธ ๋ฐ Hugging Face Hub๋ฅผ ์œ„ํ•œ ํ•˜๋‚˜์˜ ์ปค๋ฎค๋‹ˆํ‹ฐ์ž…๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๋Š” Transformers๋ฅผ ํ†ตํ•ด ๊ฐœ๋ฐœ์ž, ์—ฐ๊ตฌ์ž, ํ•™์ƒ, ๊ต์ˆ˜, ์—”์ง€๋‹ˆ์–ด ๋ฐ ๋ชจ๋“  ์ด๋“ค์ด ๊ฟˆ์„ ํ’ˆ์€ ํ”„๋กœ์ ํŠธ(Dream Project)๋ฅผ ๋นŒ๋“œ ํ•  ์ˆ˜ ์žˆ๊ธธ ๋ฐ”๋ž๋‹ˆ๋‹ค.

Transformers์— ๋‹ฌ๋ฆฐ 100,000๊ฐœ์˜ ๋ณ„์„ ์ถ•ํ•˜ํ•˜๊ธฐ ์œ„ํ•ด, ์šฐ๋ฆฌ๋Š” ์ปค๋ฎค๋‹ˆํ‹ฐ๋ฅผ ์ฃผ๋ชฉํ•˜๊ณ ์ž Transformers๋ฅผ ํ’ˆ๊ณ  ๋นŒ๋“œ ๋œ 100๊ฐœ์˜ ์–ด๋งˆ์–ด๋งˆํ•œ ํ”„๋กœ์ ํŠธ๋“ค์„ ์„ ๋ณ„ํ•˜์—ฌ awesome-transformers ํŽ˜์ด์ง€์— ๋‚˜์—ดํ•˜์˜€์Šต๋‹ˆ๋‹ค.

๋งŒ์ผ ์†Œ์œ ํ•œ ํ˜น์€ ์‚ฌ์šฉํ•˜๊ณ  ๊ณ„์‹  ํ”„๋กœ์ ํŠธ๊ฐ€ ์ด ๋ฆฌ์ŠคํŠธ์— ๊ผญ ๋“ฑ์žฌ๋˜์–ด์•ผ ํ•œ๋‹ค๊ณ  ๋ฏฟ์œผ์‹ ๋‹ค๋ฉด, PR์„ ์—ด๊ณ  ์ถ”๊ฐ€ํ•˜์—ฌ ์ฃผ์„ธ์š”!

์กฐ์ง ์•ˆ์—์„œ AI ์‚ฌ์šฉ์— ๋Œ€ํ•ด ์ง„์ง€ํ•˜๊ฒŒ ๊ณ ๋ฏผ ์ค‘์ด์‹ ๊ฐ€์š”? Hugging Face Enterprise Hub์„ ํ†ตํ•ด ๋” ๋นจ๋ฆฌ ๊ตฌ์ถ•ํ•ด ๋ณด์„ธ์š”.

Hugging Face Enterprise Hub

ํ€ต ํˆฌ์–ด

์ฃผ์–ด์ง„ ์ž…๋ ฅ(ํ…์ŠคํŠธ, ์ด๋ฏธ์ง€, ์˜ค๋””์˜ค, ...)์— ๋ฐ”๋กœ ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก, ์šฐ๋ฆฌ๋Š” pipeline API๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. Pipeline์€ ์‚ฌ์ „ํ•™์Šต ๋ชจ๋ธ๊ณผ ๊ทธ ๋ชจ๋ธ์„ ํ•™์Šตํ•  ๋•Œ ์ ์šฉํ•œ ์ „์ฒ˜๋ฆฌ ๋ฐฉ์‹์„ ํ•˜๋‚˜๋กœ ํ•ฉ์นฉ๋‹ˆ๋‹ค. ๋‹ค์Œ์€ ๊ธ์ •์ ์ธ ํ…์ŠคํŠธ์™€ ๋ถ€์ •์ ์ธ ํ…์ŠคํŠธ๋ฅผ ๋ถ„๋ฅ˜ํ•˜๊ธฐ ์œ„ํ•ด pipeline์„ ์‚ฌ์šฉํ•œ ๊ฐ„๋‹จํ•œ ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค:

>>> 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์œผ๋กœ ๋ฐ”๋กœ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์‚ฌ์ง„์—์„œ ์†์‰ฝ๊ฒŒ ๊ฐ์ฒด๋“ค์„ ํƒ์ง€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.:

>>> 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}}]

์œ„์™€ ๊ฐ™์ด, ์šฐ๋ฆฌ๋Š” ์ด๋ฏธ์ง€์—์„œ ํƒ์ง€๋œ ๊ฐ์ฒด๋“ค์— ๋Œ€ํ•˜์—ฌ ๊ฐ์ฒด๋ฅผ ๊ฐ์‹ธ๋Š” ๋ฐ•์Šค์™€ ํ™•๋ฅ  ๋ฆฌ์ŠคํŠธ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์™ผ์ชฝ์ด ์›๋ณธ ์ด๋ฏธ์ง€์ด๋ฉฐ ์˜ค๋ฅธ์ชฝ์€ ํ•ด๋‹น ์ด๋ฏธ์ง€์— ํƒ์ง€๋œ ๊ฒฐ๊ณผ๋ฅผ ํ‘œ์‹œํ•˜์˜€์Šต๋‹ˆ๋‹ค.

์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ pipeline API๊ฐ€ ์ง€์›ํ•˜๋Š” ๋‹ค์–‘ํ•œ ๊ณผ์ œ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ฝ”๋“œ 3์ค„๋กœ ์›ํ•˜๋Š” ๊ณผ์ œ์— ๋งž๊ฒŒ ์‚ฌ์ „ํ•™์Šต ๋ชจ๋ธ์„ ๋‹ค์šด๋กœ๋“œ ๋ฐ›๊ณ  ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ์€ PyTorch ๋ฒ„์ „์ž…๋‹ˆ๋‹ค:

>>> 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 ๋ฒ„์ „์ž…๋‹ˆ๋‹ค:

>>> 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์ด๋‚˜ TensorFlow tf.keras.Model์ž…๋‹ˆ๋‹ค. ์ด ํŠœํ† ๋ฆฌ์–ผ์€ ์ด๋Ÿฌํ•œ ๋ชจ๋ธ์„ ํ‘œ์ค€์ ์ธ PyTorch๋‚˜ TensorFlow ํ•™์Šต ๊ณผ์ •์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•, ๋˜๋Š” ์ƒˆ๋กœ์šด ๋ฐ์ดํ„ฐ๋กœ ํŒŒ์ธ ํŠœ๋‹ํ•˜๊ธฐ ์œ„ํ•ด Trainer API๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์„ค๋ช…ํ•ด ์ค๋‹ˆ๋‹ค.

์™œ transformers๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ• ๊นŒ์š”?

  1. ์†์‰ฝ๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ตœ์ฒจ๋‹จ ๋ชจ๋ธ:

    • ์ž์—ฐ์–ด ์ดํ•ด(NLU)์™€ ์ƒ์„ฑ(NLG), ์ปดํ“จํ„ฐ ๋น„์ „, ์˜ค๋””์˜ค ๊ณผ์ œ์—์„œ ๋›ฐ์–ด๋‚œ ์„ฑ๋Šฅ์„ ๋ณด์ž…๋‹ˆ๋‹ค.
    • ๊ต์œก์ž์™€ ์‹ค๋ฌด์ž์—๊ฒŒ ์ง„์ž… ์žฅ๋ฒฝ์ด ๋‚ฎ์Šต๋‹ˆ๋‹ค.
    • 3๊ฐœ์˜ ํด๋ž˜์Šค๋งŒ ๋ฐฐ์šฐ๋ฉด ๋ฐ”๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    • ํ•˜๋‚˜์˜ API๋กœ ๋ชจ๋“  ์‚ฌ์ „ํ•™์Šต ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  2. ๋” ์ ์€ ๊ณ„์‚ฐ ๋น„์šฉ, ๋” ์ ์€ ํƒ„์†Œ ๋ฐœ์ž๊ตญ:

    • ์—ฐ๊ตฌ์ž๋“ค์€ ๋ชจ๋ธ์„ ๊ณ„์† ๋‹ค์‹œ ํ•™์Šต์‹œํ‚ค๋Š” ๋Œ€์‹  ํ•™์Šต๋œ ๋ชจ๋ธ์„ ๊ณต์œ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    • ์‹ค๋ฌด์ž๋“ค์€ ํ•™์Šต์— ํ•„์š”ํ•œ ์‹œ๊ฐ„๊ณผ ๋น„์šฉ์„ ์ ˆ์•ฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    • ๋ชจ๋“  ๋ถ„์•ผ๋ฅผ ํ†ตํ‹€์–ด์„œ 400,000๊ฐœ ์ด์ƒ์˜ ์‚ฌ์ „ ํ•™์Šต๋œ ๋ชจ๋ธ์ด ์žˆ๋Š” ์ˆ˜์‹ญ ๊ฐœ์˜ ์•„ํ‚คํ…์ฒ˜.
  3. ๋ชจ๋ธ์˜ ๊ฐ ์ƒ์• ์ฃผ๊ธฐ์— ์ ํ•ฉํ•œ ํ”„๋ ˆ์ž„์›Œํฌ:

    • ์ฝ”๋“œ 3์ค„๋กœ ์ตœ์ฒจ๋‹จ ๋ชจ๋ธ์„ ํ•™์Šตํ•˜์„ธ์š”.
    • ๋ชฉ์ ์— ์•Œ๋งž๊ฒŒ ๋ชจ๋ธ์„ TF2.0/Pytorch/Jax ํ”„๋ ˆ์ž„ ์›Œํฌ ์ค‘ ํ•˜๋‚˜๋กœ ์ด๋™์‹œํ‚ค์„ธ์š”.
    • ํ•™์Šต, ํ‰๊ฐ€, ๊ณต๊ฐœ ๋“ฑ ๊ฐ ๋‹จ๊ณ„์— ๋งž๋Š” ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์›ํ•˜๋Š”๋Œ€๋กœ ์„ ํƒํ•˜์„ธ์š”.
  4. ํ•„์š”ํ•œ ๋Œ€๋กœ ๋ชจ๋ธ์ด๋‚˜ ์˜ˆ์‹œ๋ฅผ ์ปค์Šคํ„ฐ๋งˆ์ด์ฆˆํ•˜์„ธ์š”:

    • ์šฐ๋ฆฌ๋Š” ์ €์ž๊ฐ€ ๊ณต๊ฐœํ•œ ๊ฒฐ๊ณผ๋ฅผ ์žฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด ๊ฐ ๋ชจ๋ธ ๊ตฌ์กฐ์˜ ์˜ˆ์‹œ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
    • ๋ชจ๋ธ ๋‚ด๋ถ€ ๊ตฌ์กฐ๋Š” ๊ฐ€๋Šฅํ•œ ์ผ๊ด€์ ์œผ๋กœ ๊ณต๊ฐœ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
    • ๋น ๋ฅธ ์‹คํ—˜์„ ์œ„ํ•ด ๋ชจ๋ธ ํŒŒ์ผ์€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ๋…๋ฆฝ์ ์œผ๋กœ ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์™œ transformers๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ๋ง์•„์•ผ ํ• ๊นŒ์š”?

  • ์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ์‹ ๊ฒฝ๋ง ๋ธ”๋ก์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•œ ๋ชจ๋“ˆ์ด ์•„๋‹™๋‹ˆ๋‹ค. ์—ฐ๊ตฌ์ž๋“ค์ด ์—ฌ๋Ÿฌ ํŒŒ์ผ์„ ์‚ดํŽด๋ณด์ง€ ์•Š๊ณ  ๋ฐ”๋กœ ๊ฐ ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก, ๋ชจ๋ธ ํŒŒ์ผ ์ฝ”๋“œ์˜ ์ถ”์ƒํ™” ์ˆ˜์ค€์„ ์ ์ •ํ•˜๊ฒŒ ์œ ์ง€ํ–ˆ์Šต๋‹ˆ๋‹ค.
  • ํ•™์Šต API๋Š” ๋ชจ๋“  ๋ชจ๋ธ์— ์ ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๋งŒ๋“ค์–ด์ง€์ง„ ์•Š์•˜์ง€๋งŒ, ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์ œ๊ณตํ•˜๋Š” ๋ชจ๋ธ๋“ค์— ์ ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์ตœ์ ํ™”๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ผ๋ฐ˜์ ์ธ ๋จธ์‹  ๋Ÿฌ๋‹์„ ์œ„ํ•ด์„ , ๋‹ค๋ฅธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์„ธ์š”(์˜ˆ๋ฅผ ๋“ค๋ฉด, Accelerate).
  • ๊ฐ€๋Šฅํ•œ ๋งŽ์€ ์‚ฌ์šฉ ์˜ˆ์‹œ๋ฅผ ๋ณด์—ฌ๋“œ๋ฆฌ๊ณ  ์‹ถ์–ด์„œ, ์˜ˆ์‹œ ํด๋”์˜ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ค€๋น„ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด ์Šคํฌ๋ฆฝํŠธ๋“ค์„ ์ˆ˜์ • ์—†์ด ํŠน์ •ํ•œ ๋ฌธ์ œ์— ๋ฐ”๋กœ ์ ์šฉํ•˜์ง€ ๋ชปํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•„์š”์— ๋งž๊ฒŒ ์ผ๋ถ€ ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•ด์•ผ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์„ค์น˜

pip๋กœ ์„ค์น˜ํ•˜๊ธฐ

์ด ์ €์žฅ์†Œ๋Š” Python 3.9+, Flax 0.4.1+, PyTorch 2.0+, TensorFlow 2.6+์—์„œ ํ…Œ์ŠคํŠธ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

๊ฐ€์ƒ ํ™˜๊ฒฝ์— ๐Ÿค— Transformers๋ฅผ ์„ค์น˜ํ•˜์„ธ์š”. Python ๊ฐ€์ƒ ํ™˜๊ฒฝ์— ์ต์ˆ™ํ•˜์ง€ ์•Š๋‹ค๋ฉด, ์‚ฌ์šฉ์ž ๊ฐ€์ด๋“œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

์šฐ์„ , ์‚ฌ์šฉํ•  Python ๋ฒ„์ „์œผ๋กœ ๊ฐ€์ƒ ํ™˜๊ฒฝ์„ ๋งŒ๋“ค๊ณ  ์‹คํ–‰ํ•˜์„ธ์š”.

๊ทธ ๋‹ค์Œ, Flax, PyTorch, TensorFlow ์ค‘ ์ ์–ด๋„ ํ•˜๋‚˜๋Š” ์„ค์น˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ํ”Œ๋žซํผ์— ๋งž๋Š” ์„ค์น˜ ๋ช…๋ น์–ด๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด TensorFlow ์„ค์น˜ ํŽ˜์ด์ง€, PyTorch ์„ค์น˜ ํŽ˜์ด์ง€, Flax ์„ค์น˜ ํŽ˜์ด์ง€๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

์ด๋“ค ์ค‘ ์ ์–ด๋„ ํ•˜๋‚˜๊ฐ€ ์„ค์น˜๋˜์—ˆ๋‹ค๋ฉด, ๐Ÿค— Transformers๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด pip์„ ์ด์šฉํ•ด ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

pip install transformers

์˜ˆ์‹œ๋“ค์„ ์ฒดํ—˜ํ•ด๋ณด๊ณ  ์‹ถ๊ฑฐ๋‚˜, ์ตœ์ตœ์ตœ์ฒจ๋‹จ ์ฝ”๋“œ๋ฅผ ์›ํ•˜๊ฑฐ๋‚˜, ์ƒˆ๋กœ์šด ๋ฒ„์ „์ด ๋‚˜์˜ฌ ๋•Œ๊นŒ์ง€ ๊ธฐ๋‹ค๋ฆด ์ˆ˜ ์—†๋‹ค๋ฉด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์†Œ์Šค์—์„œ ๋ฐ”๋กœ ์„ค์น˜ํ•˜์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค.

conda๋กœ ์„ค์น˜ํ•˜๊ธฐ

๐Ÿค— Transformers๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด conda๋กœ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

conda install conda-forge::transformers

๋…ธํŠธ: huggingface ์ฑ„๋„์—์„œ transformers๋ฅผ ์„ค์น˜ํ•˜๋Š” ๊ฒƒ์€ ์‚ฌ์šฉ์ด ์ค‘๋‹จ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

Flax, PyTorch, TensorFlow ์„ค์น˜ ํŽ˜์ด์ง€์—์„œ ์ด๋“ค์„ conda๋กœ ์„ค์น˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ํ™•์ธํ•˜์„ธ์š”.

๋…ธํŠธ: ์œˆ๋„์šฐ ํ™˜๊ฒฝ์—์„œ ์บ์‹ฑ์˜ ์ด์ ์„ ์œ„ํ•ด ๊ฐœ๋ฐœ์ž ๋ชจ๋“œ๋ฅผ ํ™œ์„ฑํ™”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋งŒ์•ฝ ์—ฌ๋Ÿฌ๋ถ„์—๊ฒŒ ์žˆ์–ด์„œ ์„ ํƒ์ด ์•„๋‹Œ ํ•„์ˆ˜๋ผ๋ฉด ์ด ์ด์Šˆ๋ฅผ ํ†ตํ•ด ์•Œ๋ ค์ฃผ์„ธ์š”.

๋ชจ๋ธ ๊ตฌ์กฐ

๐Ÿค— Transformers๊ฐ€ ์ œ๊ณตํ•˜๋Š” ๋ชจ๋“  ๋ชจ๋ธ ์ฒดํฌํฌ์ธํŠธ ๋Š” huggingface.co ๋ชจ๋ธ ํ—ˆ๋ธŒ์— ์™„๋ฒฝํžˆ ์—ฐ๋™๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฐœ์ธ๊ณผ ๊ธฐ๊ด€์ด ๋ชจ๋ธ ํ—ˆ๋ธŒ์— ์ง์ ‘ ์—…๋กœ๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ˜„์žฌ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ชจ๋ธ ์ฒดํฌํฌ์ธํŠธ์˜ ๊ฐœ์ˆ˜:

๐Ÿค— Transformers๋Š” ๋‹ค์Œ ๋ชจ๋ธ๋“ค์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค: ๊ฐ ๋ชจ๋ธ์˜ ์š”์•ฝ์€ ์—ฌ๊ธฐ์„œ ํ™•์ธํ•˜์„ธ์š”.

๊ฐ ๋ชจ๋ธ์ด Flax, PyTorch, TensorFlow์œผ๋กœ ๊ตฌํ˜„๋˜์—ˆ๋Š”์ง€ ๋˜๋Š” ๐Ÿค— Tokenizers ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์ง€์›ํ•˜๋Š” ํ† ํฌ๋‚˜์ด์ €๋ฅผ ์‚ฌ์šฉํ•˜๋Š”์ง€ ํ™•์ธํ•˜๋ ค๋ฉด, ์ด ํ‘œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

์ด ๊ตฌํ˜„์€ ์—ฌ๋Ÿฌ ๋ฐ์ดํ„ฐ๋กœ ๊ฒ€์ฆ๋˜์—ˆ๊ณ  (์˜ˆ์‹œ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ฐธ๊ณ ํ•˜์„ธ์š”) ์˜ค๋ฆฌ์ง€๋„ ๊ตฌํ˜„์˜ ์„ฑ๋Šฅ๊ณผ ๊ฐ™์•„์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋„ํ๋จผํŠธ์˜ Examples ์„น์…˜์—์„œ ์„ฑ๋Šฅ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ์„ค๋ช…์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋” ์•Œ์•„๋ณด๊ธฐ

์„น์…˜ ์„ค๋ช…
๋„ํ๋จผํŠธ ์ „์ฒด API ๋„ํ๋จผํŠธ์™€ ํŠœํ† ๋ฆฌ์–ผ
๊ณผ์ œ ์š”์•ฝ ๐Ÿค— Transformers๊ฐ€ ์ง€์›ํ•˜๋Š” ๊ณผ์ œ๋“ค
์ „์ฒ˜๋ฆฌ ํŠœํ† ๋ฆฌ์–ผ Tokenizer ํด๋ž˜์Šค๋ฅผ ์ด์šฉํ•ด ๋ชจ๋ธ์„ ์œ„ํ•œ ๋ฐ์ดํ„ฐ ์ค€๋น„ํ•˜๊ธฐ
ํ•™์Šต๊ณผ ํŒŒ์ธ ํŠœ๋‹ ๐Ÿค— Transformers๊ฐ€ ์ œ๊ณตํ•˜๋Š” ๋ชจ๋ธ PyTorch/TensorFlow ํ•™์Šต ๊ณผ์ •๊ณผ Trainer API์—์„œ ์‚ฌ์šฉํ•˜๊ธฐ
ํ€ต ํˆฌ์–ด: ํŒŒ์ธ ํŠœ๋‹/์‚ฌ์šฉ ์Šคํฌ๋ฆฝํŠธ ๋‹ค์–‘ํ•œ ๊ณผ์ œ์—์„œ ๋ชจ๋ธ์„ ํŒŒ์ธ ํŠœ๋‹ํ•˜๋Š” ์˜ˆ์‹œ ์Šคํฌ๋ฆฝํŠธ
๋ชจ๋ธ ๊ณต์œ  ๋ฐ ์—…๋กœ๋“œ ์ปค๋ฎค๋‹ˆํ‹ฐ์— ํŒŒ์ธ ํŠœ๋‹๋œ ๋ชจ๋ธ์„ ์—…๋กœ๋“œ ๋ฐ ๊ณต์œ ํ•˜๊ธฐ

์ธ์šฉ

๐Ÿค— Transformers ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ธ์šฉํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด, ์ด ๋…ผ๋ฌธ์„ ์ธ์šฉํ•ด ์ฃผ์„ธ์š”:

@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"
}