Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Swift からword2vecを 使ってみる

Swift からword2vecを 使ってみる

Yusuke Ito

May 26, 2017
Tweet

More Decks by Yusuke Ito

Other Decks in Programming

Transcript

  1. $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
  2. $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)ΫϥΠΞϯτ 
  3. $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͔Β࢝·ΔγΣϧεΫϦϓτͰσϞΛ࣮ߦ 
  4. $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
  5. $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
  6. $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