def prepare_sequence(seq, to_ix): idxs = [to_ix[w] for w in seq] return [torch.tensor](https://docs.pytorch.org/docs/stable/generated/torch.tensor.html#torch.tensor "torch.tensor")(idxs, dtype=[torch.long](https://docs.pytorch.org/docs/stable/tensor_attributes.html#torch.dtype "torch.dtype")) training_data = [ # Tags are: DET - determiner; NN - noun; V - verb # For example, the word "The" is a determiner ("The dog ate the apple".split(), ["DET", "NN", "V", "DET", "NN"]), ("Everybody read that book".split(), ["NN", "V", "DET", "NN"]) ] word_to_ix = {} # For each words-list (sentence) and tags-list in each tuple of training_data for sent, tags in training_data: for word in sent: if word not in word_to_ix: # word has not been assigned an index yet word_to_ix[word] = len(word_to_ix) # Assign each word with a unique index print(word_to_ix) tag_to_ix = {"DET": 0, "NN": 1, "V": 2} # Assign each tag with a unique index # These will usually be more like 32 or 64 dimensional. # We will keep them small, so we can see how the weights change as we train. EMBEDDING_DIM = 6 HIDDEN_DIM = 6