Skip to main content

SeqPool: Collection of pooling methods for sequences of embedding vectors

Project description

SeqPool

Pytorch library implementing pooling methods for sequences of embedding vectors.

Installation

pip install seqpool

..or build from source ~

Usage

Import a sequence pooling layer and apply it to a (batch, length, embedding) shaped tensor:

from seqpool import CVTSeqPool

f = CVTSeqPool(128)
x = torch.randn(4, 1024, 128) # for example, take x from a transformer's output
y = f(x) # (4, 1024, 128) -> (4, 128)

Typical use-case is in the training of a smaller model using a pretrained model's embeddings, for example a BERT-style model.

Variants

Escaping the Big Data Paradigm with Compact Transformers arXiv

Architectural Diagram of Compact Vision Transformer

from seqpool import CVTSeqPool
f = CVTSeqPool(in_dim=128)

This paper proposes a number of improvements on Vision Transformers to improve performance on low-data tasks. One improvement was a "SeqPool" mechanism. A single linear layer produces a weighting for each sequence element, then softmax is applied. This is then used to compute the weighted sum of all embedding vectors. The intuition is that each sequence element does not contain the same amount of entropy, and so allowing the model to construct its own weighting on importance helps improve performance on the downstream task.


References

Escaping the Big Data Paradigm with Compact Transformers

Ali Hassani, Steven Walton, Nikhil Shah, Abulikemu Abuduweili, Jiachen Li, Humphrey Shi

@article{hassani2021escaping,
  title={Escaping the big data paradigm with compact transformers},
  author={Hassani, Ali and Walton, Steven and Shah, Nikhil and Abuduweili, Abulikemu and Li, Jiachen and Shi, Humphrey},
  journal={arXiv preprint arXiv:2104.05704},
  year={2021}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

seqpool-0.0.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

seqpool-0.0.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file seqpool-0.0.1.tar.gz.

File metadata

  • Download URL: seqpool-0.0.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.10.5

File hashes

Hashes for seqpool-0.0.1.tar.gz
Algorithm Hash digest
SHA256 a7811d4014c46a5b46cb8c28a11a8284d95e85b35dc0324d6e9099e9ee52aa9e
MD5 d9d0c8342779302b1481853cea486709
BLAKE2b-256 7e74e25d90986c232ad1083dbcf54697d99015830e7cc3ee1e2caec2e28ce1a3

See more details on using hashes here.

File details

Details for the file seqpool-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: seqpool-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.10.5

File hashes

Hashes for seqpool-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f650284d765fa324f657c314a819db0f35b35ac62ad51eaf85600974f506508d
MD5 fc8b10c1a6dbb4654d873c2557ec9b40
BLAKE2b-256 296d67111fd365cac60ff9f403a7dcda4e87c48a91ebe376892c0a1fd8532ead

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page