{"data":{"slug":"vec2text-vec2text","name":"vec2text","tagline":"utilities for decoding deep representations (like sentence embeddings) back to text","github_url":"https://github.com/vec2text/vec2text","owner":"vec2text","repo":"vec2text","owner_avatar_url":"https://avatars.githubusercontent.com/u/191514557?v=4","primary_language":"Python","stars":1127,"forks":117,"topics":[],"archived":false,"github_pushed_at":"2025-12-27T17:22:44+00:00","maintenance_label":"Slowing","url":"https://www.graphcanon.com/tools/vec2text-vec2text","markdown_url":"https://www.graphcanon.com/tools/vec2text-vec2text.md","api_url":"https://www.graphcanon.com/api/graphcanon/tools/vec2text-vec2text","graph_url":"https://www.graphcanon.com/api/graphcanon/graph?tool=vec2text-vec2text","description":"utilities for decoding deep representations (like sentence embeddings) back to text","homepage_url":null,"license":"Other","open_issues":27,"watchers":13,"ai_summary":null,"readme_excerpt":"# vec2text\n\n<img src=\"https://github.com/jxmorris12/vec2text-gif/blob/master/vec2text_v3.gif\" width=\"500\" />\n\nThis library contains code for doing text embedding inversion. We can train various architectures that reconstruct text sequences from embeddings as well as run pre-trained models. This repository contains code for the papers \"Text Embeddings Reveal (Almost) As Much As Text\" and \"Language Model Inversion\".\n\nTo get started, install this on PyPI:\n\n```bash\npip install vec2text\n```\n\n[Link to Colab Demo](https://colab.research.google.com/drive/14RQFRF2It2Kb8gG3_YDhP_6qE0780L8h?usp=sharing)\n\n### Development\n\nIf you're training a model you'll need to set up nltk:\n```python\nimport nltk\nnltk.download('punkt')\n```\n\nBefore pushing any code, please run precommit:\n```bash\npre-commit run --all\n```\n\n\n## Usage\n\nThe library can be used to embed text and then invert it, or invert directly from embeddings. First you'll need to construct a `Corrector` object which wraps the necessary models, embedders, and tokenizers:\n\n### Load a model via `load_pretrained_corrector`\n\n```python\ncorrector = vec2text.load_pretrained_corrector(\"text-embedding-ada-002\")\n```\n\n### Load a model via `load_corrector`\n\nIf you have trained you own custom models using vec2text, you can load them in using the `load_corrector` function.\n\n```python\ninversion_model = vec2text.models.InversionModel.from_pretrained(\"jxm/gtr__nq__32\")\ncorrector_model = vec2text.models.CorrectorEncoderModel.from_pretrained(\"jxm/gtr__nq__32__correct\")\n\ncorrector = vec2text.load_corrector(inversion_model, corrector_model)\n```\n\nBoth `vec2text.models.InversionModel` and `vec2text.models.CorrectorEncoderModel` classes inherit `transformers.PreTrainedModel` therefore you can pass in a Hugging Face model name or path to a local directory.\n\n### Invert text with `invert_strings`\n\n```python\nvec2text.invert_strings(\n    [\n        \"Jack Morris is a PhD student at Cornell Tech in New York City\",\n        \"It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity\"\n    ],\n    corrector=corrector,\n)\n['Morris is a PhD student at Cornell University in New York City',\n 'It was the age of incredulity, the age of wisdom, the age of apocalypse, the age of apocalypse, it was the age of faith, the age of best faith, it was the age of foolishness']\n```\n\nBy default, this will make a single guess (using the hypothesizer). For better results, you can make multiple steps:\n\n```python\nvec2text.invert_strings(\n    [\n        \"Jack Morris is a PhD student at Cornell Tech in New York City\",\n        \"It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity\"\n    ],\n    corrector=corrector,\n    num_steps=20,\n)\n['Jack Morris is a PhD student in tech at Cornell University in New York City',\n 'It was the best time of the epoch, it was the worst time of the epoch, it was the best time of the age of wisdom, it was the age of incredulity, it was the age of betrayal']\n```\n\nAnd for even better results, you can increase the size of the search space by setting `sequence_beam_width` to a positive integer:\n\n```python\nvec2text.invert_strings(\n    [\n        \"Jack Morris is a PhD student at Cornell Tech in New York City\",\n        \"It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity\"\n    ],\n    corrector=corrector,\n    num_steps=20,\n    sequence_beam_width=4,\n)\n['Jack Morris is a PhD student at Cornell Tech in New York City',\n 'It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity']\n```\n\nNote that this technique has to store `sequence_beam_width * sequence_beam_width` hypotheses at each step, so","github_created_at":"2023-02-25T18:07:28+00:00","created_at":"2026-07-11T23:06:23.013662+00:00","updated_at":"2026-07-11T23:06:34.554735+00:00","categories":[{"slug":"llm-frameworks","name":"LLM Frameworks","url":"https://www.graphcanon.com/categories/llm-frameworks","markdown_url":"https://www.graphcanon.com/categories/llm-frameworks.md","api_url":"https://www.graphcanon.com/api/graphcanon/categories/llm-frameworks"},{"slug":"vector-databases","name":"Vector Databases","url":"https://www.graphcanon.com/categories/vector-databases","markdown_url":"https://www.graphcanon.com/categories/vector-databases.md","api_url":"https://www.graphcanon.com/api/graphcanon/categories/vector-databases"},{"slug":"model-training","name":"Model Training","url":"https://www.graphcanon.com/categories/model-training","markdown_url":"https://www.graphcanon.com/categories/model-training.md","api_url":"https://www.graphcanon.com/api/graphcanon/categories/model-training"}],"tags":[{"slug":"python","name":"python"}],"trust":{"provenance":{"is_fork":false,"github_id":606513874,"owner_type":"Organization","methodology":"github_public_v1","parent_repo":null,"near_duplicate_slugs":[]},"computed_at":"2026-07-11T23:06:24.241Z","maintenance":{"label":"Slowing","score":36,"methodology":"github_public_v1","releases_90d":0,"days_since_push":196,"last_release_at":null},"security_summary":{"status":"ok","scanner":"osv@v1","low_count":0,"high_count":0,"last_scan_at":"2026-07-11T23:06:24.805Z","medium_count":0,"scan_profile":"deps","critical_count":0}},"capability_facts":{"scan":{"source":"repo_scan","observed_at":"2026-07-11T23:06:23.973Z"},"languages":{"value":["python"],"source":"github.language","observed_at":"2026-07-11T23:06:23.973Z"},"license_spdx":{"value":"Other","source":"github.license","observed_at":"2026-07-11T23:06:23.973Z"}}}}