This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'Christoph Heindl' | |
__copyright__ = 'Copyright 2017' | |
__license__ = 'BSD' | |
"""Trains a HMM based on gradient descent optimization. | |
The parameters (theta) of the model are transition and | |
emission probabilities, as well as the initial state probabilities. | |
Given a start solution, the negative log likelihood of data given the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import torch.nn as nn | |
from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence | |
seqs = ['gigantic_string','tiny_str','medium_str'] | |
# make <pad> idx 0 | |
vocab = ['<pad>'] + sorted(set(''.join(seqs))) | |
# make model |