Skip to main content

SeqConv

SeqConv is a PyTorch implementation of a graph convolutional operator that uses long short-term memory (LSTM) to update node embeddings. This is useful for graph datasets where each node represents a sequence, such as a time series.

Where φr and φm are LSTMs (torch.nn.LSTM), and hΘ is a neural network. The outputs of each LSTM are the last hidden state, hn, rather than all the output features.

Installation

This module can be installed with pip:

$ pip install seq_conv

Usage

SeqConv is built on PyTorch Geometric and derives from the MessagePassing class. It expects an input graph where each node's "features" is a sequence of vectors. SeqConv, similarly to NNConv, also incorporates any available edge features when collecting messages from a node's neighbors.

Parameters:

  • in_channels (int): Number of channels in the input node sequence (e.g. if each node has a sequence of vectors of size n associated with it, then in_channels = n)
  • out_channels (int): Number of channels in the output node embedding
  • edge_nn (torch.nn.Module): A neural network hΘ that maps edge features, edge_attr, of shape [-1, num_edge_features] to shape [-1, out_channels]
  • aggr (string, optional): The message aggregation scheme to use ("add", "mean", "max")
  • root_lstm (bool, optional): If set to False, the layer will not add the LSTM-transformed root node features to the output
  • bias (bool, optional): If set to False, the layer will not learn an additive bias
  • **kwargs (optional): Additional arguments for torch.nn.LSTM

Example Usage:

import torch
from seq_conv import SeqConv

# Convolutional layer
conv_layer = SeqConv(
    in_channels=1,
    out_channels=5,
    edge_nn=torch.nn.Linear(2, 5)
)

# Your input graph (see: https://pytorch-geometric.readthedocs.io/en/latest/notes/introduction.html#data-handling-of-graphs)
x = torch.randn((3, 12, 1), dtype=torch.float) # Shape is [num_nodes, seq_len, in_channels]
edge_index = torch.tensor([
    [0, 1, 1, 2],
    [1, 0, 2, 1]
], dtype=torch.long)
edge_attr = torch.randn((4, 2), dtype=torch.long)

# Your output graph
x = conv_layer(x, edge_index, edge_attr) # Shape is now [3, 5]

To-Do: Allow stacking of SeqConv layers.

Metadata

Release files for seq-conv 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for seq-conv 1.0.2
File Size Uploaded
seq_conv-1.0.2.tar.gz 3.6 kB Details

Release files / seq_conv-1.0.2.tar.gz

Download URL seq_conv-1.0.2.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
61ed61e332d82ab2ccb54569ee75ecbdcd5d0b4c3b0c44397f3ae5e5f057eb04
BLAKE2b-256 checksum
How to use checksums
734320d931366f1db4ff5823444786ba7625778379ad66d2c16bf5a0d385d6db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.36.0 CPython/3.7.8

Release history Release notifications | RSS feed

This release

1.0.2 This release

1 release file

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page