加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
word_vec.py 1008 Bytes
一键复制 编辑 原始数据 按行查看 历史
Niucas_Mao 提交于 2018-08-08 17:05 . 上传代码
#coding:utf-8
import numpy as np
import pandas as pd
from gensim.models import word2vec
import logging
#读入数据
def load_data(path):
data = np.load(path)
return data
x_train = load_data('E:/NLP/chinese-w2v-sentiment/data/x_train_data.npy')
x_test = load_data('E:/NLP/chinese-w2v-sentiment/data/x_test_data.npy')
y_train = load_data('E:/NLP/chinese-w2v-sentiment/data/y_train_data.npy')
y_test = load_data('E:/NLP/chinese-w2v-sentiment/data/y_test_data.npy')
print(x_train[0])
# 打印日志
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
#训练模型
#model = word2vec.Word2Vec(x_train,sg=0,hs=1,min_count=1,window=5,size=300)
def model(data,model_path):
model = word2vec.Word2Vec(data,sg=0,hs=1,min_count=1,window=5,size=300)
model.save(model_path)
return model
#训练数据集
train_model = model(x_train,'E:/NLP/chinese-w2v-sentiment/train_model.model')
test_model = model(x_test,'E:/NLP/chinese-w2v-sentiment/test_model.model')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化