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
Universal Linksの実装方法と陥りがちな罠
kaitokudou
1
220
WEBエンジニア向けAI活用入門
sutetotanuki
0
300
Server Driven Compose With Firebase
skydoves
0
390
色々なIaCツールを実際に触って比較してみる
iriikeita
0
260
cXML という電子商取引の トランザクションを支える プロトコルと向きあっている話
phigasui
3
2.2k
Why Spring Matters to Jakarta EE - and Vice Versa
ivargrimstad
0
960
offers_20241022_imakiire.pdf
imakurusu
2
360
Android 15 でアクションバー表示時にステータスバーが白くなってしまう問題
tonionagauzzi
0
140
役立つログに取り組もう
irof
26
8.6k
Piniaの現状と今後
waka292
5
1.4k
CSC509 Lecture 08
javiergs
PRO
0
110
AWS IaCの注目アップデート 2024年10月版
konokenj
3
3.1k
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
243
12k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
790
Thoughts on Productivity
jonyablonski
67
4.3k
Imperfection Machines: The Place of Print at Facebook
scottboms
264
13k
Making the Leap to Tech Lead
cromwellryan
132
8.9k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.6k
Six Lessons from altMBA
skipperchong
26
3.5k
The World Runs on Bad Software
bkeepers
PRO
65
11k
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ʂ