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
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.5k
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
890
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
170
イベント駆動で成長して委員会
happymana
1
320
AWS IaCの注目アップデート 2024年10月版
konokenj
3
3.3k
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
Featured
See All Featured
BBQ
matthewcrist
85
9.3k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Scaling GitHub
holman
458
140k
Raft: Consensus for Rubyists
vanstee
136
6.6k
The Cost Of JavaScript in 2023
addyosmani
45
6.7k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Site-Speed That Sticks
csswizardry
0
23
A designer walks into a library…
pauljervisheath
203
24k
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ʂ