Which model for NER-like sensor data classification?

I am building a seq2seq model which should be able to mark the start and end indexes (e.g. “step start” and “step end”) on the sensor data attached to an athlete’s leg. I would like to do the same for kicks and turns.

However, I am having difficulty producing a (100, 3) matrix using an LSTM model. Is an approach similar to the following code example appropriate for this problem?

class StepModel(nn.Module):
    def __init__(self, input_size, hidden_size, num_layers, output_size):
        super(StepModel, self).__init__()
        self.hidden_size = hidden_size
        self.num_layers = num_layers

        self.lstm = nn.LSTM(input_size, hidden_size, num_layers, bidirectional=True, batch_first=True)
        self.fc = nn.Linear(hidden_size, output_size)
        self.softmax = nn.Softmax(dim=-1)

    def forward(self, x):
        h0 = torch.zeros(self.num_layers, x.size(0), self.hidden_size).to(x.device)
        c0 = torch.zeros(self.num_layers, x.size(0), self.hidden_size).to(x.device)

        out, _ = self.lstm(x, (h0, c0))
        out = self.fc(out[:, -1, :])
        out = self.softmax(out)
        return out

Yes, the code example you provided is appropriate for building a seq2seq model using an LSTM. It defines a class called StepModel that inherits from nn.Module. The model consists of an LSTM layer followed by a fully connected layer and a softmax activation function.

The input to the model is a tensor x with shape (batch_size, seq_len, input_size). The LSTM layer processes the input sequence and returns the output tensor out with shape (batch_size, seq_len, hidden_size). The final hidden state of the LSTM layer is extracted using out[:, -1, :], and passed through the fully connected layer to obtain the output tensor.

The output tensor out is then passed through the softmax activation function to obtain the probability distribution over the output classes. The resulting tensor out has shape (batch_size, output_size), where output_size is the number of classes.

Overall, the StepModel class is a suitable implementation for your seq2seq model.