HuggingFace ããã° : BERT 101 ð€ æå 端 NLPã¢ãã«ã®è§£èª¬ (翻蚳/解説)
翻蚳 : (æ ª)ã¯ã©ã¹ãã£ãã ã»ãŒã«ã¹ã€ã³ãã©ã¡ãŒã·ã§ã³
äœææ¥æ : 12/18/2022
* æ¬ããŒãžã¯ãHuggingFace Blog ã®ä»¥äžã®ããã¥ã¡ã³ãã翻蚳ããäžã§é©å®ãè£è¶³èª¬æãããã®ã§ãïŒ
- BERT 101 ð€ State Of The Art NLP Model Explained (Authors : Britney Muller ; Published : 03/02/2022)
* ãµã³ãã«ã³ãŒãã®åäœç¢ºèªã¯ããŠãããŸãããå¿
èŠãªå Žåã«ã¯é©å®ãè¿œå æ¹å€ããŠããŸãã
* ãèªç±ã«ãªã³ã¯ã匵ã£ãŠé ããŠããŸããŸããããsales-info@classcat.com ãŸã§ãäžå ±ããã ãããšå¬ããã§ãã
- 人工ç¥èœç 究éçºæ¯æŽ
- 人工ç¥èœç ä¿®ãµãŒãã¹(çµå¶è å±€åããªã³ãµã€ãç ä¿®)
- ãã¯ãã«ã«ã³ã³ãµã«ãã£ã³ã°ãµãŒãã¹
- å®èšŒå®éš(ãããã¿ã€ãæ§ç¯)
- ã¢ããªã±ãŒã·ã§ã³ãžã®å®è£
- 人工ç¥èœç ä¿®ãµãŒãã¹
- PoC(æŠå¿µå®èšŒ)ã倱æãããªãããã®æ¯æŽ
- ãäœãŸãã®å°åã«é¢ä¿ãªã Web ãã©ãŠã¶ãããåå é ããŸããäºåç»é² ãå¿ èŠã§ãã®ã§ã泚æãã ããã
â ãååã : æ¬ä»¶ã«é¢ãããåãåããå ã¯äžèšãŸã§ãé¡ãããããŸãã
- æ ªåŒäŒç€Ÿã¯ã©ã¹ãã£ãã ã»ãŒã«ã¹ã»ããŒã±ãã£ã³ã°æ¬éš ã»ãŒã«ã¹ã»ã€ã³ãã©ã¡ãŒã·ã§ã³
- sales-info@classcat.com ; Web: www.classcat.com ; ClassCatJP
HuggingFace ããã° : BERT 101 ð€ æå 端 NLPã¢ãã«ã®è§£èª¬
What is BERT?
BERTãTransformers ã«ããåæ¹åãšã³ã³ãŒãè¡šçŸ (Bidirectional Encoder Representations from Transformers) ã®çç¥ãã¯èªç¶èšèªåŠçã®ããã®æ©æ¢°åŠç¿ (ML) ã¢ãã«ã§ãããã㯠2018 幎㫠Google AI èšèªã®ç 究è ã«ããéçºãããã»ã³ãã¡ã³ãåæãåºæè¡šçŸæœåºã®ãããªæãäžè¬çãªèšèªã¿ã¹ã¯ã® 11+ ãžã®ã¹ã€ã¹ã¢ãŒããŒãã€ããªè§£æ³ãšããŠæ©èœããŠããŸãã
èšèªã¯æŽå²çã«èŠãŠã³ã³ãã¥ãŒã¿ããç解ãããããšãå°é£ã§ããã確ãã«ãã³ã³ãã¥ãŒã¿ã¯ããã¹ãå ¥åãåéããã¹ãã¢ããŠèªãããšã¯ã§ããŸãããåºæ¬çãªèšèªã³ã³ããã¹ããæ¬ ããŠããŸãã
ããã§ãèªç¶èšèªåŠç (NLP) ãåºçŸããŸãã : ããã¹ããšè©±ãèšèãã³ã³ãã¥ãŒã¿ãèªã¿ãåæãã解éããŠæå³ãå°åºããããšãç®çãšãã人工ç¥èœã®åéã§ãããã®å®è·µã¯ãã³ã³ãã¥ãŒã¿ã人éã®èšèªããç解ãããããšãæ¯æŽããããã«èšèªåŠãçµ±èšåŠãšæ©æ¢°åŠç¿ãçµã¿åãããŠããŸãã
åŸæ¥ãåã ã® NLP ã¿ã¹ã¯ã¯åç¹å®ã¿ã¹ã¯ã®ããã«äœæãããåã ã®ã¢ãã«ã«ãã解決ãããŸãããThat is, untilâ BERT!
BERT ã¯ãæãäžè¬ç㪠NLP ã¿ã¹ã¯ã® 11+ ã解ãããšã«ãã NLP 空éãå€é©ã (ãããåŸæ¥ã®ã¢ãã«ãããè¯ã)ãNLP ã®ãªãã§ãå±ã«ãªããŸããã
ãã®ã¬ã€ãã§ã¯ãBERT ãšã¯äœããäœæ ããã¯éãã®ãããã㊠BERT ã§ã©ã®ããã«å§ããããåŠç¿ããŸã :
- BERT ã¯äœã«äœ¿ããããïŒ
- BERT ã¯ã©ã®ããã«åäœãããïŒ
- BERT ã¢ãã«ãµã€ãº & ã¢ãŒããã¯ãã£
- äžè¬çãªèšèªã¿ã¹ã¯äžã® BERT ã®æ§èœ
- 深局åŠç¿ã®ç°å¢çãªåœ±é¿
- BERT ã®ãªãŒãã³ãœãŒã¹ã»ãã¯ãŒ
- BERT ã§ã©ã®ããã«å§ããã
- BERT FAQ
- ãŸãšã
Let’s get started! ð
1. BERT ã¯äœã«äœ¿ããããïŒ
BERT ã¯åºç¯å²ãªèšèªã¿ã¹ã¯ã§å©çšã§ããŸã :
- æ ç»ã¬ãã¥ãŒãããžãã£ãããã¬ãã£ããã決å®ã§ããŸãã(ã»ã³ãã¡ã³ãåæ)
- ãã£ãããããã質åã«çããã®ã«åœ¹ç«ã¡ãŸãã(質åå¿ç)
- é»åã¡ãŒã« (Gmail) ãæžããšãããã¹ããäºæž¬ããŸãã(ããã¹ãäºæž¬)
- æ°è¡ã®ã»ã³ãã³ã¹å
¥åã ãã§ä»»æã®ãããã¯ã«ã€ããŠèšäºãæžãããšãã§ããŸãã(ããã¹ãçæ)
- é·ãå¥çŽæžãçŽ æ©ãèŠçŽã§ããŸãã(èŠçŽ)
- (âbankâ ã®ãããª) è€æ°ã®æå³ãæã€åèªãåšèŸºããã¹ãã«åºã¥ããŠå·®å¥åã§ããŸãã(å€çŸ©æ§è§£æ¶)
ããå€ãã®èšèª/NLP ã¿ã¹ã¯ããããæŽã«ãããã®åã ã®èåŸã«ãã詳现ããããŸãã
é¢çœãäºå® : 貎æ¹ã¯ã»ãŒæ¯æ¥ãNLP (ãããŠå€å BERT) ãšé¢ããåããæã£ãŠããŸãïŒ
NLP 㯠Google 翻蚳, é³å£°ã¢ã·ã¹ã¿ã³ã (Alexa, Siri, etc.), ãã£ããããã, Google æ€çŽ¢, é³å£°-operated GPS, çã ãæ¯æŽããŠããŸãã
1.1 BERT ã®äŸ
BERT 㯠2020 幎 11 æããæ®ã©ãã¹ãŠã®æ€çŽ¢ã«å¯Ÿã㊠Google ã®ããè¯ãè¡šé¢ç㪠(è±èªã®) çµæãæ¯æŽããŠããŸãã
ããã«ãBERT ãç¹å®ã®æ€çŽ¢ãããè¯ãç解ããã®ã«ã©ã®ããã«åœ¹ç«ã€ãã®äŸããããŸã :
BERT 以åã® Google ã¯åŠæ¹ç®ã®ååŸã«é¢ããæ å ±ãè¡šé¢åãããŸããã
BERT 以åŸã® Google 㯠“for someone” ãå¥ã®èª°ãã®ããã«åŠæ¹ç®ãåãåãããšã«é¢ä¿ããŠããããšãç解ããŠãä»ã§ã¯æ€çŽ¢çµæã¯ããã«çããã®ã«åœ¹ç«ã£ãŠããŸãã
2. BERT ã¯ã©ã®ããã«åäœãããïŒ
BERT ã¯ä»¥äžã掻çšããŠæ©èœããŸã :
2.1 倧èŠæš¡ãªéã®èšç·ŽããŒã¿
33 åèªã®èšå€§ãªããŒã¿ã»ããã BERT ã®ç¶ç¶çãªæåã«å¯äžããŠããŸãã
BERT ã¯ç¹ã« Wikipedia (~25 åèª) ãš Google ã® BooksCorpus (~8 åèª) äžã§èšç·ŽãããŸããããããã®å·šå€§ãªæ å ±ãæã€ããŒã¿ã»ãã㯠BERT ã®è±èªã ãã§ãªãäžçäžã®æ·±ãç¥èã«å¯äžããŸããïŒð
ãã®å€§èŠæš¡ãªããŒã¿ã»ããã§ã®èšç·Žã¯éåžžã«æéãããããŸããBERT ã®èšç·Žã¯æ°ãã Transformer ã¢ãŒããã¯ãã£ã®ãããã§å¯èœãšãªããTPU (Tensor Processing Units – 巚倧㪠ML ã¢ãã«ã®ããã«ç¹ã«æ§ç¯ããã Google ã®ã«ã¹ã¿ã åè·¯) ã䜿çšããŠã¹ããŒãã¢ãããããŸãã – 64 TPU ã 4 æ¥éã«æž¡ã£ãŠ BERT ãèšç·ŽããŸããã
Note : ããå°ã㪠BERT ã¢ãã«ã®éèŠã¯ BERT ã (æºåž¯ã¯ããœã³ã³ã®ãããª) å°ããèšç®ç°å¢å ã§äœ¿çšããããã«å¢ããŠããŸãã2020 幎 3 æã«ã¯ 23 ã®å°ãã BERT ã¢ãã«ããªãªãŒã¹ãããŸãããDistilBERT 㯠BERT ã®è»œéçãæäŸããŸã ; BERT ã®æ§èœã® 95% 以äžãç¶æããªãã 60% é«éã«å®è¡ã§ããŸãã
2.2 Masked èšèªã¢ãã«ãšã¯äœãïŒ
MLM ã¯ãã»ã³ãã³ã¹ã®ããåèªããã¹ã¯ã㊠(é ããŠ)ãBERET ã«ãã¹ã¯ãããåèªãäºæž¬ãããããã«èŠãããåèªã®ããããã®åŽã®åèªãåæ¹åã«å©çšãããããšã«ãããããã¹ãããã®åæ¹åãªåŠç¿ãå¯èœã«ããŸã/匷èŠããŸããThis had never been done before!
Fun Fact : ç§ãã¡ã¯äººéãšããŠãããèªç¶ã«è¡ã£ãŠããŸãïŒ
Masked èšèªã¢ãã«ã®äŸ :
貎æ¹ã®å人ãã°ã¬ã€ã·ã£ãŒåœç«å ¬åã§ãã£ã³ãäžã«é»è©±ãããŠããŠããµãŒãã¹ãéåãå§ãããšããŸããé»è©±ãåããåã«è²Žæ¹ãèããæåŸã¯ :
å人: âDang! Iâm out fishing and a huge trout just [ãã©ã³ã¯] my line!â
å人ãäœãšèšã£ããæšæž¬ã§ããŸããïŒïŒ
ã³ã³ããã¹ãã®ãã³ããšããŠå€±ããã (missing) åèªã®ååŸã®åèªãåæ¹åã«èããããšã§ã貎æ¹ã¯å€±ãããåèªãèªç¶ã«äºæž¬ããããšãã§ããŸã (é£ããã©ã®ãããªãã®ãã®åŸæ¥ã®ç¥èã«å ããŠ)ã貎æ¹ã¯å人㯠âbrokeâ ãšèšã£ãããšãæšæž¬ããŸãããïŒããã¯ç§ãã¡ãäºæž¬ãããã®ã§ããããŸããã人éã§ããããããã®æ¹æ³ã®å¹Ÿã€ãã«ã€ããŠééããããã§ãã
Note : ããããèšèªã¢ãã«ã®æ§èœã¹ã³ã¢ã«å¯ŸããŠã人éã®æ§èœãã®æ¯èŒãèŠãããšãå€ãçç±ã§ãããããŠãã¡ãããBERT ã®ãããªæ°ããã¢ãã«ã¯äººéãããæ£ç¢ºã§ããåŸãŸãïŒð€¯
äžèšã® [空çœ] åèªãæºããããã«è²Žæ¹ãè¡ã£ãåæ¹åææ³ã¯ BERT ãæå 端粟床ãéæããæ¹æ³ã«é¡äŒŒããŠããŸããããŒã¯ã³åãããåèªã®ã©ã³ãã 㪠15% ã¯èšç·Žã®éã«é ãããBERT ã®ãžã§ãã¯é ãããåèªãæ£ããäºæž¬ããããšã§ãããã®ããã«ãã¢ãã«ã«è±èª (ãããŠäœ¿çšããåèª) ã«ã€ããŠçŽæ¥æããŸããIsnât that neat?
Play around with BERTâs masking predictions:
(蚳泚: åæ åç §)
次æ (Next Sentence) äºæž¬ãšã¯äœãïŒ
NSP (次æäºæž¬) ã¯ãäžããããã»ã³ãã³ã¹ãåã®ã»ã³ãã³ã¹ã«ç¶ããŠãããåŠããäºæž¬ããããšã§ãBERT ãã»ã³ãã³ã¹éã®é¢ä¿ã«ã€ããŠåŠç¿ããã®ãæ¯æŽããããã«äœ¿çšãããŸãã
次æäºæž¬ãµã³ãã« :
- Paul went shopping. He bought a new shirt. (æ£ããã»ã³ãã³ã¹ãã¢)
- Ramona made coffee. Vanilla ice cream cones for sale. (äžæ£ãªã»ã³ãã³ã¹ãã¢)
èšç·Žã§ã¯ãBERT ã次ã®ã»ã³ãã³ã¹äºæž¬ç²ŸåºŠãåäžããæ¯æŽã®ããã«ã50% ã®æ£ããã»ã³ãã³ã¹ãã¢ã 50% ã®ã©ã³ãã ãªã»ã³ãã³ã¹ãã¢ãšããã¯ã¹ã€ã³ãããŸãã
Fun Fact : BERT 㯠MLM (50%) ãš NLP (50%) ã®äž¡æ¹ã§åæã«èšç·ŽãããŸãã
2.4 Transformers
Transformer ã¢ãŒããã¯ãã£ã¯ ML èšç·Žã極ããŠå¹ççã«äžŠååããããšãå¯èœã«ããŸããããããŠå§åçãªäžŠååã¯æ¯èŒççæéã§å€§èŠæš¡ãªããŒã¿é㧠BERT ãèšç·Žããããšãå¯èœã«ããŸãã
Transformers ã¯åèªéã®é¢ä¿æ§ã芳å¯ããããã«ã¢ãã³ã·ã§ã³æ©æ§ã䜿çšããŸããå ã ã¯æå㪠2017 Attention Is All You Need è«æã§ææ¡ãããã³ã³ã»ããã¯äžçäžã® NLP ã¢ãã«ã§ Transformers ã®äœ¿çšã®ãã£ãããšãªããŸããã
2017 幎ã®ãããã®çºè¡šä»¥æ¥ãTransformers ã¯èªç¶èšèªåŠç, çºè©±èªè, ãããŠã³ã³ãã¥ãŒã¿ããžã§ã³ ã®ãããªã¯å€ãã®åéã®ã¿ã¹ã¯ã«åãçµãæå 端ã®ã¢ãããŒãã«æ¥éã«ãªã£ãŠãããŸãããèŠããã«ã貎æ¹ã深局åŠç¿ãè¡ã£ãŠããã®ã§ããã°ã貎æ¹ã¯ Transformers ãå¿ èŠã ãšããããšã§ãïŒ
Lewis Tunstall, Hugging Face ML ãšã³ãžã㢠& Natural Language Processing with Transformers ã®èè
Timeline of popular Transformer model releases:
2.4.1 Transformers ã¯ã©ã®ããã«æ©èœãããïŒ
Transformers ã¯ãã¯ãã«ãªæ·±å±€åŠç¿ã¢ã«ãŽãªãºã ã§ãããã¢ãã³ã·ã§ã³ã®æŽ»çšã«ããæ©èœããŸãã
â 泚æ (ã¢ãã³ã·ã§ã³) ãéããŠç§ãã¡äººéãæ å ±ãåŠçããæ¹æ³ãšããã»ã©éãã¯ãããŸãããè åšãäžããªãããããã¯å¿çãå¿ èŠãšããªããããµããæ¥ã ã®å ¥åãå¿ãã/ç¡èŠããããšãç§ãã¡ã¯ä¿¡ããããªãã»ã©äžæãã§ããäŸãã°ã貎æ¹ã¯åã®ç«ææ¥ã«åž°å® ãããšãã«èŠããèããããšãã¹ãŠãèŠããŠããããšãã§ããŸããïŒOf course not! ç§ãã¡ã®è³ã®ã¡ã¢ãªã«ã¯éçããã貎éã§ããèšæ¶åã¯èªæãªå ¥åãå¿ããèœåã«ããå©ããããŠããŸãã
åæ§ã«ãæ©æ¢°åŠç¿ã¢ãã«ã¯éèŠãªããšã ãã«æ³šæãæããç¡é¢ä¿ãªæ å ±ãåŠçããŠèšç®è³æºã浪費ããªãæ¹æ³ãåŠç¿ããå¿ èŠããããŸããTransformers ã¯æŽãªãåŠçã®ããã«ã»ã³ãã³ã¹ã®ã©ã®åèªãæãéèŠã§ãããã瀺ãå·®å¥åããéã¿ãäœæããŸãã
transformer ã¯ãéåžžã¯ãšã³ã³ãŒããšåŒã°ãããtransformer å±€ã®ã¹ã¿ãã¯ãçµç±ããŠå ¥åãé£ç¶çã«åŠçããããšã§ãããè¡ãªããŸããå¿ èŠã§ããã°ãã¿ãŒã²ããåºåãäºæž¬ããããã«å¥ã® transformer å±€ã®ã¹ã¿ã㯠– ãã³ãŒã – ã䜿çšã§ããŸããâ ããã©ã BERT ã¯ãã³ãŒãã䜿çšããŸãããTransformers ã¯æåž«ãªãåŠç¿ã«æ¯é¡ãªãé©ããŠããŸãããããã¯æ°çŸäžã®ããŒã¿ãã€ã³ããå¹ççã«åŠçã§ããããã§ãã
Fun Fact : Google 㯠2011 幎ããèšç·ŽããŒã¿ãã©ãã«ä»ãããããã« reCAPTCHA ã®éžæã䜿çšããŠããŸãããGoogle Books ã®ã¢ãŒã«ã€ãå šäœãš New York Times ã«ã¿ãã°ã® 1,300 äžã®èšäºã reCAPTCHA ããã¹ããå ¥åãã人ã ãéããŠæåããããã (transcribed) æ°å€åãããŠããŸãããä»ã¯ãreCAPTCHA 㯠Google Street View ç»å, è», åæ¢ä¿¡å·, é£è¡æ©, çã«ã©ãã«ä»ãããããšãèŠæ±ããŠããŸããGoogle ããã®åŽåãžã®ç§ãã¡ã®åå ãç¥ãããŠããããšçŽ æµãªã®ã§ãã (èšç·ŽããŒã¿ã¯å°æ¥çãªåçšæå³ããããã¡ãªã®ã§), è±ç·ããŸãã …
â» To learn more about Transformers check out our Hugging Face Transformers Course.
BERT ã¢ãã«ãµã€ãº & ã¢ãŒããã¯ãã£
2 ã€ã®ãªãªãžãã« BERT ã¢ãã«ã«ã€ããŠã¢ãŒããã¯ãã£ãå解ããŸããã :
ML ã¢ãŒããã¯ãã£çšèª:
- ãã©ã¡ãŒã¿ : ã¢ãã«ã§å©çšå¯èœãªåŠç¿å¯èœãªå€æ°/å€ã®æ°
- Transformer å±€ : Transformer ãããã¯æ°ãtransformer ãããã¯ã¯åèªè¡šçŸã®ã·ãŒã¯ãšã³ã¹ãæèãèæ
®ãã (contextualized) åèª (æ°å€åãããåèª) ã®ã·ãŒã¯ãšã³ã¹ã«å€æããŸãã
- é ããµã€ãº : å
¥åãšåºåã®éã«äœçœ®ããæ°åŠé¢æ°ã®å±€ã§ãæãŸããçµæãçæããããã«éã¿ã (åèªã«) å²ãåœãŠãŸãã
- ã¢ãã³ã·ã§ã³ã»ããã : Transformer ãããã¯ã®ãµã€ãº
- ããã»ãã·ã³ã° : ã¢ãã«ãèšç·Žããããã«äœ¿çšãããåŠçãŠãããã®ã¿ã€ãã
- èšç·Žã®é·ã : ã¢ãã«ãèšç·Žããããã«ããã£ãæéã
Hereâs how many of the above ML architecture parts BERTbase and BERTlarge has:
BERTlarge ã®è¿œå ã®å±€ãã¢ãã³ã·ã§ã³ãããããããŠãã©ã¡ãŒã¿ã NLP ã¿ã¹ã¯ã«å¯ŸããŠãã®æ§èœãã©ã®ããã«åäžããããèŠãŠã¿ãŸãããã
4. äžè¬çãªèšèªã¿ã¹ã¯äžã® BERT ã®æ§èœ
⻠蚳泚 : ãã®ç« ã®è©³çŽ°ã¯ åæ åç §ã
BERT has successfully achieved state-of-the-art accuracy on 11 common NLP tasks, outperforming previous top NLP models, and is the first to outperform humans! But, how are these achievements measured?
NLP è©äŸ¡ã¡ãœãã :
4.1 SQuAD v1.1 & v2.0
4.2 SWAG
4.3 GLUE ãã³ãããŒã¯
5. 深局åŠç¿ã®ç°å¢çãªåœ±é¿
倧èŠæš¡ãªæ©æ¢°åŠç¿ã¢ãã«ã¯èšå€§ãªããŒã¿éãå¿ èŠãšããããã¯æéãšèšç®è³æºã®äž¡æ¹ã§é«äŸ¡ã§ãã
ãããã®ã¢ãã«ã¯ãŸãç°å¢ãžã®åœ±é¿ããããŸã :
æ©æ¢°åŠç¿ãžã®ç°å¢ãžã®åœ±é¿ã¯ããªãŒãã³ãœãŒã¹ãéããŠæ©æ¢°åŠç¿ã®äžçãæ°äž»åããããšã®æ£åœæ§ãä¿¡ããå€ãã®çç±ã®äžã€ã§ãïŒå€§èŠæš¡ãªäºåèšç·Žæžã¿ã¢ãã«ã®å ±æã¯ãã³ãã¥ããã£æåã®åãçµã¿ã«ããå šäœçãªèšç®ã³ã¹ããšã«ãŒãã³ã»ãããããªã³ãã®åæžã«ã€ããŠæ¬è³ªçã§ãã
6. BERT ã®ãªãŒãã³ãœãŒã¹ã»ãã¯ãŒ
GPT-3 ã®ãããªä»ã®å€§èŠæš¡åŠç¿ã¢ãã«ãšã¯éããBERT ã®ãœãŒã¹ã³ãŒãã¯äžè¬ã«ã¢ã¯ã»ã¹å¯èœã§ (GitHub ã® BERT ã®ã³ãŒãåç §)ãBERT ãäžçäžã§åºã䜿çšãããããšãå¯èœã«ããŠããŸããThis is a game-changer!
éçºè ã¯ä»ã§ã¯ BERT ã®ãããªæå 端ã¢ãã«ãååŸããŠå€§éã®æéãšãéããããããšãªãçŽ æ©ãå®è¡ã§ããŸããð€¯
代ããã«éçºè ã¯ãç¬èªã®ã¿ã¹ã¯ã«ã¢ãã«æ§èœãã«ã¹ã¿ãã€ãºããããã« BERT ã埮調æŽããåãçµã¿ã«æ³šåã§ããŸãã
貎æ¹ã BERT ã埮調æŽããããšãæãŸãªããªãã°ãç¹å®ã®ãŠãŒã¹ã±ãŒã¹ã®ããã«æ°åã®ãªãŒãã³ãœãŒã¹ã§ç¡æã®ãäºåèšç·Žæžã¿ BERT ã¢ãã«ãçŸåšå©çšå¯èœã§ããããšã«æ³šæããããšã¯éèŠã§ãã
ç¹å®ã®ã¿ã¹ã¯ã«å¯ŸããŠäºåèšç·Žããã BERT ã¢ãã« :
- Twitter ã»ã³ãã¡ã³ãåæ
- æ¥æ¬èªããã¹ãã®åæ
- ææ categorizer (è±èª – anger, fear, joy, çã)
- èšåº (Clinical) ããŒãåæ
- é³å£° to ããã¹ã翻蚳
- æ害 (Toxic) ã³ã¡ã³ãæ€åº
You can also find hundreds of pre-trained, open-source Transformer models available on the Hugging Face Hub.
7. BERT ã§ã©ã®ããã«å§ããã
ãã®ããŒãããã¯ãäœæããŸãã ã®ã§ãGoogle Colab ã§ãã®ç°¡åãªãã¥ãŒããªã¢ã«ãéã㊠BERT ãè©Šãããšãã§ããŸããããŒãããã¯ãéããã以äžã®ã³ãŒãã貎æ¹ã®ãã®ã«è¿œå ããŠãã ãããPro Tip : Use (Shift + Click) to run a code cell.
Note : Hugging Face ã® pipeline ã¯ã©ã¹ ã¯ãã³ãŒãã®ããã 1 è¡ã§ transformers ã®ãããªãªãŒãã³ãœãŒã¹ ML ã¢ãã«ãä¿¡ããããªããããç°¡åã«åŒã蟌ã¿ãŸãã
7.1 Transformers ã®ã€ã³ã¹ããŒã«
æåã«ã次ã®ã³ãŒã㧠Transformers ãã€ã³ã¹ããŒã«ããŸããã :
!pip install transformers
7.2 BEERT ãè©Šã
以äžã®ã»ã³ãã³ã¹ã貎æ¹èªèº«ã®ãã®ã«èªç±ã«çœ®ãæããŠãã ããããã ããBERT ãæ¬ èœããåèªãäºæž¬ã§ããããã«ã©ããã« [MASK] ã¯æ®ããŠãã ããã
from transformers import pipeline
unmasker = pipeline('fill-mask', model='bert-base-uncased')
unmasker("Artificial Intelligence [MASK] take over the world.")
When you run the above code you should see an output like this:
[{'score': 0.3182411789894104, 'sequence': 'artificial intelligence can take over the world.', 'token': 2064, 'token_str': 'can'}, {'score': 0.18299679458141327, 'sequence': 'artificial intelligence will take over the world.', 'token': 2097, 'token_str': 'will'}, {'score': 0.05600147321820259, 'sequence': 'artificial intelligence to take over the world.', 'token': 2000, 'token_str': 'to'}, {'score': 0.04519503191113472, 'sequence': 'artificial intelligences take over the world.', 'token': 2015, 'token_str': '##s'}, {'score': 0.045153118669986725, 'sequence': 'artificial intelligence would take over the world.', 'token': 2052, 'token_str': 'would'}]
Kind of frightening right? ð
7.3 ã¢ãã«ã®ãã€ã¢ã¹ã«æ³šæãã
BERT ã “man” ã«å¯ŸããŠã©ã®ãããªãžã§ããææ¡ãããèŠãŠã¿ãŸããã :
unmasker("The man worked as a [MASK].")
When you run the above code you should see an ouput that looks something like:
[{'score': 0.09747546911239624, 'sequence': 'the man worked as a carpenter.', 'token': 10533, 'token_str': 'carpenter'}, {'score': 0.052383411675691605, 'sequence': 'the man worked as a waiter.', 'token': 15610, 'token_str': 'waiter'}, {'score': 0.04962698742747307, 'sequence': 'the man worked as a barber.', 'token': 13362, 'token_str': 'barber'}, {'score': 0.037886083126068115, 'sequence': 'the man worked as a mechanic.', 'token': 15893, 'token_str': 'mechanic'}, {'score': 0.037680838257074356, 'sequence': 'the man worked as a salesman.', 'token': 18968, 'token_str': 'salesman'}]
BERT 㯠man ã®ãžã§ãã Carpenter, Waiter, Barber, Mechanic, or Salesman ã§ãããšäºæž¬ããŸããã
ããã§ã¯ “woman” ã«å¯ŸããŠã©ã®ãããªãžã§ããææ¡ãããèŠãŠã¿ãŸãããã
unmasker("The woman worked as a [MASK].")
You should see an output that looks something like:
[{'score': 0.21981535851955414, 'sequence': 'the woman worked as a nurse.', 'token': 6821, 'token_str': 'nurse'}, {'score': 0.1597413569688797, 'sequence': 'the woman worked as a waitress.', 'token': 13877, 'token_str': 'waitress'}, {'score': 0.11547300964593887, 'sequence': 'the woman worked as a maid.', 'token': 10850, 'token_str': 'maid'}, {'score': 0.03796879202127457, 'sequence': 'the woman worked as a prostitute.', 'token': 19215, 'token_str': 'prostitute'}, {'score': 0.030423851683735847, 'sequence': 'the woman worked as a cook.', 'token': 5660, 'token_str': 'cook'}]
BERT 㯠woman ã®ãžã§ãã Nurse, Waitress, Maid, Prostitute, or Cook ã§ãããšäºæž¬ããŸãããããã¯è·æ¥çãªåœ¹å²ã§æãã㪠gender ãã€ã¢ã¹ã瀺ããŠããŸãã
7.4 楜ããã幟ã€ãã®ä»ã® BERT ããŒãããã¯
A Visual Notebook to BERT for the First Time
+Don’t forget to checkout the Hugging Face Transformers Course to learn more ð
8. BERT FAQ
BERT 㯠PyTorch ã§äœ¿çšã§ããŸããïŒ
Yes! Hugging Face ã®å°é家㯠GitHub 㧠PyTorch transformers ã¬ããžã㪠ããªãŒãã³ãœãŒã¹åããŸããã
Pro Tip : Lewis Tunstall, Leandro von Werra, and Thomas Wolf also wrote a book to help people build language applications with Hugging Face called, âNatural Language Processing with Transformersâ.
BERT 㯠Tensorflow ã§äœ¿çšã§ããŸããïŒ
Yes! TensorFlow ã Transformers ã®ããã¯ãšã³ããšããŠäœ¿çšã§ããŸãã
BERT ãäºåèšç·Žããã«ã¯ã©ã®ãããããããŸããïŒ
2 ã€ã®ãªãªãžãã« BERT ã¢ãã«ã¯ 4(BERTbase) ãš 16(BERTlarge) ã® Cloud TPU 㧠4 æ¥éèšç·ŽãããŸããã
BERT ã埮調æŽããã«ã¯ã©ã®ãããããããŸããïŒ
äžè¿°ã®äžè¬ç㪠NLP ã¿ã¹ã¯ã«ã€ããŠãBERT ã¯åäž Cloud TPU 㧠1-25 åã®éãåäž GPU 㧠1-130 åã®éããããŸãã
BERT ã¯äœãéãã®ãïŒ
BERT 㯠2 ã¹ãããã§èšç·Žããã NLP ã®æåã®ã¢ãã«ã®äžã€ã§ã :
- BERT ã¯æåž«ãªãæµåã§ã©ãã«ä»ããããŠããªã (人éã®ã¢ãããŒã·ã§ã³ããªã) èšå€§ãªéã®ããŒã¿ã§èšç·ŽãããŸããã
- ãããã BERT ã¯åã®äºåèšç·Žæžã¿ã¢ãã«ããå§ããŠãå°éã®äººéãã¢ãããŒãããããŒã¿ã§èšç·Žãããæå 端ãªããã©ãŒãã³ã¹ãšããçµæã«ãªããŸããã
9. ãŸãšã
BERT ã¯éåžžã«è€éã§é«åºŠãªèšèªã¢ãã«ã§ãèšèªç解ãèªååããæ¯æŽãããŸããæå 端ã®æ§èœãå®çŸããèœåã¯èšå€§ãªéã®ããŒã¿äžã®èšç·Žãš NLP åéã«é©æ°ãããããã Transformers ã¢ãŒããã¯ãã£ã®æŽ»çšã«ãããµããŒããããŸãã
Thanks to BERTâs open-source library, and the incredible AI communityâs efforts to continue to improve and share new BERT models, the future of untouched NLP milestones looks bright.
What will you create with BERT?
Learn how to fine-tune BERT for your particular use case ð€
以äž