spline-based-transformer


Namespline-based-transformer JSON
Version 0.0.14 PyPI version JSON
download
home_pageNone
SummarySpline Based Transformer
upload_time2024-11-09 00:35:50
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License Copyright (c) 2024 Phil Wang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords artificial intelligence deep learning transformers attention mechanism b-spline latent trajectories
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <img src="./spline-based-transformer.png" width="400px"></img>

## Spline-Based Transformer

Implementation of the proposed <a href="https://www.youtube.com/watch?v=AzolLlIbKhg">Spline-Based Transformer</a> ([paper](https://la.disneyresearch.com/wp-content/uploads/SBT.pdf)) from Disney Research

This is basically a transformer based autoencoder, but they cleverly use a set of latent tokens, where that set of tokens are the (high dimensional) control points for a spline.

## Install

```bash
$ pip install spline-based-transformer
```

## Usage

```python
import torch
from spline_based_transformer import SplineBasedTransformer

model = SplineBasedTransformer(
    dim = 512,
    enc_depth = 6,
    dec_depth = 6
)

data = torch.randn(1, 1024, 512)

loss = model(data, return_loss = True)
loss.backward()

# after much training

recon, control_points = model(data, return_latents = True)
assert data.shape == recon.shape

# mess with the control points, which should preserve continuity better

control_points += 1

controlled_recon = model.decode_from_latents(control_points, num_times = 1024)
assert controlled_recon.shape == data.shape
```

For an example of an image autoencoder

```python
import torch

from spline_based_transformer import (
    SplineBasedTransformer,
    ImageAutoencoderWrapper
)

model = ImageAutoencoderWrapper(
    image_size = 256,
    patch_size = 32,
    spline_transformer = SplineBasedTransformer(
        dim = 512,
        enc_depth = 6,
        dec_depth = 6
    )
)

images = torch.randn(2, 3, 256, 256)

loss = model(images, return_loss = True)
loss.backward()

# after much training

recon_images, control_points = model(images, return_latents = True)
assert images.shape == recon_images.shape

# changing the control points

control_points += 1

controlled_recon_images = model.decode_from_latents(control_points)

assert controlled_recon_images.shape == images.shape
```

## Citations

```bibtex
@misc{Chandran2024,
    author  = {Prashanth Chandran, Agon Serifi, Markus Gross, Moritz Bächer},
    url     = {https://la.disneyresearch.com/publication/spline-based-transformers/}
}
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "spline-based-transformer",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "artificial intelligence, deep learning, transformers, attention mechanism, b-spline, latent trajectories",
    "author": null,
    "author_email": "Phil Wang <lucidrains@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/43/76/487dfa448da9ad2a987abf4e7823ca328cbca7cc2e20154029f6e5f48d9d/spline_based_transformer-0.0.14.tar.gz",
    "platform": null,
    "description": "<img src=\"./spline-based-transformer.png\" width=\"400px\"></img>\n\n## Spline-Based Transformer\n\nImplementation of the proposed <a href=\"https://www.youtube.com/watch?v=AzolLlIbKhg\">Spline-Based Transformer</a> ([paper](https://la.disneyresearch.com/wp-content/uploads/SBT.pdf)) from Disney Research\n\nThis is basically a transformer based autoencoder, but they cleverly use a set of latent tokens, where that set of tokens are the (high dimensional) control points for a spline.\n\n## Install\n\n```bash\n$ pip install spline-based-transformer\n```\n\n## Usage\n\n```python\nimport torch\nfrom spline_based_transformer import SplineBasedTransformer\n\nmodel = SplineBasedTransformer(\n    dim = 512,\n    enc_depth = 6,\n    dec_depth = 6\n)\n\ndata = torch.randn(1, 1024, 512)\n\nloss = model(data, return_loss = True)\nloss.backward()\n\n# after much training\n\nrecon, control_points = model(data, return_latents = True)\nassert data.shape == recon.shape\n\n# mess with the control points, which should preserve continuity better\n\ncontrol_points += 1\n\ncontrolled_recon = model.decode_from_latents(control_points, num_times = 1024)\nassert controlled_recon.shape == data.shape\n```\n\nFor an example of an image autoencoder\n\n```python\nimport torch\n\nfrom spline_based_transformer import (\n    SplineBasedTransformer,\n    ImageAutoencoderWrapper\n)\n\nmodel = ImageAutoencoderWrapper(\n    image_size = 256,\n    patch_size = 32,\n    spline_transformer = SplineBasedTransformer(\n        dim = 512,\n        enc_depth = 6,\n        dec_depth = 6\n    )\n)\n\nimages = torch.randn(2, 3, 256, 256)\n\nloss = model(images, return_loss = True)\nloss.backward()\n\n# after much training\n\nrecon_images, control_points = model(images, return_latents = True)\nassert images.shape == recon_images.shape\n\n# changing the control points\n\ncontrol_points += 1\n\ncontrolled_recon_images = model.decode_from_latents(control_points)\n\nassert controlled_recon_images.shape == images.shape\n```\n\n## Citations\n\n```bibtex\n@misc{Chandran2024,\n    author  = {Prashanth Chandran, Agon Serifi, Markus Gross, Moritz B\u00e4cher},\n    url     = {https://la.disneyresearch.com/publication/spline-based-transformers/}\n}\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Phil Wang  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Spline Based Transformer",
    "version": "0.0.14",
    "project_urls": {
        "Homepage": "https://pypi.org/project/spline-based-transformer",
        "Repository": "https://github.com/lucidrains/spline-based-transformer"
    },
    "split_keywords": [
        "artificial intelligence",
        " deep learning",
        " transformers",
        " attention mechanism",
        " b-spline",
        " latent trajectories"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ba1aedd7f34fa04836c0c27a8594092d26a7a0088f67add25a3e39d09d1aac07",
                "md5": "bf9f1fb86a83b860f874bfa91eeb7193",
                "sha256": "be0f28c8254c07cd1b47d250b973c8b868c8584485eb8fbeebb9095f2182bf69"
            },
            "downloads": -1,
            "filename": "spline_based_transformer-0.0.14-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bf9f1fb86a83b860f874bfa91eeb7193",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 6816,
            "upload_time": "2024-11-09T00:35:48",
            "upload_time_iso_8601": "2024-11-09T00:35:48.746091Z",
            "url": "https://files.pythonhosted.org/packages/ba/1a/edd7f34fa04836c0c27a8594092d26a7a0088f67add25a3e39d09d1aac07/spline_based_transformer-0.0.14-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4376487dfa448da9ad2a987abf4e7823ca328cbca7cc2e20154029f6e5f48d9d",
                "md5": "4b054206355453a4adb4868860d09733",
                "sha256": "f023c41004b47c54639ca61288ba7fef979e19f9b076f06e618b22a6aaca86a2"
            },
            "downloads": -1,
            "filename": "spline_based_transformer-0.0.14.tar.gz",
            "has_sig": false,
            "md5_digest": "4b054206355453a4adb4868860d09733",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 5620,
            "upload_time": "2024-11-09T00:35:50",
            "upload_time_iso_8601": "2024-11-09T00:35:50.257430Z",
            "url": "https://files.pythonhosted.org/packages/43/76/487dfa448da9ad2a987abf4e7823ca328cbca7cc2e20154029f6e5f48d9d/spline_based_transformer-0.0.14.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-09 00:35:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lucidrains",
    "github_project": "spline-based-transformer",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "spline-based-transformer"
}
        
Elapsed time: 0.62341s