アイソモカ

知の遊牧民の開発記録

開発記録 200306 Fri (お魚の本 2章, 相互情報量, 次元削減)

お魚の本 (ゼロから作る Deep Learning自然言語処理編) 2.3 カウントベースの手法 を読んで書いてみる。

2.4.1~2.4.3 相互情報量、次元削減、SVD

SVD は分かったような分からないようななので、ちゃんと計算したい。

メモ:行列の大きさを得る .shape

アレイについて。co_matrix.shape で行列の大きさ (行, 列) が得られる。

co_matrix = np.array([[1,1,1],[2,2,2],[3,3,3],[4,4,4]])
print(co_matrix)
print(co_matrix.shape)
↓
[[1 1 1]
 [2 2 2]
 [3 3 3]
 [4 4 4]]
(4, 3)

メモ:辞書のループに .items() を使う方法

辞書について。 word_to_id.items() で、

print(word_to_id.items())
↓
dict_items([('you', 0), ('say', 1), ('goodbye', 2), ('and', 3), ('i', 4), ('hello', 5), ('.', 6)])

タプルのリストが得られる。以下のようにループ。

for word, word_id in word_to_id.items():
    ...

count_method_small.py を実行してみた

初めに言があった。言は神と共にあった。言は神であった。

John 1-1, KJV from biblestudytools.com

 ...
text = 'In the beggining was the Word, and the Word was with God, and the Word was God.'
 ...

f:id:piijey:20200306223811p:plain
count_method_small_word.png

小さいコーパスやとどう解釈したらいいのか分からへんなあ。