import time, numpy as np, pandas as pd
from gensim.test.utils import get_tmpfile
from gensim.models import KeyedVectors
from keras.preprocessing import sequence
from keras.models import Sequential
from keras.layers import Dense, LSTM
from keras.utils import to_categorical
t1=time.time()
path = get_tmpfile("./wordvectors.kv")
wv = KeyedVectors.load(path, mmap='r')
train = pd.read_csv('../data/train_w5k.csv')
test = pd.read_csv('../data/test_w5k.csv')
test_id = test["id"].copy()
y=to_categorical((train["class"]-1).astype(int))
column="word_seg"
print("clashape:",y.shape)
train=[wdl.split() for wdl in train[column]]
test=[wdl.split() for wdl in test[column]]
maxlen=max([len(x) for x in test+train])
print("maxlen:",maxlen)
def w2v_pad(data):
data = [[wv[s] for s in st if s in wv.vocab] for st in data]
data = sequence.pad_sequences(data, maxlen=maxlen)
print('data shape:', data.shape)
train=w2v_pad(train)
test=w2v_pad(test)
t2=time.time()
print("dataproc time use:",t2-t1)
model = Sequential()
model.add(LSTM(64, input_shape=(train.shape[1], train.shape[2])))
model.add(Dense(y.shape[1], activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['categorical_accuracy'])
model.fit(train, y,batch_size=1024,epochs=100,validation_split=0.2,verbose=2)
preds=model.predict(test,batch_size=1024,verbose=1)
t3=time.time()
print("lstm time use:",t3-t2)
test_prob=pd.DataFrame(preds)
test_prob.columns=["class_prob_%s"%i for i in range(1,preds.shape[1]+1)]
test_prob["id"]=test_id
test_prob.to_csv('../data/w2v+lstm_prob.csv',index=None)
test_pred=pd.DataFrame(np.argmax(preds,axis=1))
test_pred.columns=["class"]
test_pred["class"]=(test_pred["class"]+1).astype(int)
test_pred["id"]=test_id
test_pred[["id","class"]].to_csv('../data/w2v+lstm_sub.csv',index=None)
print("probs shape:",test_prob.shape)
print("preds shape:",test_pred.shape)
没有合适的资源?快使用搜索试试~ 我知道了~
数据城堡“达观杯”文本智能处理挑战赛.zip
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共14个文件
py:12个
gitattributes:1个
csv:1个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 180 浏览量
2023-11-09
01:27:54
上传
评论
收藏 3.12MB ZIP 举报
温馨提示
挑战杯大赛相关代码、设计文档、使用说明,供备赛参赛人员参考 挑战杯大赛相关代码、设计文档、使用说明,供备赛参赛人员参考 挑战杯大赛相关代码、设计文档、使用说明,供备赛参赛人员参考 挑战杯大赛相关代码、设计文档、使用说明,供备赛参赛人员参考 挑战杯大赛相关代码、设计文档、使用说明,供备赛参赛人员参考 挑战杯大赛相关代码、设计文档、使用说明,供备赛参赛人员参考 挑战杯大赛相关代码、设计文档、使用说明,供备赛参赛人员参考 挑战杯大赛相关代码、设计文档、使用说明,供备赛参赛人员参考 挑战杯大赛相关代码、设计文档、使用说明,供备赛参赛人员参考 挑战杯大赛相关代码、设计文档、使用说明,供备赛参赛人员参考 挑战杯大赛相关代码、设计文档、使用说明,供备赛参赛人员参考 挑战杯大赛相关代码、设计文档、使用说明,供备赛参赛人员参考 挑战杯大赛相关代码、设计文档、使用说明,供备赛参赛人员参考 挑战杯大赛相关代码、设计文档、使用说明,供备赛参赛人员参考 挑战杯大赛相关代码、设计文档、使用说明,供备赛参赛人员参考 挑战杯大赛相关代码、设计文档、使用说明,供备赛参赛人员参考 挑战杯大赛相关代码、设计文档、使用说明,供备赛参赛人员参考 挑战杯大赛相关代码、设计文档、使用说明,供备赛参赛人员参考 挑战杯大赛相关代码、设计文档、使用说明,供备赛参赛人员参考 挑战杯大赛相关代码、设计文档、使用说明,供备赛参赛人员参考 挑战杯大赛相关代码、设计文档、使用说明,供备赛参赛人员参考
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 14 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/aabe6d6d0d60488ebb2b6aca61c27695_lijunhcn.jpg!1)
![avatar-vip](https://csdnimg.cn/release/downloadcmsfe/public/img/user-vip.1c89f3c5.png)
辣椒种子
- 粉丝: 3533
- 资源: 5721
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)