Tutorials/examples of captum with 1D data?

Hello all,

I’m hoping to use captum for feature attribution on a basic 1-D linear regression model (see below), but all the examples I’ve seen use 2D models (usually for machine vision applications). Is there a good tutorial out there for using captum with simpler models?

Thanks!

class Regression(nn.Module):

  def __init__(self):
    super().__init__()
    self.layers = nn.Sequential(
      nn.Linear(7490, 64),
      nn.ReLU(),
      nn.Linear(64, 32),
      nn.ReLU(),
      nn.Linear(32, 1)
    )


  def forward(self, x):
    '''
      Forward pass
    '''
    return self.layers(x)

def training_loop(n_epochs, train_loader):
# training loop

    for epoch in range(n_epochs):

        # Set current loss value
        current_loss = 0.0
        # Iterate over the DataLoader for training data
        for i, data in enumerate(train_loader, 0):
          # Get and prepare inputs
          inputs, targets = data
          inputs, targets = inputs.float(), targets.float()
          targets = targets.reshape((targets.shape[0],1))
            # Zero the gradients
          optimizer.zero_grad()
          # Perform forward pass
          outputs = model(inputs)

          # Compute loss
          loss = loss_function(outputs, targets)

          # Perform backward pass
          loss.backward()

          # Perform optimization
          optimizer.step()
    return model

Captum works with 1D models too. Most of the examples use images, but the attribution methods are model agnostic. For a simple feed forward network like yours, methods such as Integrated Gradients or Saliency should work without changing the model. The main difference is that your input tensor will have shape [batch_size, 7490] instead of image dimensions. The image examples still apply once you replace the input format.