import pandas as pd
from pathlib import Path
mypath = Path(".")
df = pd.read_csv(mypath/'dianping.csv')
df.head()
comment | sentiment | |
---|---|---|
0 | 口味:不知道是我口高了,还是这家真不怎么样。 我感觉口味确实很一般很一般。上菜相当快,我敢说... | 0 |
1 | 菜品丰富质量好,服务也不错!很喜欢! | 1 |
2 | 说真的,不晓得有人排队的理由,香精香精香精香精,拜拜! | 0 |
3 | 菜量实惠,上菜还算比较快,疙瘩汤喝出了秋日的暖意,烧茄子吃出了大阪烧的味道,想吃土豆片也是口... | 1 |
4 | 先说我算是娜娜家风荷园开业就一直在这里吃 每次出去回来总想吃一回 有时觉得外面的西式简餐总是... | 1 |
df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 2000 entries, 0 to 1999 Data columns (total 2 columns): comment 2000 non-null object sentiment 2000 non-null int64 dtypes: int64(1), object(1) memory usage: 31.4+ KB
# !pip install jieba
import jieba
df['text'] = df.comment.apply(lambda x: " ".join(jieba.cut(x)))
Building prefix dict from the default dictionary ... Loading model from cache C:\Users\LIJIAX~1\AppData\Local\Temp\jieba.cache Loading model cost 0.926 seconds. Prefix dict has been built succesfully.
df.head()
comment | sentiment | text | |
---|---|---|---|
0 | 口味:不知道是我口高了,还是这家真不怎么样。 我感觉口味确实很一般很一般。上菜相当快,我敢说... | 0 | 口味 : 不 知道 是 我口 高 了 , 还是 这家 真 不怎么样 。 我 感觉 口味 ... |
1 | 菜品丰富质量好,服务也不错!很喜欢! | 1 | 菜品 丰富 质量 好 , 服务 也 不错 ! 很 喜欢 ! |
2 | 说真的,不晓得有人排队的理由,香精香精香精香精,拜拜! | 0 | 说真的 , 不 晓得 有人 排队 的 理由 , 香精 香精 香精 香精 , 拜拜 ! |
3 | 菜量实惠,上菜还算比较快,疙瘩汤喝出了秋日的暖意,烧茄子吃出了大阪烧的味道,想吃土豆片也是口... | 1 | 菜量 实惠 , 上菜 还 算 比较 快 , 疙瘩汤 喝出 了 秋日 的 暖意 , 烧茄子 吃... |
4 | 先说我算是娜娜家风荷园开业就一直在这里吃 每次出去回来总想吃一回 有时觉得外面的西式简餐总是... | 1 | 先说 我 算是 娜娜 家风 荷园 开业 就 一直 在 这里 吃 每次 出去 回来 总想 ... |
df[['text']].to_csv("output/dianping_cut.csv", index = False, header = False)
df.head()
text | sentiment | |
---|---|---|
0 | 口味 : 不 知道 是 我口 高 了 , 还是 这家 真 不怎么样 。 我 感觉 口味 ... | 0 |
1 | 菜品 丰富 质量 好 , 服务 也 不错 ! 很 喜欢 ! | 1 |
2 | 说真的 , 不 晓得 有人 排队 的 理由 , 香精 香精 香精 香精 , 拜拜 ! | 0 |
3 | 菜量 实惠 , 上菜 还 算 比较 快 , 疙瘩汤 喝出 了 秋日 的 暖意 , 烧茄子 吃... | 1 |
4 | 先说 我 算是 娜娜 家风 荷园 开业 就 一直 在 这里 吃 每次 出去 回来 总想 ... | 1 |
# !pip install gensim
import gensim
model = gensim.models.Word2Vec.load('refs/zh/zh.bin')
more_sentences = gensim.models.word2vec.Text8Corpus("output/dianping_cut.csv") # 加载语料
ValueError: You must specify either total_examples or total_words, for proper job parameters updationand progress calculations. The usual value is total_examples=model.corpus_count.
model.build_vocab(more_sentences, update=True) # 更新词汇表
model.train(more_sentences, total_examples=model.corpus_count, epochs=1)
(57687, 114396)
model.save("output/word2vec_online_training.model")