赞
踩
sentences=[‘i like dog’, ‘i love coffee’, ‘i hate milk’]
当输入[‘i’,‘like’], [‘i’,‘love’], [‘i’,‘hate’]时,分别预测下一个单词为[‘dog’], [‘coffee’],[‘milk’]
import torch
import torch.nn as nn
import torch.optim as optim
from torch.autograd import Variable
dtype = torch.FloatTensor
sentences = ['i like dog', 'i love coffee', 'i hate milk']
words = ' '.join(sentences).split()
words_dict = list(set(words))
num2word = {
index:word for index, word in enumerate(words_dict)}
word2num = {
word:index for index, word in enumerate(words_dict)}
def make_batch(sentences):
input_batch = []
target_batch = []
for sen in sentences
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。