Code repo for "Most Language Models can be Poets too: An AI Writing Assistant and Constrained Text Generation Studio" at the (CAI2) workshop, jointly held at (COLING 2022)
Python
217
32 commits
updated Apr 11, 2026
Constrained Text Generation Studio (CTGS) is an AI writing assistant for recreational linguists, poets, creative writers, and researchers to use and study the ability of large language models to generate constrained text.
CTGS allows users to generate or choose from text with any combination of a wide variety of constraints, such as banning a particular letter, forcing generated words to have a certain number of syllables, and/or forcing words to be partial anagrams of another word. A partial list of these sorts of constraints can be found here.
At each generation step, a language model samples from a probability distribution over its entire vocabulary. CTGS filters or penalizes tokens that violate the chosen constraints before the sampling step. This has two advantages over fine-tuning:
Previous versions of CTGS suffered from a fundamental problem: when constraints were too strict, they would filter out all tokens from the top-k/top-p candidate pool, leaving the model with nothing to say. This vocabulary crippling problem has been solved with three mechanisms:
CTGS, along with its datasets and a HuggingFace Space called Gadsby, are presented in the paper "Most Language Models can be Poets too: An AI Writing Assistant and Constrained Text Generation Studio", appearing at The Second Workshop on When Creative AI Meets Conversational AI (CAI2), jointly held at COLING 2022.
CTGS consists of 4 main components: the model, the constraint engine, the filters, and the text transforms.
CTGS supports any causal language model available on HuggingFace, with support for 32-bit, 16-bit, and 8-bit precision loading.
The constraint engine provides three settings that control how constraints interact with the language model:
CTGS has 21 constraint filters organized into 4 categories. Any combination can be applied simultaneously:
Lexical Constraints
Phonetic Constraints
Semantic Constraints
Structural Constraints
Text transforms are applied to tokens before constraint filtering. They increase the vocabulary that survives filtering:
git clone https://github.com/Hellisotherpeople/Constrained-Text-Generation-Studio.git
cd Constrained-Text-Generation-Studio
uv sync
uv run python Constrained-Text-Generation-Studio.py
git clone https://github.com/Hellisotherpeople/Constrained-Text-Generation-Studio.git
cd Constrained-Text-Generation-Studio
pip install -r requirements.txt
python Constrained-Text-Generation-Studio.py
The first run will download the default model (EleutherAI/pythia-1b) and FastText embeddings from HuggingFace. This may take several minutes depending on your internet connection.
Wait for model loading - Check the Model Settings window for loading status. The status text will confirm when the model is ready.
Type or paste text into the main text box.
Press F1 (or click "Predict New Tokens") to generate constraint-aware suggestions. Right-click in the text box to see them.
Press F2 (or click "Generate Tokens") to auto-insert tokens directly.
| Key | Action |
|---|---|
| F1 | Predict new token candidates (populates right-click menu) |
| F2 | Insert a single token directly into the text |
distilgpt2 or EleutherAI/pythia-160m for rapid iteration, then switch to larger models for quality.Enter any HuggingFace causal language model name in the Model Settings window and click "Load Model". Popular options:
distilgpt2 - Fast, small (good for testing)EleutherAI/pythia-160m - Small but capableEleutherAI/pythia-1b - Default, good balanceEleutherAI/pythia-2.8b - Higher quality (needs more RAM/VRAM)meta-llama/Llama-2-7b-hf - High quality (needs GPU + HF access token)Use 16-bit or 8-bit precision for larger models to reduce memory usage.
CTGS is built with:
The application uses a tiling window layout with docking enabled - windows can be rearranged and docked to your preference. Hover over green (?) icons throughout the interface for contextual help.
32 commits
Python
100.0%
Code repo for "Most Language Models can be Poets too: An AI Writing Assistant and Constrained Text Generation Studio" at the (CAI2) workshop, jointly held at (COLING 2022)
Python
217
32 commits
updated Apr 11, 2026
Constrained Text Generation Studio (CTGS) is an AI writing assistant for recreational linguists, poets, creative writers, and researchers to use and study the ability of large language models to generate constrained text.
CTGS allows users to generate or choose from text with any combination of a wide variety of constraints, such as banning a particular letter, forcing generated words to have a certain number of syllables, and/or forcing words to be partial anagrams of another word. A partial list of these sorts of constraints can be found here.
At each generation step, a language model samples from a probability distribution over its entire vocabulary. CTGS filters or penalizes tokens that violate the chosen constraints before the sampling step. This has two advantages over fine-tuning:
Previous versions of CTGS suffered from a fundamental problem: when constraints were too strict, they would filter out all tokens from the top-k/top-p candidate pool, leaving the model with nothing to say. This vocabulary crippling problem has been solved with three mechanisms:
CTGS, along with its datasets and a HuggingFace Space called Gadsby, are presented in the paper "Most Language Models can be Poets too: An AI Writing Assistant and Constrained Text Generation Studio", appearing at The Second Workshop on When Creative AI Meets Conversational AI (CAI2), jointly held at COLING 2022.
CTGS consists of 4 main components: the model, the constraint engine, the filters, and the text transforms.
CTGS supports any causal language model available on HuggingFace, with support for 32-bit, 16-bit, and 8-bit precision loading.
The constraint engine provides three settings that control how constraints interact with the language model:
CTGS has 21 constraint filters organized into 4 categories. Any combination can be applied simultaneously:
Lexical Constraints
Phonetic Constraints
Semantic Constraints
Structural Constraints
Text transforms are applied to tokens before constraint filtering. They increase the vocabulary that survives filtering:
git clone https://github.com/Hellisotherpeople/Constrained-Text-Generation-Studio.git
cd Constrained-Text-Generation-Studio
uv sync
uv run python Constrained-Text-Generation-Studio.py
git clone https://github.com/Hellisotherpeople/Constrained-Text-Generation-Studio.git
cd Constrained-Text-Generation-Studio
pip install -r requirements.txt
python Constrained-Text-Generation-Studio.py
The first run will download the default model (EleutherAI/pythia-1b) and FastText embeddings from HuggingFace. This may take several minutes depending on your internet connection.
Wait for model loading - Check the Model Settings window for loading status. The status text will confirm when the model is ready.
Type or paste text into the main text box.
Press F1 (or click "Predict New Tokens") to generate constraint-aware suggestions. Right-click in the text box to see them.
Press F2 (or click "Generate Tokens") to auto-insert tokens directly.
| Key | Action |
|---|---|
| F1 | Predict new token candidates (populates right-click menu) |
| F2 | Insert a single token directly into the text |
distilgpt2 or EleutherAI/pythia-160m for rapid iteration, then switch to larger models for quality.Enter any HuggingFace causal language model name in the Model Settings window and click "Load Model". Popular options:
distilgpt2 - Fast, small (good for testing)EleutherAI/pythia-160m - Small but capableEleutherAI/pythia-1b - Default, good balanceEleutherAI/pythia-2.8b - Higher quality (needs more RAM/VRAM)meta-llama/Llama-2-7b-hf - High quality (needs GPU + HF access token)Use 16-bit or 8-bit precision for larger models to reduce memory usage.
CTGS is built with:
The application uses a tiling window layout with docking enabled - windows can be rearranged and docked to your preference. Hover over green (?) icons throughout the interface for contextual help.
32 commits
Python
100.0%