Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Swift からword2vecを 使ってみる
Search
Yusuke Ito
May 26, 2017
Programming
0
1k
Swift からword2vecを 使ってみる
Yusuke Ito
May 26, 2017
Tweet
Share
More Decks by Yusuke Ito
See All by Yusuke Ito
Macとオーディオ再生 2024/11/02
yusukeito
0
150
おうちHackを取り入れた リノベーション事例
yusukeito
0
620
Server Side Swiftを しばらく運用してみた話
yusukeito
0
550
Swift Outside the Box
yusukeito
1
2.4k
SwiftでgRPCとProtocolBuffersを使う
yusukeito
4
1.3k
Swift on Raspberry Pi でI2Cデバイスを使う
yusukeito
1
640
Isomorphic Swift
yusukeito
2
580
Swiftの値付きEnumをHackする
yusukeito
0
290
Swift プロトコル指向なCのラッパーを作る
yusukeito
3
1.3k
Other Decks in Programming
See All in Programming
約9000個の自動テストの 時間を50分->10分に短縮 Flakyテストを1%以下に抑えた話
hatsu38
23
11k
Tuning GraphQL on Rails
pyama86
2
1k
Piniaの現状と今後
waka292
5
1.4k
役立つログに取り組もう
irof
26
8.6k
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
910
Outline View in SwiftUI
1024jp
1
110
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
480
cXML という電子商取引の トランザクションを支える プロトコルと向きあっている話
phigasui
3
2.2k
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
210
Vitest Browser Mode への期待 / Vitest Browser Mode
odanado
PRO
2
1.7k
Kotlin2でdataクラスの copyメソッドを禁止する/Data class copy function to have the same visibility as constructor
eichisanden
1
130
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
7
2.8k
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
41
2.1k
Testing 201, or: Great Expectations
jmmastey
38
7k
[RailsConf 2023] Rails as a piece of cake
palkan
51
4.9k
Navigating Team Friction
lara
183
14k
BBQ
matthewcrist
85
9.3k
Designing the Hi-DPI Web
ddemaree
280
34k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
A Modern Web Designer's Workflow
chriscoyier
692
190k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Making Projects Easy
brettharned
115
5.9k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Rails Girls Zürich Keynote
gr2m
93
13k
Transcript
$PQZSJHIU4IJSPZBHJ$PSQPSBUJPO"MMSJHIUTSFTFSWFE 4XJGU͔ΒXPSEWFDΛ ͬͯΈΔ ϦʔυΞʔΩςΫτ ҏ౻༞ี :VTVLF*UP !OPWJ@ നϠΪίʔϙϨʔγϣϯ 5PLZP4FSWFS4JEF4XJGU.FFUVQ
5PLZP݄ʙ
$PQZSJHIU4IJSPZBHJ$PSQPSBUJPO"MMSJHIUTSFTFSWFE 4FF63- • https://github.com/shiroyagicorp/swift-seeurl • ݩʑࣾϥΠϒϥϦΛެ։ • cURL(curlίϚϯυ), libcurlϕʔε •
ಉظॲཧ(RunLoopෆཁ) let result = try HTTPClient.sendRequest("GET", "https://google.com") print(result.statusCode, result.body) ϑΥϩʔΞοϓهࣄUSZ4XJGU5PLZPͱͦͷޙ IUUQBJBMTIJSPZBHJDPKQNZUSZTXJGUBOEGPMMPXVQ
$PQZSJHIU4IJSPZBHJ$PSQPSBUJPO"MMSJHIUTSFTFSWFE ϝϯςφϯε͍ͯ͠ΔϥΠϒ ϥϦ • novi/mysql-swift: MySQLΫϥΠΞϯτ (όΠϯσΟϯά) • novi/nkf-swift: Network
Kanji FilterͷόΠϯσΟϯά • novi/mecab-swift: MeCabܗଶૉղੳͷόΠϯσΟϯά • novi/i2c-swift: I2CόεϥΠϒϥϦ • shiroyagicorp/swift-seeurl: cURL(HTTPS)ΫϥΠΞϯτ
None
$PQZSJHIU4IJSPZBHJ$PSQPSBUJPO"MMSJHIUTSFTFSWFE OVNTX • https://github.com/sonsongithub/numsw • try! Swift TokyoͷϋοΧιϯͰ࡞ͬͨ • Pythonʹ͋ΔܭࢉϥΠϒϥϦ(numsw)ΛSwift
Ͱ͍͍ͨ • ࠓͨ·ʹϝϯςφϯε͍ͯ͠Δ
$PQZSJHIU4IJSPZBHJ$PSQPSBUJPO"MMSJHIUTSFTFSWFE XPSEWFD • 2013͘Β͍ʹެ։ • C࣮ • word2vecͷίϯηϓτ͜ͷล • https://deepage.net/bigdata/machine_learning/
2016/09/02/ word2vec_power_of_word_vector.html
$PQZSJHIU4IJSPZBHJ$PSQPSBUJPO"MMSJHIUTSFTFSWFE XPSEWFDͷιʔείʔυ • https://code.google.com/archive/p/word2vec/ • ͕ͩɺGoogle Codeऴྃʹ͍μϯϩʔυͰ͖ͳ͍ • https://github.com/svn2github/word2vec.git •
͜ͷลͷϛϥʔΛ͏ • make Ͱ࣮ߦϑΝΠϧΛϏϧυ • macOSͩͱmalloc.hϔομʔ͕ແ͍ͱ͍͏Τϥʔ͕ग़ΔͷͰɺͦͷߦ Λίϝϯτ͢Δ • demo-*.sh͔Β࢝·ΔγΣϧεΫϦϓτͰσϞΛ࣮ߦ
$PQZSJHIU4IJSPZBHJ$PSQPSBUJPO"MMSJHIUTSFTFSWFE XPSEWFDD • ςΩετϑΝΠϧΛೖྗͯ͠ɺτϨʔχϯάɺϞσ ϧΛग़ྗ • Cݴޠ 700ߦఔͷ CLI •
ϚϧνεϨουରԠ • ίʔυ͕ಡΈʹ͍͘
$PQZSJHIU4IJSPZBHJ$PSQPSBUJPO"MMSJHIUTSFTFSWFE EJTUBODFD • ϞσϧϑΝΠϧͱ୯ޠ(ෳ)Λೖྗͯ͠ɺίαΠϯ ྨࣅ(ίαΠϯڑ)Λܭࢉͯ͠ग़ྗ Enter word or sentence
(EXIT to break): cat dog Word Cosine distance ------------------------------------------------------------------------ goat 0.827205 cow 0.796463 bee 0.788516 blonde 0.784559 hamster 0.784402 ass 0.779677 rat 0.774975
$PQZSJHIU4IJSPZBHJ$PSQPSBUJPO"MMSJHIUTSFTFSWFE 4XJGU͔Β࣮ߦ͢Δʹ 1. .cͷιʔεΛSwift͔ΒݺͿ • ͍ͭͷCͷϥΠϒϥϦΛSwift͔ΒಡΈࠐΉํ๏ • ࠓճϥΠϒϥϦͰͳ͘ɺmain()ͷܗʹͳͬͯ ͍ΔͷͰɺϥούʔؔͳͲΛఆٛ 2.
͕ΜͬͯSwiftʹҠ২
$PQZSJHIU4IJSPZBHJ$PSQPSBUJPO"MMSJHIUTSFTFSWFE ϞσϧϑΝΠϧ • ୯ޠͷϦετ(char*)ͱ୯ޠΠϯσοΫε(Int) • ୯ޠΠϯσοΫεͱ୯ޠϕΫτϧ(Float) • σϞͩͱαΠζ͕30ϝΨόΠτ͋Δ m0
m1 m2 i0 the -0.455356 1.908487 1.365852 i1 of 0.266191 1.750760 0.486601 i2 and 0.889470 1.455499 0.380907 i3 one -2.213606 0.914580 -0.512441
$PQZSJHIU4IJSPZBHJ$PSQPSBUJPO"MMSJHIUTSFTFSWFE EJTUBODFDͷΔ͜ͱ • ϞσϧΛύʔεͯ͠ڊେͳ(30MBఔͷ)ϝϞϦ্ʹಡΈࠐΉ • ͋Β͔͡Ί୯ޠͱ୯ޠΠϯσοΫεʹ͚Δ • ୯ޠΠϯσοΫεͱ୯ޠϕΫτϧΛϝϞϦ্ʹಡΈࠐΉ • ༩͑ΒΕͨɺ୯ޠʹରͯ͠ɺ୯ޠϕΫτϧ͔ΒίαΠϯڑ
Λܭࢉͭͭ͠ɺڑ͕͍ۙͷΛιʔτͯ͠ग़ྗ(දࣔ) • https://ja.stackoverflow.com/questions/2001/word2vecͷ distanceͳͥߴʹಈ࡞͢Δͷ͔
$PQZSJHIU4IJSPZBHJ$PSQPSBUJPO"MMSJHIUTSFTFSWFE 4XJGUʹҠ২ • Ϟσϧ(୯ޠϕΫτϧ)ΛಡΈࠐΉϝϞϦۭؒ UnsafeMutablePointer<Float>.allocate(capacity:) Λ༻ • Swift3͔Βಋೖ͞ΕͨϙΠϯλͱϝϞϦۭؒΛ҆શʹޮతʹ ѻ͏Έ(݁ߏ͍͠) •
ૉΒ͍͠SwiftͷϙΠϯλܕͷղઆ: http://qiita.com/ omochimetaru/items/c95e0d36ae7f1b1a9052 • UnsafeRawPointer Migration: https://swift.org/migration- guide/se-0107-migrate.html
$PQZSJHIU4IJSPZBHJ$PSQPSBUJPO"MMSJHIUTSFTFSWFE ͬͨ͜ͱ • ୯ޠͱ୯ޠΠϯσοΫεͷରԠΛྻͰͳࣙ͘ॻʹมߋ • จࣈྻͷѻ͍ΛStringωΠςΟϒʹมߋ • ݩʑchar*strcmpͳͲͷCϨϕϧͩͬͨͷͰɺՄಡੑ ѻ͍͕େม •
(͓ͦΒ͘)ɺϢχίʔυͷରԠ͕Մೳ • (·͍ͩͬͯͳ͍͕)ɺιʔτपΓͷվળ
$PQZSJHIU4IJSPZBHJ$PSQPSBUJPO"MMSJHIUTSFTFSWFE ࠓճͷϦϙδτϦ • https://github.com/novi/word2vec-swift
$PQZSJHIU4IJSPZBHJ$PSQPSBUJPO"MMSJHIUTSFTFSWFE ·ͱΊ • C͔ΒͷҠ২ָ • ߏจ͍ۙ • ϙΠϯλपΓಉ͡Έ͕͑Δ • word2vecʹ͍ͭͯΑ͘ཧղͰ͖ͯΕ͞Βʹ༰қ
$PQZSJHIU4IJSPZBHJ$PSQPSBUJPO"MMSJHIUTSFTFSWFE • ࣍ճ: നϠΪͰӡ༻͍ͯ͠ΔαʔόʔαΠυSwift • ൃදऀืूʂτϐοΫͳΜͰOKʂ