2021
07-22
07-22
pytorch 如何使用batch训练lstm网络
batch的lstm#导入相应的包importtorchimporttorch.nnasnnimporttorch.nn.functionalasFimporttorch.optimasoptimimporttorch.utils.dataasDatatorch.manual_seed(1)#准备数据的阶段defprepare_sequence(seq,to_ix):idxs=[to_ix[w]forwinseq]returntorch.tensor(idxs,dtype=torch.long)withopen("/home/lstm_train.txt",encoding='utf8')asf:train_data=[]word=[]label...
继续阅读 >