2020-05-01から1ヶ月間の記事一覧

言語処理100本ノック2020(python)備忘録60-69

60 import gensim PATH = 'GoogleNews-vectors-negative300.bin' model = gensim.models.KeyedVectors.load_word2vec_format(PATH, binary=True) print(model['United_States']) 出力は [-3.61328125e-02 -4.83398438e-02 2.35351562e-01 1.74804688e-01 -1.…

言語処理100本ノック2020(python)備忘録50-59

newsCorpora.csvは "1 Fed official says weak data caused by weather" " should not slow taper http://www.latimes.com/business/money/la-fi-mo-federal-reserve-plosser-stimulus-economy-20140310" 0 "1312750.story\?track=rss Los Angeles Times b d…

言語処理100本ノック2020(python)備忘録40-49

まずはcabochaをインストール $cabocha -f1 neko.txt>neko.txt.cabocha を実行。-f1をオプションでつけた。 * 0 -1D 0/0 0.000000 一 名詞,数,*,*,*,*,一,イチ,イチ EOS EOS * 0 2D 0/0 -0.764522 記号,空白,*,*,*,*, , , * 1 2D 0/1 -0.764522 吾輩 名詞,代…

言語処理100本ノック2020(python)備忘録30-39

30 まずはmecabを使って $ mecab neko.txt > neko.txt.mecab を実行します。mecabのインストールは読者が頑張ってください。 word_array = [] with open('neko.txt.mecab') as r: r_lines = r.read() r_test = r_lines.splitlines() r_test_1bun = r_test[4:…

言語処理100本ノック2020(python)備忘録20-29

20 import gzip import json country_dict_list = [] with gzip.open('jawiki-country.json.gz', 'rt') as r: data = r.readlines() for line in data: country_dict_list.append(json.loads(line)) for line_dict in country_dict_list: if line_dict['titl…

言語処理100本ノック2020(python)備忘録10-19

10 11 12 13 14 15 16 17 18 19 10 path = 'popular-names.txt' f = open(path) s = f.read() f.close() s_line_sep = s.splitlines() wc = len(s_line_sep) print(wc) 出力は 2780 splitlinesでそれぞれの行を要素とする配列s_line_sepを作り、その長さ(=…