import torch
import torch.nn as nn
import torch.autograd as autograd
from torch import optim
defprepare_sequence(seq,to_ix):
idxs =[to_ix[w]for w in seq]
tensor = torch.LongTensor(idxs)return autograd.Variable(tensor)
training_data =[('the dog ate the apple'.split(),['DET','NN','V','DET','NN']),('Everybody read that book'.split(),['NN','V','DET','NN'])]
word_to_ix ={}for sent,tags in training_data:for word in sent:if word notin word_to_ix:
word_to_ix[word]=len(word_to_ix)print(word_to_ix)