{
    "info": {
        "author": "Alexander Rush",
        "author_email": "arush@cornell.edu",
        "bugtrack_url": null,
        "classifiers": [],
        "description": "# Torch-Struct: Structured Prediction Library \n\n![Tests](https://github.com/harvardnlp/pytorch-struct/workflows/Tests/badge.svg)\n[![Coverage Status](https://coveralls.io/repos/github/harvardnlp/pytorch-struct/badge.svg?branch=master)](https://coveralls.io/github/harvardnlp/pytorch-struct?branch=master)\n\n<p align=\"center\">\n  <img src=\"https://github.com/harvardnlp/pytorch-struct/raw/master/download.png\">\n  </p>\n\n\nA library of tested, GPU implementations of core structured prediction algorithms for deep learning applications.\n\n* HMM / LinearChain-CRF \n* HSMM / SemiMarkov-CRF \n* Dependency Tree-CRF \n* PCFG Binary Tree-CRF \n* ...\n\nDesigned to be used as efficient batched layers in other PyTorch code. \n\n[Tutorial paper](https://arxiv.org/abs/2002.00876) describing methodology.\n\n## Getting Started\n\n\n```python\n!pip install -qU git+https://github.com/harvardnlp/pytorch-struct\n# Optional CUDA kernels for FastLogSemiring\n!pip install -qU git+https://github.com/harvardnlp/genbmm\n# For plotting.\n!pip install -q matplotlib\n```\n\n\n```python\nimport torch\nfrom torch_struct import DependencyCRF, LinearChainCRF\nimport matplotlib.pyplot as plt\ndef show(x): plt.imshow(x.detach())\n```\n\n\n```python\n# Make some data.\nvals = torch.zeros(2, 10, 10) + 1e-5\nvals[:, :5, :5] = torch.rand(5)\nvals[:, 5:, 5:] = torch.rand(5) \ndist = DependencyCRF(vals.log())\nshow(dist.log_potentials[0])\n```\n\n\n![png](README_files/README_4_0.png)\n\n\n\n```python\n# Compute marginals\nshow(dist.marginals[0])\n```\n\n\n![png](README_files/README_5_0.png)\n\n\n\n```python\n# Compute argmax\nshow(dist.argmax.detach()[0])\n```\n\n\n![png](README_files/README_6_0.png)\n\n\n\n```python\n# Compute scoring and enumeration (forward / inside)\nlog_partition = dist.partition\nmax_score = dist.log_prob(dist.argmax)\n```\n\n\n```python\n# Compute samples \nshow(dist.sample((1,)).detach()[0, 0])\n```\n\n\n![png](README_files/README_8_0.png)\n\n\n\n```python\n# Padding/Masking built into library.\ndist = DependencyCRF(vals, lengths=torch.tensor([10, 7]))\nshow(dist.marginals[0])\nplt.show()\nshow(dist.marginals[1])\n```\n\n\n![png](README_files/README_9_0.png)\n\n\n\n![png](README_files/README_9_1.png)\n\n\n\n```python\n# Many other structured prediction approaches\nchain = torch.zeros(2, 10, 10, 10) + 1e-5\nchain[:, :, :, :] = vals.unsqueeze(-1).exp()\nchain[:, :, :, :] += torch.eye(10, 10).view(1, 1, 10, 10) \nchain[:, 0, :, 0] = 1\nchain[:, -1,9, :] = 1\nchain = chain.log()\n\ndist = LinearChainCRF(chain)\nshow(dist.marginals.detach()[0].sum(-1))\n```\n\n\n![png](README_files/README_10_0.png)\n\n\n## Library\n\nFull docs: http://nlp.seas.harvard.edu/pytorch-struct/\n\nCurrent distributions implemented:\n\n* LinearChainCRF \n* SemiMarkovCRF \n* DependencyCRF \n* NonProjectiveDependencyCRF\n* TreeCRF \n* NeuralPCFG / NeuralHMM\n\nEach distribution includes: \n\n* Argmax, sampling, entropy, partition, masking, log_probs, k-max\n\nExtensions:\n\n* Integration with `torchtext`, `pytorch-transformers`, `dgl`\n* Adapters for generative structured models (CFG / HMM / HSMM)\n* Common tree structured parameterizations TreeLSTM / SpanLSTM\n\n\n## Low-level API: \n\nEverything implemented through semiring dynamic programming. \n\n* Log Marginals\n* Max and MAP computation\n* Sampling through specialized backprop\n* Entropy and first-order semirings. \n\n\n## Examples\n\n* BERT <a href=\"https://github.com/harvardnlp/pytorch-struct/blob/master/notebooks/BertTagger.ipynb\">Part-of-Speech</a> \n* BERT <a href=\"https://github.com/harvardnlp/pytorch-struct/blob/master/notebooks/BertDependencies.ipynb\">Dependency Parsing</a>\n* <a href=\"https://github.com/harvardnlp/pytorch-struct/blob/master/notebooks/Unsupervised_CFG.ipynb\">Unsupervised Learning</a> \n* <a href=\"https://github.com/harvardnlp/pytorch-struct/blob/master/examples/tree.py\">Structured VAE </a>\n\n<img src=\"https://media.giphy.com/media/IdxKpsWBHa5PpjuhHM/giphy.gif\">\n\n## Citation\n\n```\n@misc{alex2020torchstruct,\n    title={Torch-Struct: Deep Structured Prediction Library},\n    author={Alexander M. Rush},\n    year={2020},\n    eprint={2002.00876},\n    archivePrefix={arXiv},\n    primaryClass={cs.CL}\n}\n```\n\n\n",
        "description_content_type": "text/markdown",
        "docs_url": null,
        "download_url": "",
        "downloads": {
            "last_day": -1,
            "last_month": -1,
            "last_week": -1
        },
        "home_page": "https://github.com/harvardnlp/pytorch-struct",
        "keywords": "",
        "license": "",
        "maintainer": "",
        "maintainer_email": "",
        "name": "torch-struct",
        "package_url": "https://pypi.org/project/torch-struct/",
        "platform": "",
        "project_url": "https://pypi.org/project/torch-struct/",
        "project_urls": {
            "Homepage": "https://github.com/harvardnlp/pytorch-struct"
        },
        "release_url": "https://pypi.org/project/torch-struct/0.5/",
        "requires_dist": [
            "torch"
        ],
        "requires_python": ">=3.6",
        "summary": "",
        "version": "0.5",
        "yanked": false,
        "yanked_reason": null
    },
    "last_serial": 9410913,
    "releases": {
        "0.5": [
            {
                "comment_text": "",
                "digests": {
                    "md5": "80940d05e3a14b32d63a70f95327c8a8",
                    "sha256": "9e4c4e5a2317d01cef47bfb0786b4ece6aebe1fa23f5f8a6a91887a3aab3d020"
                },
                "downloads": -1,
                "filename": "torch_struct-0.5-py3-none-any.whl",
                "has_sig": false,
                "md5_digest": "80940d05e3a14b32d63a70f95327c8a8",
                "packagetype": "bdist_wheel",
                "python_version": "py3",
                "requires_python": ">=3.6",
                "size": 34703,
                "upload_time": "2021-02-14T02:43:46",
                "upload_time_iso_8601": "2021-02-14T02:43:46.263751Z",
                "url": "https://files.pythonhosted.org/packages/b2/8c/775b7e141f11d509d59d0d2d801337ff3ad0203bc1a40335ea83e1161ba7/torch_struct-0.5-py3-none-any.whl",
                "yanked": false,
                "yanked_reason": null
            },
            {
                "comment_text": "",
                "digests": {
                    "md5": "c6658e4c1aff60598c346e5dc4afb5d6",
                    "sha256": "a40e234353f3b1a1df743100a781949b84b48877578340e77dc5066899c06495"
                },
                "downloads": -1,
                "filename": "torch_struct-0.5.tar.gz",
                "has_sig": false,
                "md5_digest": "c6658e4c1aff60598c346e5dc4afb5d6",
                "packagetype": "sdist",
                "python_version": "source",
                "requires_python": ">=3.6",
                "size": 30369,
                "upload_time": "2021-02-14T02:43:47",
                "upload_time_iso_8601": "2021-02-14T02:43:47.357426Z",
                "url": "https://files.pythonhosted.org/packages/f3/e1/bb2ad949a56c25014e1a7c0e2b0f5a7f670eff876fe733156afe2119eede/torch_struct-0.5.tar.gz",
                "yanked": false,
                "yanked_reason": null
            }
        ]
    },
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "80940d05e3a14b32d63a70f95327c8a8",
                "sha256": "9e4c4e5a2317d01cef47bfb0786b4ece6aebe1fa23f5f8a6a91887a3aab3d020"
            },
            "downloads": -1,
            "filename": "torch_struct-0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "80940d05e3a14b32d63a70f95327c8a8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 34703,
            "upload_time": "2021-02-14T02:43:46",
            "upload_time_iso_8601": "2021-02-14T02:43:46.263751Z",
            "url": "https://files.pythonhosted.org/packages/b2/8c/775b7e141f11d509d59d0d2d801337ff3ad0203bc1a40335ea83e1161ba7/torch_struct-0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "c6658e4c1aff60598c346e5dc4afb5d6",
                "sha256": "a40e234353f3b1a1df743100a781949b84b48877578340e77dc5066899c06495"
            },
            "downloads": -1,
            "filename": "torch_struct-0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "c6658e4c1aff60598c346e5dc4afb5d6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 30369,
            "upload_time": "2021-02-14T02:43:47",
            "upload_time_iso_8601": "2021-02-14T02:43:47.357426Z",
            "url": "https://files.pythonhosted.org/packages/f3/e1/bb2ad949a56c25014e1a7c0e2b0f5a7f670eff876fe733156afe2119eede/torch_struct-0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "vulnerabilities": []
}