Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
word2vec accuracy
Search
asako
August 16, 2016
Programming
78
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
word2vec accuracy
refer:
https://speakerdeck.com/asakoraven/word2vec
asako
August 16, 2016
More Decks by asako
See All by asako
quantum computer
asakoraven
0
54
Introduce Jupyter Notebook
asakoraven
0
34
Load csv by Cypher
asakoraven
0
49
Query by cypher
asakoraven
0
23
time series database
asakoraven
0
31
word2vec
asakoraven
0
42
Other Decks in Programming
See All in Programming
AmebaブログはKMPから卒業します
kmars0605
0
190
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
1.1k
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
5
5.1k
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
120
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
390
パスワード再設定メールのURLについて知っておこう
uyuki234
0
160
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
150
AWSに止められる覚悟してますか?
morizo_1984
2
540
Optunaを作ったときにやりたかったこと、その後 (2026/10/16, Optuna Meetup #3)
iwiwi
1
440
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
2
710
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
380
JIS keyboard support in Omarchy
lef237
0
120
Featured
See All Featured
GitHub's CSS Performance
jonrohan
1033
470k
Technical Leadership for Architectural Decision Making
baasie
3
600
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
480
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
360
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
600
[RailsConf 2023] Rails as a piece of cake
palkan
59
7.1k
Writing Fast Ruby
sferik
630
63k
Docker and Python
trallard
47
4.2k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
220
Producing Creativity
orderedlist
PRO
348
41k
Between Models and Reality
mayunak
4
500
Transcript
word2vec accuracy A report by Asako TOYAMA
demo-word-accuracy.sh make if [ ! -e text8 ]; then wget
http://mattmahoney.net/dc/text8.zip -O text8.gz gzip -d text8.gz -f fi time ./word2vec -train text8 -output vectors.bin -cbow 1 -size 200 -window 8 -negative 25 -hs 0 -sample 1e-4 -threads 20 -binary 1 -iter 15 ./compute-accuracy vectors.bin 30000 < questions-words.txt # to compute accuracy with the full vocabulary, use: ./compute-accuracy vectors.bin < questions-words.txt
text8 Word2vecに同封されているデータセット オリジナルは以下のページにある http://mattmahoney.net/dc/textdata 英単語 約 17,000,000 words
accuracy (text8) $ ./compute-accuracy vectors.bin < questions-words.txt capital-common-countries: ACCURACY TOP1:
80.04 % (405 / 506) Total accuracy: 80.04 % Semantic accuracy: 80.04 % Syntactic accuracy: nan % capital-world: ACCURACY TOP1: 48.26 % (1720 / 3564) Total accuracy: 52.21 % Semantic accuracy: 52.21 % Syntactic accuracy: nan % currency: ACCURACY TOP1: 21.81 % (130 / 596) Total accuracy: 48.33 % Semantic accuracy: 48.33 % Syntactic accuracy: nan % city-in-state: ACCURACY TOP1: 44.59 % (1039 / 2330) Total accuracy: 47.08 % Semantic accuracy: 47.08 % Syntactic accuracy: nan % family: ACCURACY TOP1: 59.05 % (248 / 420) Total accuracy: 47.76 % Semantic accuracy: 47.76 % Syntactic accuracy: nan %
compute-accuracy を⽇本語デ ータに適⽤して確認してみたい。 Next try
questions-japanese-words.txtΛ࡞Δ questions-words.txt の 以下のカテゴリだけ機械翻訳にかけ、⽇本語単語に置換 •capital-common-countries •capital-world •familyカテゴリを機械翻訳かけた後、追加編集し、英語定義削除 city-in-state(japanese)カテゴリ追加(47都道府県の記述追加) japanese-synonymカテゴリ追加(語彙については要検討) japanese-adjectiveカテゴリ追加(語彙については要検討)
questions-japanese-words.txtʢଓ͖ʣ 以下のカテゴリはとりあえず、英語のまま残しておく。(あまり、意味がないが) •gram1-adjective-to-adverb •gram2-opposite •gram3-comparative •gram4-superlative •gram5-present-participle •gram6-nationality-adjective •gram7-past-tense •gram8-plural
•gram9-plural-verbs
KB8JLJͰ࣮ࢪͯ͠ΈΔ ja wiki dump https://dumps.wikimedia.org/jawi/latest/
Wikipedia Extractor http://medialab.di.unipi.it/wiki/Wikipedia_Extractor https://github.com/attardi/wikiextractor Wiki のデータからテキストのみを抽出するスクリプト $ ./WikiExtractor.py -b 500k
-o extracted jawiki-latest-pages-articles.xml.bz2
Wikipedia Extractor ⽣成されたファイルの中⾝はこんな感じ。<doc>タグだけ残る。 <doc id="3455820" url="https://ja.wikipedia.org/wiki?curid=3455820" title="ߦಙϞεΫ"> ߦಙϞεΫ ߦಙϞεΫ·ͨ ώϥɾϚεδυʢ
ʣɺઍ༿ݝࢢࢢߦಙӺલʹॴࡏ͢ΔϞεΫɻ1997ʹݐͯΒΕͨɻΠεϥϛοΫɾαʔΫϧɾΦϒɾδϟύϯ ʢICOJʣͷҰ෦ہͰ͋ΔຊϞεΫϑΝϯσʔγϣϯʢJMFʣʹΑͬͯӡӦ͞Ε͍ͯΔɻ ຊޠදهʹ͍ͭͯʮώϥϚεδουʯʢ ) ͷ΄͔ɺʮߦಙϞεΫʯ ͱ༻͍ΒΕΔɻ ϞεΫɺ࣍ͷجຊతͳαʔϏεΛఏڙ͍ͯ͠Δ ݐ̐֊ݐͯͰɺ ֤֊ͷׂΓͯɺҎԼͷ௨ΓͰ͋Δɻ ࠷دΓӺ౦ژϝτϩ౦ઢߦಙӺɻ(ెาͰ7) </doc>
Wikipedia Extractor WikiExtractor.py は <doc>タグだけ残るので <doc>タグを削除するスクリプトを作成
wakati Word Extractorの出⼒は500K毎の出⼒に分割してしまったので、これを word2vec⽤にひとつのファイルにまとめる。 $ python a.py extracted/*/* | ¥
mecab -b 1000000 ¥ -F"%f[6] " -U"%m " -E"\n" ¥ -d /usr/local/lib/mecab/dic/mecab-ipadic-neologd ¥ > ./jawiki-wakati.txt
jawiki-watati.txt $ ls -lh jawiki-wakati.txt -rw-r--r-- 1 asako staff 2.5G
8 7 14:35 jawiki-wakati.txt $ wc jawiki-wakati.txt 7543274 417027641 2706398402 jawiki-wakati.txt
word2vec $ ./word2vec -train ./data/jawiki-wakati.txt -output jawiki.bin -size 200 -window
8 -negative 25 -hs 0 -sample 1e-4 -thread 2 -binary 1 -iter 15
accuracy (jawiki) $ ./compute-accuracy jawiki.bin < ./questions-japanese-words.txt capital-common-countries(japanese): ACCURACY TOP1:
57.05 % (2485 / 4356) Total accuracy: 57.05 % Semantic accuracy: 57.05 % Syntactic accuracy: nan % currency(english): ACCURACY TOP1: 1.33 % (5 / 375) Total accuracy: 52.63 % Semantic accuracy: 52.63 % Syntactic accuracy: nan % city-in-state(english): ACCURACY TOP1: 13.24 % (281 / 2122) Total accuracy: 40.43 % Semantic accuracy: 40.43 % Syntactic accuracy: nan % city-in-state(japanese): ACCURACY TOP1: 84.18 % (1820 / 2162) Total accuracy: 50.93 % Semantic accuracy: 50.93 % Syntactic accuracy: nan % family(japanese): ACCURACY TOP1: 50.99 % (258 / 506) Total accuracy: 50.93 % Semantic accuracy: 50.93 % Syntactic accuracy: nan % gram1-adjective-to-adverb: ACCURACY TOP1: 0.00 % (0 / 272) Total accuracy: 49.51 % Semantic accuracy: 50.93 % Syntactic accuracy: 0.00 % gram2-opposite:
updated filter script again <doc>タグを削除 <br>タグを削除 formula_1 や codice_1など数式のリンク⽂字を削除 品詞判定を実施
助詞、助動詞、記号、フィラー、その他に分類される品詞を削除 使⽤辞書の品詞分類はこちらのページ(http://www.unixuser.org/%7Eeuske/doc/postag/#chasen) 適当にstop word (てる, いる, なる, れる, する, ある)を拾い出し、stop word排除を実施
wakati with new filter script again Word Extractorの出⼒は500K毎の出⼒に分割してしまったので、これを word2vec⽤にひとつのファイルにまとめる。 $
python c.py ./extracted/*/* > ./jawiki-wakati.c.py.txt
jawiki-wakati.c.py.txt $ ls -lh jawiki-wakati.c.py.txt -rw-r--r-- 1 asako staff 1.6G
8 31 10:01 jawiki-wakati.c.py.txt $ wc jawiki-wakati.c.py.txt 7514452 223030315 1759604245 jawiki-wakati.c.py.txt
word2vec with new filter script (c.py) $ ./word2vec -train ./data/jawiki-wakati.c.py.txt
-output jawiki.c.py.bin -size 200 -window 8 -negative 25 -hs 0 -sample 1e-4 -thread 2 -binary 1 -iter 15
accuracy (jawiki.c.py.bin) $ ./compute-accuracy jawiki.c.py.bin < ./questions-japanese-words.txt capital-common-countries(japanese): ACCURACY TOP1:
59.93 % (2610 / 4355) Total accuracy: 59.93 % Semantic accuracy: 59.93 % Syntactic accuracy: nan % currency(english): ACCURACY TOP1: 0.53 % (2 / 375) Total accuracy: 55.22 % Semantic accuracy: 55.22 % Syntactic accuracy: nan % city-in-state(english): ACCURACY TOP1: 14.75 % (313 / 2122) Total accuracy: 42.69 % Semantic accuracy: 42.69 % Syntactic accuracy: nan % city-in-state(japanese): ACCURACY TOP1: 87.23 % (1886 / 2162) Total accuracy: 53.37 % Semantic accuracy: 53.37 % Syntactic accuracy: nan % family(japanese): ACCURACY TOP1: 52.17 % (264 / 506) Total accuracy: 53.31 % Semantic accuracy: 53.31 % Syntactic accuracy: nan % gram1-adjective-to-adverb: ACCURACY TOP1: 0.37 % (1 / 272) Total accuracy: 51.84 % Semantic accuracy: 53.31 % Syntactic accuracy: 0.37 % gram2-opposite:
ωοτͷهࣄݟ͚ͭΔ http://qiita.com/HirofumiYashima/items/398db35da4d422e70c5f ⾃分で論⽂読めよ!とも、思うが、気⼒がない。 1. コーパスの単語数が多けれは多いほど、モデルの次元数が⼤きければ⼤きいほど、意味演算の正確性 の精度は⾼まる。(モデルの次元数が⼤きい場合は、コーパスサイズも相応にないと精度は落ちる) 2. ⽂法的 ( Syntactic
)には、 NNLM が、意味的 ( Semantic ) には Skip-gram が精度が⾼い 3.コーパスのサイズが2倍になれば、モデルの次元数も2倍にするべきである
TJ[FύϥϝʔλΛ૿ͯ͠ɺͬͯΈΔ
word2vec with c.py, size 400 $ ./word2vec -train ./data/jawiki-wakati.c.py.txt -output
jawiki.c.py.size.400.bin - size 400 -window 8 -negative 25 -hs 0 -sample 1e-4 -thread 2 -binary 1 -iter 15
accuracy (jawiki.c.py.size.400.bin) $ ./compute-accuracy jawiki.c.py.size.400.bin < ./questions-japanese-words.txt capital-common-countries(japanese): ACCURACY TOP1:
58.14 % (2532 / 4355) Total accuracy: 58.14 % Semantic accuracy: 58.14 % Syntactic accuracy: nan % currency(english): ACCURACY TOP1: 0.27 % (1 / 375) Total accuracy: 53.55 % Semantic accuracy: 53.55 % Syntactic accuracy: nan % city-in-state(english): ACCURACY TOP1: 14.84 % (315 / 2122) Total accuracy: 41.56 % Semantic accuracy: 41.56 % Syntactic accuracy: nan % city-in-state(japanese): ACCURACY TOP1: 87.23 % (1886 / 2162) Total accuracy: 52.52 % Semantic accuracy: 52.52 % Syntactic accuracy: nan % family(japanese): ACCURACY TOP1: 53.36 % (270 / 506) Total accuracy: 52.56 % Semantic accuracy: 52.56 % Syntactic accuracy: nan % gram1-adjective-to-adverb: ACCURACY TOP1: 0.00 % (0 / 272) Total accuracy: 51.10 % Semantic accuracy: 52.56 % Syntactic accuracy: 0.00 % gram2-opposite:
ຊޠͷΈͷධՁ ja wiki (۟ಡͷআʣ ja wiki ʢॿࢺɺॿಈࢺͷআʣ ja wiki ʢॿࢺɺॿಈࢺͷআʣ
࣍ݩ 200࣍ݩ 200࣍ݩ 400࣍ݩ ୯ޠ 417,027,641 words 223,030,315 words 223,030,315 words ࠃɾट 57.05 59.93 58.14 ಓݝɾݝ ிॴࡏ 50.93 53.37 52.52 உঁରൺ 50.93 53.31 52.52 ຊޠྨޠ 34.50 36.52 36.28 ຊޠܗ༰ࢺ 34.88 36.85 36.58
distance ja wiki (۟ಡͷআʣ ja wiki ʢॿࢺɺॿಈࢺͷআʣ ja wiki ʢॿࢺɺॿಈࢺͷআʣ
࣍ݩ 200࣍ݩ 200࣍ݩ 400࣍ݩ ୯ޠ 417,027,641 words 223,030,315 words 223,030,315 words 1Ґ Cݴޠ Cݴޠ Cݴޠ 2Ґ ॲཧܥ ϓϩάϥϛϯά ϓϩάϥϛϯά 3Ґ ϓϩάϥϛϯά ॲཧܥ ॲཧܥ 4Ґ ίϯύΠϥ εΫϦϓτݴޠ ؔܕϓϩάϥϛϯά 5Ґ εΫϦϓτݴޠ LISP ίϯύΠϥ 6Ґ ΦϒδΣΫτࢦ ϓϩάϥϛϯάύϥμΠϜ εΫϦϓτݴޠ 7Ґ ΞηϯϒϦݴޠ ؔܕϓϩάϥϛϯά ΦϖϨʔςΟϯάγεςϜ distanceコマンドで[プログラミング⾔語](1単語)を⼊⼒
distance ja wiki (۟ಡͷআʣ ja wiki ʢॿࢺɺॿಈࢺͷআʣ ja wiki ʢॿࢺɺॿಈࢺͷআʣ
࣍ݩ 200࣍ݩ 200࣍ݩ 400࣍ݩ ୯ޠ 417,027,641 words 223,030,315 words 223,030,315 words 1Ґ స৬ใ స৬ใ ϦΫφϏ 2Ґ ϑϩϜɾΤʔ ϦΫφϏ ϦΫϧʔτϥΠϑελΠϧ 3Ґ ͱΒʔΏ ϑϩϜɾΤʔ ϑϩϜɾΤʔ 4Ґ CSK ͱΒʔΏ ISIZE 5Ґ ࠂཧళ ϦΫϧʔτϥΠϑελΠϧ స৬ใ 6Ґ ٻਓ ి௨ Χʔηϯαʔ 7Ґ ֶੜԉޢձ ࠾༻ࠂ ͱΒʔΏ distanceコマンドで[リクルート](1単語)を⼊⼒
distance ja wiki (۟ಡͷআʣ ja wiki ʢॿࢺɺॿಈࢺͷআʣ ja wiki ʢॿࢺɺॿಈࢺͷ
আʣ ࣍ݩ 200࣍ݩ 200࣍ݩ 400࣍ݩ ୯ޠ 417,027,641 words 223,030,315 words 223,030,315 words 1Ґ ϓϩάϥϛϯά ϓϩάϥϛϯά ϓϩάϥϛϯά 2Ґ ίϯύΠϥ Cݴޠ Cݴޠ 3Ґ Cݴޠ LISP ςΫχοΫ 4Ґ ΦϒδΣΫτࢦϓϩάϥϛϯά ίϯύΠϥ ϓϩάϥϜ 5Ґ ؔϓϩάϥϛϯά εΫϦϓτݴޠ ࣮ 6Ґ ΦϒδΣΫτࢦ ΦϒδΣΫτࢦϓϩάϥϛϯά ΞϓϦέʔγϣϯ 7Ґ ߏจ δΣωϦοΫϓϩάϥϛϯά ίϯύΠϥ distanceコマンドで[プログラミング⾔語 パフォーマンス ](2単語)を⼊⼒
distance ja wiki (۟ಡͷআʣ ja wiki ʢॿࢺɺॿಈࢺͷআʣ ja wiki ʢॿࢺɺॿಈࢺͷআʣ
࣍ݩ 200࣍ݩ 200࣍ݩ 400࣍ݩ ୯ޠ 417,027,641 words 223,030,315 words 223,030,315 words 1Ґ ίϯαϧλϯτ ਓࡐհձࣾ ίϯαϧλϯτ 2Ґ ϑϦʔϥϯαʔ ίϯαϧλϯτ ब৬ 3Ґ ݣձࣾ ৬ۀ ਓࡐհձࣾ 4Ґ ਓࡐհձࣾ ब৬ ৬ۀ 5Ґ τϨʔμʔ ࠶ब৬ ࣄ 6Ґ ਓࡐݣ δϣϒ ϦΫϧʔτΤʔδΣϯτ 7Ґ ৬ۀ ϑϦʔϥϯαʔ ࠶ब৬ distanceコマンドで[転職 エージェント](2単語)を⼊⼒