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
370
おうちHackを取り入れた リノベーション事例
yusukeito
0
630
Server Side Swiftを しばらく運用してみた話
yusukeito
0
560
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
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
ヤプリ新卒SREの オンボーディング
masaki12
0
130
subpath importsで始めるモック生活
10tera
0
310
イベント駆動で成長して委員会
happymana
1
330
CSC509 Lecture 12
javiergs
PRO
0
160
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
930
CSC509 Lecture 09
javiergs
PRO
0
140
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
120
Contemporary Test Cases
maaretp
0
140
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
110
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
How GitHub (no longer) Works
holman
310
140k
KATA
mclloyd
29
14k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Being A Developer After 40
akosma
87
590k
The World Runs on Bad Software
bkeepers
PRO
65
11k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Facilitating Awesome Meetings
lara
50
6.1k
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ʂ