前提・実現したいこと
pythonでword2vecを使いたく、自分でtwitterからとってきたツイートをcsvファイルに入れて、それをword2vecに通したいのですが、下記のソースコードを実行したとき以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
(base) C:\jikken>python genModel.py C:\Anaconda\lib\site-packages\gensim\utils.py:1212: UserWarning: detected Windows; aliasing chunkize to chunkize_serial warnings.warn("detected Windows; aliasing chunkize to chunkize_serial") Traceback (most recent call last): File "genModel.py", line 5, in <module> model = word2vec.Word2Vec(data, size=200) File "C:\Anaconda\lib\site-packages\gensim\models\word2vec.py", line 767, in __init__ fast_version=FAST_VERSION) File "C:\Anaconda\lib\site-packages\gensim\models\base_any2vec.py", line 759, in __init__ self.build_vocab(sentences=sentences, corpus_file=corpus_file, trim_rule=trim_rule) File "C:\Anaconda\lib\site-packages\gensim\models\base_any2vec.py", line 936, in build_vocab sentences=sentences, corpus_file=corpus_file, progress_per=progress_per, trim_rule=trim_rule) File "C:\Anaconda\lib\site-packages\gensim\models\word2vec.py", line 1571, in scan_vocab total_words, corpus_count = self._scan_vocab(sentences, progress_per, trim_rule) File "C:\Anaconda\lib\site-packages\gensim\models\word2vec.py", line 1540, in _scan_vocab for sentence_no, sentence in enumerate(sentences): File "C:\Anaconda\lib\site-packages\gensim\models\word2vec.py", line 1363, in __iter__ text = rest + fin.read(8192) # avoid loading the entire file (=1 line) into RAM UnicodeDecodeError: 'cp932' codec can't decode byte 0xef in position 0: illegal multibyte sequence
該当のソースコード
python
1#coding: UTF-8 2from gensim.models import word2vec 3with open("tweet.csv", "r") as csv_file: 4 data = word2vec.Text8Corpus(csv_file) 5 model = word2vec.Word2Vec(data, size=200)
試したこと
3行目を
with open("tweet.csv", "r", encoding = 'utf-8') as csv_file:
に変えて試してみたが、
TypeError: can't concat str to bytes
というエラーがでてできなかった。
補足情報(FW/ツールのバージョンなど)
tweet.csvは文字コードをutf-8で保存してあります。
また、csvファイルの中身はすべて日本語のツイートのみです。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/26 06:38
2018/10/26 06:39
2018/10/26 06:42
2018/10/26 06:43 編集
2018/10/26 06:49
2018/10/26 06:51
2018/10/26 06:59