iOSエンジニアのためのNLP基礎

9d1961575e45a8286cdde5f86dbba312?s=47 akatsuki174
September 17, 2017

 iOSエンジニアのためのNLP基礎

iOSDC2017での登壇資料です。

9d1961575e45a8286cdde5f86dbba312?s=128

akatsuki174

September 17, 2017
Tweet

Transcript

  1. iOSΤϯδχΞͷͨΊͷ NLPجૅ @akatsuki174

  2. ࣗݾ঺հ • ਢ౻ຘ • iOSΤϯδχΞ • גࣜձࣾZaimॴଐ • iOSDC 2017ίΞελοϑ

    • Twitter, Qiita, SlideShare, Github, SpeakerDeck →akatsuki174
  3. ࠓ೔ͷεϥΠυ ɾSpeakerdeckͷϦϯΫΛઌఔTwitterͰྲྀ͠·ͨ͠ ɾݟͮΒ͍ɺޙͰݟฦ͍ͨ͠౳͕͋Ε͹ͪ͜Βࢀর ɹΑΖ͓͘͠ئ͍͠·͢ ʢ࣌ؒͳ͍ͷͰεϥΠυαΫαΫਐΊ·͢ʣ ΞΧ΢ϯτ͸ @akatsuki174Ͱ͢

  4. ࠓ೔ͷεϥΠυ ※iOS11ͷ࿩΋ग़͖ͯ·͕͢ɺެ։͞Ε͍ͯΔ৘ใΛ ݩʹεϥΠυΛ࡞͍ͬͯ·͢ɻ

  5. ࢲͱࣗવݴޠॲཧ ɾେֶͷଔۀݚڀͰΏΔΏΔ1೥ؒʢॏཁޠ൑ఆʣ ɾ࠷ॳͷձࣾͰ2,3ϲ݄ʢτϐοΫ൑ఆʣ ɾ2ࣾ໨ͰΏΔΏΔยखؒ൒೥ʢݕࡧνϡʔχϯάʣ

  6. ͜ͷηογϣϯͷ໨త ɾNLP API͸ͲͷΑ͏ͳ΋ͷͳͷ͔஌ͬͯ΋Β͏ ɾࣗવݴޠॲཧʹগ͠Ͱ΋ڵຯΛ࣋ͬͯ΋Β͏

  7. ͜ͷηογϣϯͷେ࿮ NLP APIΛઆ໌ͭͭͦ͠ͷཪଆͰ࢖ΘΕ͍ͯΔ ࣗવݴޠॲཧͷٕज़ʹ͍ͭͯ঺հ͠·͢

  8. ͦ΋ͦ΋ࣗવݴޠॲཧͬͯʁ

  9. ࣗવݴޠͱ͸ ʮਓ͕͓ؒޓ͍ʹίϛϡχέʔγϣϯΛߦ͏ͨΊͷ ࣗવൃੜతͳݴޠʯ by Wikipedia 㱻ਓ޻ݴޠʢϓϩάϥϛϯάݴޠ౳ʣͳͲ https://ja.wikipedia.org/wiki/ࣗવݴޠ

  10. ࣗવݴޠॲཧͱ͸ ʮਓ͕ؒ೔ৗతʹ࢖͍ͬͯΔࣗવݴޠΛίϯϐϡʔλʹ ॲཧͤ͞ΔҰ࿈ͷٕज़Ͱ͋Γɺਓ޻஌ೳͱݴޠֶͷҰ෼໺ʯ by Wikipedia https://ja.wikipedia.org/wiki/ࣗવݴޠॲཧ

  11. ࣗવݴޠॲཧͷ׆༻ྫ ɾػց຋༁ ɾ͔ͳ׽ࣈม׵ ɾର࿩γεςϜʢνϟοτϘοτ౳ʣ ɾ৘ใநग़ɺ৘ใݕࡧ

  12. ࣗવݴޠॲཧͷશମ૾ େن໛σʔλ࣌୅ʹٻΊΒΕΔࣗવݴޠॲཧ https://www.slideshare.net/pfi/ss-11474303

  13. ࣗવݴޠॲཧͷશମ૾ େن໛σʔλ࣌୅ʹٻΊΒΕΔࣗવݴޠॲཧ https://www.slideshare.net/pfi/ss-11474303 ΈΜͳͷେ޷͖ͳ ܗଶૉղੳ͸ ୯ޠ෼ׂͷҰ෼໺

  14. ࣗવݴޠॲཧͷશମ૾ େن໛σʔλ࣌୅ʹٻΊΒΕΔࣗવݴޠॲཧ https://www.slideshare.net/pfi/ss-11474303 NLP API͕ѻ͏ ൣғ͸͜͜Β΁Μ

  15. WWDC2017Ͱͷ ηογϣϯ಺༰ʹ͍ͭͯ

  16. [WWDC 2017] Natural Language Processing and your Apps ɾϑΝʔετύʔςΟΞϓϦͰͲͷΑ͏ͳ׆༻͕͞ΕΔ͔ ɾࣗવݴޠॲཧͷجૅతͳઆ໌

    ɾNLP APIͱ͸ ɾNLP API׆༻ྫ ɾNLP APIΛ࢖͏ϝϦοτ ɾσόοά࣌ͷώϯτ
  17. [WWDC 2017] Natural Language Processing and your Apps ɾϑΝʔετύʔςΟΞϓϦͰͲͷΑ͏ͳ׆༻͕͞ΕΔ͔ ɾࣗવݴޠॲཧͷجૅతͳઆ໌

    ɾNLP APIͱ͸ ɾNLP API׆༻ྫ ɾNLP APIΛ࢖͏ϝϦοτ ɾσόοά࣌ͷώϯτ
  18. Natural Language Processing and your Apps / https://developer.apple.com/videos/play/wwdc2017/208/ iMessageΛ։͘ ݻ༗໊ࢺ͕ม׵ީิ

    ʹग़ͯ͜ͳ͍
  19. Natural Language Processing and your Apps / https://developer.apple.com/videos/play/wwdc2017/208/ χϡʔεΞϓϦΛ։͘ ͖ͬ͞ม׵͠Α͏ͱ

    ͨ͠ݻ༗໊ࢺؚ͕·Ε ͍ͯΔχϡʔεΛಡΉ
  20. Natural Language Processing and your Apps / https://developer.apple.com/videos/play/wwdc2017/208/ iMessageʹ໭Δ ͖ͬ͞ग़ͯ͜ͳ͔ͬͨ

    ݻ༗໊ࢺ͕ม׵ ީิʹʂʂ
  21. ͦͷଞηογϣϯ಺༰ʹؔ͢Δ ৄ͍͠৘ใ͸QiitaͰɻ

  22. ͔͜͜Β͸NLP APIʹԊͬͯ ࣗવݴޠॲཧͦͷ΋ͷʹ͍ͭͯ ࿩͍ͨ͠ͱࢥ͍·͢ɻ

  23. NLP APIͷॲཧͷྲྀΕ ݴ ޠ ൑ ఆ τ ʛ Ϋ ϯ

    Խ ඼ ࢺ λ ά ෇ ͚ Ϩ ϯ Ϛ Խ ݻ ༗ ද ݱ ந ग़
  24. NLP APIͷॲཧͷྲྀΕ ݴ ޠ ൑ ఆ τ ʛ Ϋ ϯ

    Խ ඼ ࢺ λ ά ෇ ͚ Ϩ ϯ Ϛ Խ ݻ ༗ ද ݱ ந ग़ ೔ຊޠඇରԠ
  25. NLP APIͷॲཧͷྲྀΕ ݴ ޠ ൑ ఆ τ ʛ Ϋ ϯ

    Խ ඼ ࢺ λ ά ෇ ͚ Ϩ ϯ Ϛ Խ ݻ ༗ ද ݱ ந ग़
  26. ݴޠ൑ఆ ɾԿΛ͢Δʹͯ͠΋ݴޠ͕Θ͔Βͳ͚Ε͹Կ΋Ͱ͖ͳ͍ ɾͦͷͨΊʢݴޠͷ൑ఆ͕ඞཁͳ৔߹͸ʣҰ൪࠷ॳʹ ɹߦΘΕΔλεΫ ɾจࣈN-gramΛ׆༻ͯ͠൑ఆΛߦ͏͜ͱ͕ଟ͍༷ࢠ

  27. N-gramʹΑΔݴޠ൑ఆ ɾݴޠ൑ఆͩͬͯͦΜͳ؆୯͡Όͳ͍ ɾɾಉ͡ޠ೿ɺޠ܈ͷݴޠ͸Α͘ࣅ͍ͯΔ ɾͦ͜ͰN-gramͷొ৔ ɾNจࣈ(or N୯ޠ)͝ͱʹ۠੾Γɺͦͷմ͕ͲͷݴޠͰΑ͘ ɹݟΒΕΔ͔Λ൑ఆʢ㲈෼ྨʣ

  28. จࣈN-gramʹΑΔݴޠ൑ఆͷྫ ɾN = 1 ɹcafé ʢϑϥϯεޠʣ ɹˠ ӳޠʹ͸ʮéʯͱ͍͏දه͸ͳ͍͔Β… etc ɾN

    = 2 ɹthe peopleʢӳޠʣɹ ɹˠʮthʯͱ͍͏ฒͼ͸ӳޠʹଟ͍͕υΠπޠʹ͸গͳ͘… etc
  29. iOSʹ͓͚Δݴޠ൑ఆ iOS11Ͱ৽ొ৔ ݴޠίʔυͷจࣈྻͰग़ྗ͞ΕΔ

  30. ɾʮHelloʯͱ͍͏จࣈΛݴޠ൑ఆ͢Δͱ”it”͕ฦͬͯ͘Δ ɾɾ͔͠͠”en”ͱ͍͏Մೳੑ΋͋Γ͏Δ ↓ ༧Ίݴޠ͕Θ͔͍ͬͯΔͳΒͪ͜Β͔ΒݴޠΛࢦఆͯ͠ ͋͛ͨํ͕ྑ͍ ؾΛ͚ͭΔ΂͖͜ͱ

  31. NLP APIͷॲཧͷྲྀΕ ݴ ޠ ൑ ఆ τ ʛ Ϋ ϯ

    Խ ඼ ࢺ λ ά ෇ ͚ Ϩ ϯ Ϛ Խ ݻ ༗ ද ݱ ந ग़
  32. ʮτʔΫϯʯʮτʔΫϯԽʯ ɾτʔΫϯʢ㲈ࣈ۟ʣ ɹςΩετதͷ୯ޠͱ۟ಡ఺ͷ͜ͱ ɾτʔΫϯԽʢ㲈ࣈ۟ղੳʣʢ㱭 ܗଶૉղੳʣ ɹࣗવݴޠ΍ϓϩάϥϛϯάݴޠͳͲͷจࣈྻΛղੳͯ͠ ɹτʔΫϯΛಘΔ͜ͱ ɹ˞ܗଶૉղੳͷղੳର৅͸ࣗવݴޠͷΈ

  33. iOSʹ͓͚ΔτʔΫφΠζ

  34. ೔ຊޠʹ΋௅ઓʂ

  35. ·͋͜Μͳ͜ͱ΋͋ΔΑͶ…ʁ

  36. ࡶஊɿίϯύΠϥ͕ίʔυΛʮཧղʯ͢Δʹ͸ ࣈ۟ղੳɺߏจղੳɺ࣮ߦίʔυੜ੒ͳͲͷաఔΛܦͯ ίϯύΠϥ͸ίʔυΛղऍ͢Δ

  37. ࡶஊɿίϯύΠϥ͕ίʔυΛʮཧղʯ͢Δʹ͸ ࣈ۟ղੳͷաఔͰ͸ιʔείʔυΛϓϩάϥϜ্ͷ ࠷খ୯Ґʢҙຯͷ͋Δ୯Ґʣʹ෼ׂ͢Δ ྫɿwhile (abc < 10) { abc +=

    1 } (͜ͷྫจڐ͍ͯͩ͘͠͞) while / ( / abc / < / 10 / ) / { / abc / += / 1 / } /* hoge */ ͳͲͷίϝϯτ΋Ұմͱͯ͠ѻ͏
  38. ࡶஊɿίϯύΠϥ͕ίʔυΛʮཧղʯ͢Δʹ͸ ߏจղੳͷաఔͰ͸ɺ༩͑ΒΕͨτʔΫϯྻ͔Βߏจنଇʹ ͕ͨͬͯ͠ߏจΛղੳ͢Δ 1 + 3 * ( 9 -

    3 ) + - *
  39. NLP APIͷॲཧͷྲྀΕ ݴ ޠ ൑ ఆ τ ʛ Ϋ ϯ

    Խ ඼ ࢺ λ ά ෇ ͚ Ϩ ϯ Ϛ Խ ݻ ༗ ද ݱ ந ग़
  40. ඼ࢺλά෇͚ ɾ୯ޠʹରͯ͠඼ࢺΛ͚͍ͭͯ͘͜ͱ ɾ׆༻ྫʢࣙॻΞϓϦʣɿςΩετதͷ͋Δ୯ޠ͕ ɹಈࢺͳͷ໊͔ࢺͳͷ͔͕Θ͔͍ͬͯΕ͹ ɹΑΓద੾ͳ༁ΛৼΔ͜ͱ͕Ͱ͖Δɹ

  41. ͲͷΑ͏ʹ඼ࢺΛܾఆͯ͠Δʁ ɾܗଶૉతͳख͕͔Γ͔Β ɹhappiness → ܗ༰ࢺ, establishment → ໊ࢺ ɾ౷ޠʢ㲈ߏจʣతͳख͕͔Γ͔Β ɹӳޠͰ͸ܗ༰ࢺ͸໊ࢺͷ௚લɺbeಈࢺͷ௚ޙʹஔ͔ΕΔ

    ɹ͜ͱ͕ଟ͍ɺͳͲ ɾҙຯతͳख͕͔Γ͔Β ɹ໊ࢺͱ͸ɺਓɺ৔ॴɺ෺ࣄͷ໊લͰ͋ΔɺͳͲ
  42. iOSʹ͓͚Δλά෇͚

  43. NLP APIͷॲཧͷྲྀΕ ݴ ޠ ൑ ఆ τ ʛ Ϋ ϯ

    Խ ඼ ࢺ λ ά ෇ ͚ Ϩ ϯ Ϛ Խ ݻ ༗ ද ݱ ந ग़
  44. ϨϯϚԽ ࣙॻͷݟग़͠ޠΛநग़͢Δॲཧ ྫɿpresided → presideʢաڈܗ͔Βݱࡏܗ΁ʣ ɹɹhours → hourʢෳ਺ܗ͔Β୯਺ܗ΁ʣ

  45. iOSʹ͓͚ΔϨϯϚԽ աڈܗ͔Βݱࡏܗʹͳ͍ͬͯΔ খจࣈʹͳ͍ͬͯͳ͍

  46. NLP APIͷॲཧͷྲྀΕ ݴ ޠ ൑ ఆ τ ʛ Ϋ ϯ

    Խ ඼ ࢺ λ ά ෇ ͚ Ϩ ϯ Ϛ Խ ݻ ༗ ද ݱ ந ग़
  47. ݻ༗දݱநग़ ɾݻ༗໊ࢺʢਓ໊ɺ஍໊౳ʣɺ࣌ؒදݱʢ೔෇ɺ࣌ࠁʣͳͲ ɹΛςΩετ͔Βநग़͢Δٕज़ ɾςΩετʹ͓͍ͯݻ༗දݱ͸ॏཁ৘ใͳͷͰ ɹ৘ใநग़΍νϟοτϘοτͳͲͷର࿩γεςϜʹ͓͍ͯ ɹ׆༻͞Ε͍ͯΔ

  48. ݻ༗දݱநग़ͷख๏ ɾ஌ࣝϕʔεख๏ ɾ౷ܭతख๏

  49. ஌ࣝϕʔεख๏ ɾنଇʢύλʔϯʣΛਓखͰ࡞੒͠ɺͦΕʹ౰ͯ͸·Δ ɹ΋ͷΛநग़͢Δ ɹྫɿ໊ࢺʴʮ͞Μʯˠਓ໊ ɹɹɹ໊ࢺʴʮࢢʯˠ஍໊ ɾنଇΛ໢ཏతʹߏங͠Α͏ͱ͢Δͱലେͳίετ͕͔͔Δ

  50. ౷ܭతख๏ ɾڭࢣ͋ΓֶशΛͤ͞ɺநग़نଇΛࣗಈֶश͢ΔΑ͏ʹ͢Δ ɾSVMʢSupport Vector Machine / ࣝผؔ਺ʣ΍CRF ɹʢConditional Random Fields

    / ࣝผϞσϧʣ͕༗໊
  51. iOSʹ͓͚Δݻ༗දݱநग़ joinNamesΛઃఆ͍ͯ͠ΔͷͰ ෳ߹ޠͰ΋நग़Մʂ

  52. ·ͱΊ

  53. ·ͱΊ ɾNLP API͸ཪଆͷࣗવݴޠॲཧΛҙࣝ͠ͳͯ͘΋खܰʹ ɹ࢖͏͜ͱ͕Ͱ͖Δ ɾࣗવݴޠॲཧ͸Ԟਂָ͍ͯ͘͠ʂʂʂ

  54. ิ଍ɿؔ࿈ࢿྉҰཡ ɾNLP APIͰ͍Ζ͍Ζࢼͯ͠Έͨʢۙ೔ެ։ʣ ɹʢNDAͷؔ܎Ͱʣ ɾNatural Language APIͱͦͷཪଆΛ೷͘[׬શ൛] https://speakerdeck.com/akatsuki174/natural-language- apitosofalseli-ce-wosi-ku-wan-quan-ban ɾࣗવݴޠॲཧͱΞϓϦ

    http://qiita.com/akatsuki174/items/9f273ecfd29245a9f39d
  55. ऴΘΓɻ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ ͋ͱɺϦδΣΫτίϯདྷͯͶɻ

  56. དྷͦ͏ͳ࣭໰ͱճ౴ ※͋͘·Ͱ΋ࢲͷ༧૝ͱߟ͑Ͱ͋Γɺ ճ౴ͷਖ਼֬ੑ͸อূ͠·ͤΜɻ

  57. NLP APIͲ͜Ͱ࢖͏ͷʁ ͍͍࣭໰Ͱɺ೉͍࣭͠໰Ͱ͢Ͷɻ ͿͬͪΌ͚ϩʔΧϧͰࣗવݴޠॲཧΛ΍Δ৔໘͸ͦΜͳ ͳ͍ͱࢥ͍·͢ɻ Ͱ͕͢ɺ͋͑ͯڍ͛Δͱͨ͠Β࣍ͷϝϦοτ͕͋Δͱࢥ͍· ͢ɻ

  58. ϩʔΧϧͰNLPΛ΍ΔϝϦοτ ɾΦϑϥΠϯͰ΋࢖͑Δ ɾɾจষೖྗ͕සൟʹൃੜ͢ΔΞϓϦͳΒ಺෦ʹࣙॻ࣋ͬͯ ɹɹNLP APIΛ࢖ͬͯ΋͍͍͔΋ ɾɾݴޠ൑ఆ͔͠࢖Θͳ͍৔໘ͳΒɺΘ͟Θ͟αʔόαΠυ ɹɹ͔Βݺ͹ͳ͍͍ͯ͘ͷ͸ྑ͍…͔΋ʁ ɾΩʔϘʔυΞϓϦͳΒࠓ·ͰΑΓॲཧָʹॻ͚Δ͔΋ʁ

  59. ߟ͑ΔͳɺՄೳੑΛײ͡Ζ i M e s s a g e N

    e w s NLPͰॲཧͨ͠΋ͷΛڞ༗͢Δ෦෼
  60. ߟ͑ΔͳɺՄೳੑΛײ͡Ζ i M e s s a g e N

    e w s NLPͰॲཧͨ͠΋ͷΛڞ༗͢Δ෦෼ y o u r a p p