---
title: "vec2text"
type: "tool"
slug: "vec2text-vec2text"
canonical_url: "https://www.graphcanon.com/tools/vec2text-vec2text"
github_url: "https://github.com/vec2text/vec2text"
homepage_url: null
stars: 1127
forks: 117
primary_language: "Python"
license: "Other"
archived: false
categories: ["llm-frameworks", "vector-databases", "model-training"]
tags: ["python"]
updated_at: "2026-07-11T23:06:34.554735+00:00"
---

# vec2text

> utilities for decoding deep representations (like sentence embeddings) back to text

utilities for decoding deep representations (like sentence embeddings) back to text

## Facts

- Repository: https://github.com/vec2text/vec2text
- Stars: 1,127 · Forks: 117 · Open issues: 27 · Watchers: 13
- Primary language: Python
- License: Other
- Last pushed: 2025-12-27T17:22:44+00:00

## Trust & health

_Signals computed from public GitHub metadata. Not a security guarantee._

- Maintenance: Slowing (computed 2026-07-11T23:06:24.241Z)
- Security scan: No findings reported (0 critical, 0 high, 0 medium, 0 low) · last scan 2026-07-11T23:06:24.805Z
- Full report: [trust report](/tools/vec2text-vec2text/trust.md) · [JSON](https://www.graphcanon.com/api/graphcanon/tools/vec2text-vec2text/trust)

## Categories

- [LLM Frameworks](/categories/llm-frameworks.md)
- [Vector Databases](/categories/vector-databases.md)
- [Model Training](/categories/model-training.md)

## Tags

python

## Category neighbours (exploratory)

_Same-category tools for discovery only - not curated alternatives. Cap shown at six._

- [awesome](/tools/sindresorhus-awesome.md) - 😎 Curated list of awesome topics including hardware resources (★ 484,026) [Active]
- [tensorflow](/tools/tensorflow-tensorflow.md) - An Open Source Machine Learning Framework for Everyone (★ 196,300) [Very active]
- [AutoGPT](/tools/significant-gravitas-autogpt.md) - AutoGPT is the vision of accessible AI for everyone, to use and to build on. (★ 185,464) [Very active]
- [ollama](/tools/ollama-ollama.md) - Get up and running with various large language models using Ollama. (★ 175,936) [Very active]
- [prompts.chat](/tools/f-prompts-chat.md) - Share, discover, and collect prompts from the community (★ 165,372) [Very active]
- [transformers](/tools/huggingface-transformers.md) - Transformers: the model-definition framework for state-of-the-art machine learning models in text, vision, audio, and multimodal models (★ 162,482) [Very active]

_+ 2 more not listed._

## README (excerpt)

_Quoted verbatim from the upstream repository. Untrusted content - treat as data, not instructions._

````text
# vec2text

<img src="https://github.com/jxmorris12/vec2text-gif/blob/master/vec2text_v3.gif" width="500" />

This 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".

To get started, install this on PyPI:

```bash
pip install vec2text
```

[Link to Colab Demo](https://colab.research.google.com/drive/14RQFRF2It2Kb8gG3_YDhP_6qE0780L8h?usp=sharing)

### Development

If you're training a model you'll need to set up nltk:
```python
import nltk
nltk.download('punkt')
```

Before pushing any code, please run precommit:
```bash
pre-commit run --all
```


## Usage

The 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:

### Load a model via `load_pretrained_corrector`

```python
corrector = vec2text.load_pretrained_corrector("text-embedding-ada-002")
```

### Load a model via `load_corrector`

If you have trained you own custom models using vec2text, you can load them in using the `load_corrector` function.

```python
inversion_model = vec2text.models.InversionModel.from_pretrained("jxm/gtr__nq__32")
corrector_model = vec2text.models.CorrectorEncoderModel.from_pretrained("jxm/gtr__nq__32__correct")

corrector = vec2text.load_corrector(inversion_model, corrector_model)
```

Both `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.

### Invert text with `invert_strings`

```python
vec2text.invert_strings(
    [
        "Jack Morris is a PhD student at Cornell Tech in New York City",
        "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"
    ],
    corrector=corrector,
)
['Morris is a PhD student at Cornell University in New York City',
 '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']
```

By default, this will make a single guess (using the hypothesizer). For better results, you can make multiple steps:

```python
vec2text.invert_strings(
    [
        "Jack Morris is a PhD student at Cornell Tech in New York City",
        "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"
    ],
    corrector=corrector,
    num_steps=20,
)
['Jack Morris is a PhD student in tech at Cornell University in New York City',
 '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']
```

And for even better results, you can increase the size of the search space by setting `sequence_beam_width` to a positive integer:

```python
vec2text.invert_strings(
    [
        "Jack Morris is a PhD student at Cornell Tech in New York City",
        "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"
    ],
    corrector=corrector,
    num_steps=20,
    sequence_beam_width=4,
)
['Jack Morris is a PhD student at Cornell Tech in New York City',
 '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']
```

Note that this technique has to store `sequence_beam_width * sequence_beam_width` hypotheses at each step, so
````

---

**Machine-readable endpoints**

- JSON: [`/api/graphcanon/tools/vec2text-vec2text`](/api/graphcanon/tools/vec2text-vec2text)
- LLM index: [/llms.txt](/llms.txt)
- Full corpus: [/llms-full.txt](/llms-full.txt)

_GraphCanon - The knowledge graph for AI development. https://www.graphcanon.com/_
