Upgrade to Pro — share decks privately, control downloads, hide ads and more …

生成AIと自然言語処理の基礎 / 20231111-pyml-niigata-18.pdf

kasacchiful
November 11, 2023

生成AIと自然言語処理の基礎 / 20231111-pyml-niigata-18.pdf

2023-11-11 (土) Python機械学習勉強会 in 新潟 で発表した資料です。

ハンズオン資料:
https://github.com/kasacchiful/pyml-niigata-openai-api-handson

勉強会ページ:
https://pyml-niigata.connpass.com/event/290081/

kasacchiful

November 11, 2023
Tweet

More Decks by kasacchiful

Other Decks in Programming

Transcript

  1. ੜ੒AIͱࣗવݴޠॲཧͷجૅ
    Pythonػցֶशษڧձ in ৽ׁ
    2023-11-11 @kasacchiful

    View full-size slide

  2. Classmethod, Inc.


    Solutions Architect / Software Developer


    AWS Community Builder (Serverless)


    Favorite:


    Community:


    • JAWS-UG Niigata


    • Python ML in Niigata


    • JaSST Niigata


    • ASTER


    • SWANII


    • Cloud
    fl
    are Meetup Niigata


    • etc.


    Hiroshi Kasahara
    @kasacchiful
    @kasacchiful
    2

    View full-size slide

  3. ໨࣍
    • ੜ੒AIʹ͍ͭͯ


    • ࣗવݴޠॲཧͷجૅ


    • ੜ੒AIͱ͏·͘෇͖߹͏ʹ͸ʁ

    View full-size slide

  4. ੜ੒AIʹ͍ͭͯ

    View full-size slide

  5. ੜ੒AIͱ͸Կ͔ʁ
    • ϓϩϯϓτʹԠ౴ͯ͠ςΩετɺը૾ɺ·ͨ͸ଞͷϝσΟΞΛੜ੒͢
    Δ͜ͱ͕Ͱ͖Δਓ޻஌ೳγεςϜͷҰछͰ͋Δɻ
    ग़యIUUQTKBXJLJQFEJBPSHXJLJੜ੒తਓ޻஌ೳ

    View full-size slide

  6. ੜ੒AIͱ͸Կ͔ʁ

    View full-size slide

  7. ੜ੒AIͷ୅දతͳྫ
    • ࣗવݴޠੜ੒


    • ChatGPTͷΑ͏ʹɺਓ͕ؒ࡞ͬͨΑ͏ͳจষΛੜ੒͢Δٕज़


    • ը૾ੜ੒


    • GAN (Generative Adversal Network) ͷΑ͏ͳٕज़Ͱɺೖྗͷը૾͔Β৽͍͠ը૾
    Λੜ੒͢Δٕज़


    • ଞ


    • ʮࣗવݴޠ → ը૾ʯ΍ʮࣗવݴޠ → ࣗવݴޠͱը૾ʯ͕Ͱ͖ΔϞσϧ͕ଘࡏ͢Δɻ

    View full-size slide

  8. ChatGPTͷিܸ
    • 2022೥11݄


    • OpenAI͕ࣾChatGPTΛϦϦʔε


    • ର࿩ͷମݧ͕ඇৗʹྑ͍ͱ࿩
    ୊ʹͳΔ


    • Google → ඇৗࣄଶ(Code
    Red)એݴ


    • Microsoft → ఏܞ & ࣗࣾαʔ
    ϏεऔΓࠐΈ (Bing / Azure)
    ग़యIUUQTQSFTJEFOUKQBSUJDMFT
    • 2023೥3݄


    • ChatGPTͷAPIΛϦϦʔε


    • ར༻ྉ͕҆ՁͳGPT-3.5-Turbo


    • Bot΍ΞϓϦ͕ଓʑϦϦʔε


    • 2023೥3݄


    • GPT-4ΛϦϦʔε


    • ໿100ஹݸͷύϥϝʔλ

    View full-size slide

  9. ଞͷੜ੒AIαʔϏε
    • Bard


    • Google͕ఏڙ͢Δର࿩ܕAIαʔϏε (ChatGPTͷର߅)


    • Claude


    • Anthropic͕ఏڙ͢Δର࿩ܕAIαʔϏε


    • Anthropic͸ݩOpenAIͷϝϯόʔ͕ىۀɻGoogleɺAmazon౳͕ग़ࢿɻ


    • Amazon BedrockͰClaude v2͕ར༻Մೳ


    • Claude v2ͷ೔ຊޠੑೳ͸ɺGPT-4ʹඖఢ͢Δͱ͍ΘΕ͍ͯΔ

    View full-size slide

  10. ੜ੒AIར༻ͷ伴: ϓϩϯϓτ
    • ϓϩϯϓτΤϯδχΞϦϯά


    • ੜ੒AI͔Βద੾ͳग़ྗΛಘΔͨΊͷೖྗ (ϓϩϯϓτ) Λ࠷దԽ͢
    Δख๏

    View full-size slide

  11. ϓϩϯϓτΤϯδχΞϦϯάΨΠυ
    • https://www.promptingguide.ai/jp

    View full-size slide

  12. ChatGPT Prompt Engineering for Developers
    • https://www.deeplearning.ai/short-courses/chatgpt-prompt-
    engineering-for-developers/

    View full-size slide

  13. ϓϩϯϓτͷίπ
    • ໌֬Ͱ۩ମతͳࢦࣔΛॻ͘


    • ໌֬ͳ໾ׂΛॻ͘


    • ۠੾ΓจࣈΛ࢖͏


    • ճ౴ྫΛग़͢


    • ຐ๏ͷݴ༿ʮεςοϓόΠεςοϓͰʯ


    • ճ౴݁Ռͷ௕͞Λࢦఆ͢Δ


    • ୯७ͳ࣭໰ʹ෼͚Δ

    View full-size slide

  14. ϓϩϯϓτͷίπ: ໌֬Ͱ۩ମతͳࢦࣔΛॻ͘
    • ʮ͍ͭɾͲ͜Ͱɾ୭͕ɾԿΛɾͳͥɾͲͷΑ͏ʹɾͲΕ͘Β͍ʯͳͲ


    • ᐆດͳ࣭໰Ͱ΋ճ౴ͯ͘͠ΕΔ͕ɺޡͬͨ݁ՌΛճ౴ͯ͠͠·͏͜ͱ
    ͕ଟ͍ɻ

    View full-size slide

  15. ϓϩϯϓτͷίπ: ໌֬ͳ໾ׂΛॻ͘
    • ಛఆͷ໾ׂΛ༩͑Δͱɺͦͷ໾ׂΛԋͯ͡Ұ؏ੑͷ͋Δճ౴͕ಘΒΕ
    Δɻ


    • ྫ:


    • ͋ͳͨ͸ҰྲྀͷʓʓͰ͢ɻ


    • ωΠςΟϒϨϕϧͷ຋༁ՈͰ͢ɻ


    • Ϊϟϧʹͳͬͯ౴͍͑ͯͩ͘͞ɻ

    View full-size slide

  16. ϓϩϯϓτͷίπ: ۠੾ΓจࣈΛ࢖͏
    • ෳࡶͳϓϩϯϓτΛ಺༰ʹΑͬͯ۠੾Δ


    • ۠੾Γจࣈ͸εϖʔε΍Ҿ༻ූͳͲΛ࢖͏৔߹͕ଟ͍


    • ྫ:


    ҎԼͷจষΛཁ໿ͯ͠Լ͍͞ɻ


    ## จষ


    {͜͜ʹจষΛॻ͘}


    ## ճ౴

    View full-size slide

  17. ϓϩϯϓτͷίπ: ճ౴ྫΛग़͢
    • ͋Β͔͡Ί͍͔ͭ͘ճ౴ྫΛϓϩϯϓτʹॻ͍ͯ͋͛Δ͜ͱͰɺͦͷ಺༰ʹԊͬ
    ͯճ౴ͯ͘͠ΕΔɻ


    • ྫ:


    ରٛޠΛڭ͍͑ͯͩ͘͞ɻΘ͔Βͳ͍৔߹͸ɺΘ͔Βͳ͍ͱ౴͍͑ͯͩ͘͞ɻ


    ࣭໰: େ͖͍ɹճ౴: খ͍͞


    ࣭໰: ߴ͍ɹճ౴: ௿͍


    ࣭໰: ڱ͍ɹճ౴:

    View full-size slide

  18. ϓϩϯϓτͷίπ: ຐ๏ͷݴ༿ʮεςοϓόΠε
    ςοϓͰʯ
    • ܭࢉΛ൐͏έʔεͳͲෳࡶͳϓϩϯϓτͷ৔߹ɺਖ਼͍͠౴͑ʹͳΒͳ͍͜ͱ͕ଟ͍ɻ


    • લड़ͷճ౴ྫΛग़ͯ͋͛͠Δͱਫ਼౓্͕͕Δ͕ɺʮεςοϓόΠεςοϓͰߟ͑ͯΈ
    ·͠ΐ͏ɻʯͱ౤͔͚͛Δ͜ͱͰݴޠϞσϧଆͰॱ൪ʹࢥߟͯ͠ਖ਼͍͠౴͑ʹͳΔ
    έʔε͕ଟ͍ɻ(͜ΕΛ Zero-shot Chain of Thought Prompting ͱݺͿ )


    • ྫ:


    ࢲ͸ࢢ৔ʹߦͬͯ10ݸͷϦϯΰΛങ͍·ͨ͠ɻྡਓʹ2ͭɺमཧ޻ʹ2ͭ౉͠·ͨ͠ɻ
    ͦΕ͔Β5ͭͷϦϯΰΛങͬͯ1ͭ৯΂·ͨ͠ɻ࢒Γ͸ԿݸͰ͔͢ʁεςοϓόΠε
    ςοϓͰߟ͑ͯΈ·͠ΐ͏ɻ

    View full-size slide

  19. ϓϩϯϓτͷίπ: ճ౴݁Ռͷ௕͞Λࢦఆ͢Δ
    • ճ౴ͤ͞Δࡍͷྻڍ਺΍จࣈ਺Λࢦఆ͢Δͱɺճ౴಺༰ͷՄಡੑ্͕
    ͕Δɻ


    • ྫ:


    • ҎԼͷձٞͷٞࣄ࿥Λ200จࣈҎ಺Ͱཁ໿͍ͯͩ͘͠͞ɻ


    • ࣄલʹݕ౼͓ͯ͘͠΂͖͜ͱΛ5ͭ·Ͱग़͍ͯͩ͘͠͞ɻ

    View full-size slide

  20. ϓϩϯϓτͷίπ: ୯७ͳ࣭໰ʹ෼͚Δ
    • ෳࡶͰᐆດͳ࣭໰Ͱ΋ճ౴ͯ͘͠ΕΔ͕ɺ࣭໰಺༰Λ෼ׂ͢Δ͜ͱͰͦͷ಺༰ΛҰͭͣͭճ౴ͯ͠
    ͘ΕΔɻ


    • ྫ:


    • ༑ਓͷ݁ࠗࣜͷ͝ॕّʹ͍ͭͯڭ͍͑ͯͩ͘͞


    • ͝ॕّͷ૬৔͸͍͘ΒͰ͔͢ʁ


    • ࠓճͷέʔεͩͱ͍͘Β͕ଥ౰Ͱ͔͢ʁ


    • ͝ॕّା͸ͲΜͳσβΠϯΛબͿ΂͖Ͱ͔͢ʁ


    • ͝ॕّାʹॻ͘Ѽ໊͸ͲͷΑ͏ʹॻ͘΂͖Ͱ͔͢ʁ


    • ଞʹ஫ҙ఺͸͋Γ·͔͢ʁ

    View full-size slide

  21. ࣗવݴޠॲཧͷجૅ

    View full-size slide

  22. ੜ੒AIʹབྷΉॲཧ


    View full-size slide

  23. ੜ੒AIʹབྷΉॲཧ


    = Embedding

    View full-size slide

  24. Embedding (ຒΊࠐΈ)
    • ςΩετจࣈྻΛɺଟ࣍ݩͷ਺஋ϕΫτϧʹม׵͢Δ͜ͱ


    • ҙຯͷ͍ۙ୯ޠಉ࢜͸ɺޓ͍ʹ͍ۙϕΫτϧ্ۭؒʹ഑ஔ͞ΕΔ͜ͱ
    Ͱɺ͍ۙҙຯͷݕࡧ౳ͰҖྗΛൃش͢Δɻ


    • OpenAI͸ɺݴޠϞσϧͷ܇࿅աఔͰɺେྔͷςΩετσʔλΛ୯ޠ
    ΍จষ͕ͲͷΑ͏ʹؔ࿈͠߹͍ͬͯΔ͔Λֶश͍ͯ͠Δɻ
    (Embeddingͷֶश)
    ͓͸Α͏ → [0.008031543, -0.00587116, … , -0.0040030633]

    View full-size slide

  25. Word2Vec
    • ୯ޠΛϕΫτϧԽ


    • ୯ޠͷҙຯΛఆྔతʹ೺Ѳ͢Δ͜ͱ͕Մೳ


    • ʮԦ༷ʯ-ʮஉੑʯ+ʮঁੑʯ=ʮঁԦʯ


    • Word2VecͷϞσϧ͸ͨ͘͞Μެ։͞Ε͍ͯΔ


    • จষ͔Β୯ޠʹ෼͚Δॲཧ͸ɺผ్ܗଶૉղੳͰʮ෼͔ͪॻ͖ʯΛߦ͏͜ͱ͕
    ଟ͍


    • MeCab / Janome ౳Ͱ࣮ࢪ

    View full-size slide

  26. OpenAIͷEmbedding
    • จষΛʮτʔΫϯʯʹ෼͚Δ


    • ୯ޠ΍۟ಡ఺ͳͲ͕ɺͦΕͧΕҰҙͷ਺஋ID (=τʔΫϯ) ʹม׵


    • ʮτʔΫϯʯ͕ར༻ྉʹؔΘΔ


    • ʮτʔΫϯʯຖʹEmbedding


    • Embeddingࣗମ΋ֶशʹΑͬͯ֫ಘ͍ͯ͘͠


    • Embedding݁ՌͷϕΫτϧΛ࢖ֶͬͯश


    • GPT౳ͷݴޠϞσϧͷֶश

    View full-size slide

  27. ݴޠϞσϧͷத֩: Transformer
    ग़య"TIJTI7BTXBOJ FUBMl"UUFOUJPO*T"MM:PV/FFEz /*14

    IUUQTBSYJWPSHBCT

    View full-size slide

  28. Vector Store
    • ϕΫτϧσʔλΛอଘɾݕࡧ͢ΔͨΊͷσʔλϕʔε


    • େྔͷจষΛEmbedding


    • → େྔͷϕΫτϧσʔλ͕ग़དྷ্͕Δ


    • ۙ೥ɺVector StoreͷαʔϏε͕ଟ͘ొ৔͖͍ͯͯ͠Δ

    View full-size slide

  29. ੜ੒AIͱ͏·͘෇͖߹͏ʹ͸ʁ

    View full-size slide

  30. ݕ౼͢΂͖͜ͱ
    • ϓϩϯϓτɺΊͪΌେࣄ


    • ੜ੒AIར༻ΨΠυϥΠϯΛߟ͑Δ


    • τʔΫϯͷਪఆ


    • OpenAIͷεςʔλενΣοΫ

    View full-size slide

  31. ੜ੒AIར༻ΨΠυϥΠϯ
    • ೔ຊσΟʔϓϥʔχϯάڠձ͕ެ
    ։͍ͯ͠Δ


    • https://www.jdla.org/document/

    View full-size slide

  32. ଞͷձࣾͷΨΠυϥΠϯ΋ࢀߟʹ
    • Ϋϥεϝιου͕ެ։͍ͯ͠Δ


    • https://dev.classmethod.jp/
    articles/guideline-for-use-of-ai-
    services/

    View full-size slide

  33. τʔΫϯͷਪఆ
    • https://platform.openai.com/
    tokenizer


    • Ͳͷ͘Β͍ͷτʔΫϯ͕͔͔Δ͔ਪఆ


    • ར༻ྉ΍rate limitͷࢀߟʹ

    View full-size slide

  34. OpenAIͷεςʔλε
    • OpenAIͷαʔϏε͕མ͍ͪͯΔ
    ͔ͳͱࢥͬͨΒɺ͜͜ΛνΣοΫ


    • https://status.openai.com/

    View full-size slide

  35. ͦΕͰ͸ɺϋϯζΦϯ


    ΍ͬͯΈ·͠ΐ͏

    View full-size slide