Repository: https://github.com/sam-paech/antislop-vllm
AntiSlop-vLLM is a Python toolkit designed to improve the quality of text generated by Large Language Models (LLMs) by actively preventing "slop" – common, overused, or undesirable phrases, patterns, and n-grams. It works with any OpenAI-compatible API endpoint (like those provided by vLLM, llama.cpp, etc.) that supports the /v1/completions endpoint and can return top token logprobs.
This project is an evolution of the original antislop-sampler, adapted to work with OpenAI-compatible APIs rather than local Hugging Face transformers models.
The core idea is to generate text incrementally, validate it against a set of configurable rules, and if a violation is detected, backtrack and attempt to generate a different, compliant continuation. This is achieved by:
AntiSlop-vLLM can be used for single prompt completions or for generating entire datasets with reduced "slop." It also includes an automated pipeline (auto_unslop.py) for iteratively refining ban lists based on model outputs.
/v1/completions endpoint and provides top logprobs (e.g., vLLM, TGI, Anyscale, Together.ai, Fireworks.ai, Deepinfra, Lepton, etc.).auto_unslop.py):
config.yaml and command-line arguments./v1/completions endpoint of your specified API. It's crucial that the API can return logprobs for the generated tokens.request_mode: chunk) or token-by-token via a stream (request_mode: stream).SlopPhraseValidator: Checks against a list of exact phrases.RegexValidator: Matches text against a list of regex patterns.NGramValidator: Identifies banned n-grams in the text.ApiAntiSlopSampler uses the logprobs (alternative token probabilities) returned by the API for that specific position.force_backtrack: true).requirements.txt for specific versions):
openai>=1.0.0pyyaml>=6.0tiktoken>=0.4.0nltk>=3.6.0pandaswordfreqdatasetstqdmtransformers>=4.40.0 (for chat templates, refusal detector, and auto_unslop.py)regexClone the repository:
git clone https://github.com/sam-paech/antislop-vllm.git
cd antislop-vllm
Install dependencies:
pip install -r requirements.txt
NLTK Data: The scripts will attempt to download necessary NLTK resources (punkt for tokenization, stopwords for n-gram validation) if they are not found. You can also download them manually:
import nltk
nltk.download('punkt')
nltk.download('stopwords')
Configure config.yaml:
config-example.yaml to config.yaml.config.yaml to set your API endpoint (api_base_url), API key (if required), model_name, paths to ban lists, and default generation parameters.banlists/ directory. You should curate your own for best results.The primary script for generation is main.py. It can be run in single prompt mode or batch dataset generation mode. Configuration is primarily handled by config.yaml, but most settings can be overridden by command-line arguments.
Modify config.yaml for persistent settings. Key options include:
api_base_url, api_key, model_nameslop_phrases_file, top_n_slop_phrasesregex_blocklist_filengram_validator (including banned_file, remove_stopwords, language)generation_params (like max_new_tokens, temperature, top_p, top_k, min_p, chunk_size, request_mode)prompt_template, system_prompt (for dataset generation)logging_levelGenerates a single "unslotted" output for a given prompt and prints it to the console.
python main.py \
--api-base-url "http://localhost:8000/v1" \
--api-key "YOUR_API_KEY_OR_XXX" \
--model-name "Qwen/Qwen3-4B" \
--chat-template-model-id "Qwen/Qwen3-4B" \
--logging-level "INFO" \
--slop-phrases-file "banlists/slop_phrases.json" \
--top-n-slop_phrases 500 \
--regex-blocklist-file "banlists/regex_not_x_but_y.json" \
--ngram-banned-file "banlists/banned_ngrams.json" \
--max-new-tokens 500 \
--prompt "Write a short story about a brave knight and a mischievous dragon."
(Adjust --api-base-url, --api-key, --model-name, and --chat-template-model-id as needed.)
Generates multiple completions from prompts sourced from a Hugging Face dataset or a JSON file, saving the results to a JSONL file.
1. Start your vLLM (or other OpenAI-compatible) server: (This is just an example; adapt to your model and hardware.)
vllm serve unsloth/gemma-3-4b-it \
--port 8000 \
--max-model-len 2500 \
--served-model-name "unsloth/gemma-3-4b-it" \
--gpu-memory-utilization 0.95 \
--dtype bfloat16 \
--api-key "YOUR_API_KEY_IF_SERVER_NEEDS_ONE"
2. Run the main.py script in batch mode:
python main.py \
--config config.yaml \
--output-jsonl "results/creative_writing_generations.jsonl" \
--input-hf-dataset "Nitral-AI/Reddit-SFW-Writing_Prompts_ShareGPT" \
--hf-dataset-split "train" \
--threads 40 \
--max-prompts 100 \
--logging-level "INFO" \
--max-new-tokens 1000 \
--request-mode "chunk" \
--chunk-size 20 \
--ftpo-pairs-jsonl "results/ftpo_pairs.jsonl"
config.yaml but overrides some for batch processing.--input-hf-dataset: Specifies the source of prompts.--output-jsonl: Where the generated dataset will be saved.--threads: Number of parallel generation workers.--max-prompts: Limits the number of new prompts processed per run.--ftpo-pairs-jsonl: If specified, saves (chosen, rejected) token pairs for FTPO training (final token preference optimisation).Run AntiSlop as an OpenAI-compatible server. This lets you use any OpenAI client library while automatically applying anti-slop filtering.
1. Start your backend vLLM server:
vllm serve unsloth/gemma-3-4b-it --port 8000 --api-key xxx
2. Start the AntiSlop proxy server:
python main.py --openai-api --openai-api-port 8080 \
--api-base-url "http://localhost:8000/v1" \
--api-key "xxx" \
--model-name "unsloth/gemma-3-4b-it" \
--chat-template-model-id "unsloth/gemma-3-4b-it" \
--slop-phrases-file "banlists/slop_phrases.json" \
--top-n-slop-phrases 500
3. Use with any OpenAI client:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8080/v1", api_key="unused")
response = client.chat.completions.create(
model="unsloth/gemma-3-4b-it",
messages=[{"role": "user", "content": "Write a story about a princess."}],
max_tokens=500,
temperature=0.9
)
print(response.choices[0].message.content)
Supported request parameters: max_tokens, temperature, min_p, top_p, top_k, ban_strength.
See example_api_server.ipynb for a complete example.
auto_unslop.py)The auto_unslop.py script provides a pipeline for iteratively refining ban lists and improving generation quality. In each iteration, it:
main.py to generate a dataset using the current ban lists.banned_ngrams.json and banned_slop_phrases.json files with new entries.This process helps to automatically discover and mitigate model-specific "slop" over several iterations.
To run the iterative pipeline:
python auto_unslop.py
Make sure to configure parameters at the top of auto_unslop.py (like NUM_ITERATIONS, HF_DATASET_NAME, THREADS, paths to ban lists, etc.) and ensure your API server is running. The script will create a timestamped experiment directory under results/ to store outputs from each iteration.
For more detailed examples and an interactive way to explore the functionality, refer to the example_run_antislop_vllm.ipynb notebook in the repository.
antislop-samplerWhile antislop-vllm is based on the concepts of the original antislop-sampler, there are key differences:
antislop-vllm is designed for OpenAI-compatible remote APIs (like vLLM), whereas antislop-sampler worked directly with Hugging Face transformers models loaded locally.antislop-vllm relies entirely on the remote API to provide tokenization (via returned token strings in logprobs) and the logprobs themselves. The original sampler handled tokenization and logit calculation locally.antislop-vllm uses the /v1/completions endpoint, not /v1/chat/completions, as the former typically provides the necessary per-token logprob information required for backtracking.main.py: Main script for single/batch generation.auto_unslop.py: Iterative anti-slop and ban list refinement pipeline.config.yaml (and config-example.yaml): Configuration files.api_client/: Contains ApiClient for interacting with OpenAI-compatible APIs.core/:
sampler.py: ApiAntiSlopSampler - the core logic for generation, validation, and backtracking.models.py: Dataclasses for API results and violation info.state/:
generation_state.py: Manages the state of the text being generated.validators/: Implements different validation strategies (SlopPhraseValidator, RegexValidator, NGramValidator).utils/: Helper functions for configuration, string manipulation, chat templates, refusal detection, etc.banlists/: Directory for example ban list files (JSON format). Users should curate their own lists.data/: Can store auxiliary data like human writing profiles for auto_unslop.py.results/: Default output directory for batch generations and auto_unslop.py experiments.example_run_antislop_vllm.ipynb: Jupyter notebook with usage examples.auto_unslop.py script can help in this process./v1/completions specification and reliably returns top logprobs for backtracking to function effectively.Issues and Pull Requests are welcome!
If you use AntiSlop-vLLM or the concepts from the original antislop-sampler in your research, please consider citing:
@misc{paech2024antislop,
title={AntiSlop Sampler},
author={Samuel J. Paech},
year={2024},
howpublished={\url{https://github.com/sam-paech/antislop-sampler}}
}
And/or link to this repository: https://github.com/sam-paech/antislop-vllm
315 followers · starred Jul 2026
59 followers · starred Oct 2025
Repository: https://github.com/sam-paech/antislop-vllm
AntiSlop-vLLM is a Python toolkit designed to improve the quality of text generated by Large Language Models (LLMs) by actively preventing "slop" – common, overused, or undesirable phrases, patterns, and n-grams. It works with any OpenAI-compatible API endpoint (like those provided by vLLM, llama.cpp, etc.) that supports the /v1/completions endpoint and can return top token logprobs.
This project is an evolution of the original antislop-sampler, adapted to work with OpenAI-compatible APIs rather than local Hugging Face transformers models.
The core idea is to generate text incrementally, validate it against a set of configurable rules, and if a violation is detected, backtrack and attempt to generate a different, compliant continuation. This is achieved by:
AntiSlop-vLLM can be used for single prompt completions or for generating entire datasets with reduced "slop." It also includes an automated pipeline (auto_unslop.py) for iteratively refining ban lists based on model outputs.
/v1/completions endpoint and provides top logprobs (e.g., vLLM, TGI, Anyscale, Together.ai, Fireworks.ai, Deepinfra, Lepton, etc.).auto_unslop.py):
config.yaml and command-line arguments./v1/completions endpoint of your specified API. It's crucial that the API can return logprobs for the generated tokens.request_mode: chunk) or token-by-token via a stream (request_mode: stream).SlopPhraseValidator: Checks against a list of exact phrases.RegexValidator: Matches text against a list of regex patterns.NGramValidator: Identifies banned n-grams in the text.ApiAntiSlopSampler uses the logprobs (alternative token probabilities) returned by the API for that specific position.force_backtrack: true).requirements.txt for specific versions):
openai>=1.0.0pyyaml>=6.0tiktoken>=0.4.0nltk>=3.6.0pandaswordfreqdatasetstqdmtransformers>=4.40.0 (for chat templates, refusal detector, and auto_unslop.py)regexClone the repository:
git clone https://github.com/sam-paech/antislop-vllm.git
cd antislop-vllm
Install dependencies:
pip install -r requirements.txt
NLTK Data: The scripts will attempt to download necessary NLTK resources (punkt for tokenization, stopwords for n-gram validation) if they are not found. You can also download them manually:
import nltk
nltk.download('punkt')
nltk.download('stopwords')
Configure config.yaml:
config-example.yaml to config.yaml.config.yaml to set your API endpoint (api_base_url), API key (if required), model_name, paths to ban lists, and default generation parameters.banlists/ directory. You should curate your own for best results.The primary script for generation is main.py. It can be run in single prompt mode or batch dataset generation mode. Configuration is primarily handled by config.yaml, but most settings can be overridden by command-line arguments.
Modify config.yaml for persistent settings. Key options include:
api_base_url, api_key, model_nameslop_phrases_file, top_n_slop_phrasesregex_blocklist_filengram_validator (including banned_file, remove_stopwords, language)generation_params (like max_new_tokens, temperature, top_p, top_k, min_p, chunk_size, request_mode)prompt_template, system_prompt (for dataset generation)logging_levelGenerates a single "unslotted" output for a given prompt and prints it to the console.
python main.py \
--api-base-url "http://localhost:8000/v1" \
--api-key "YOUR_API_KEY_OR_XXX" \
--model-name "Qwen/Qwen3-4B" \
--chat-template-model-id "Qwen/Qwen3-4B" \
--logging-level "INFO" \
--slop-phrases-file "banlists/slop_phrases.json" \
--top-n-slop_phrases 500 \
--regex-blocklist-file "banlists/regex_not_x_but_y.json" \
--ngram-banned-file "banlists/banned_ngrams.json" \
--max-new-tokens 500 \
--prompt "Write a short story about a brave knight and a mischievous dragon."
(Adjust --api-base-url, --api-key, --model-name, and --chat-template-model-id as needed.)
Generates multiple completions from prompts sourced from a Hugging Face dataset or a JSON file, saving the results to a JSONL file.
1. Start your vLLM (or other OpenAI-compatible) server: (This is just an example; adapt to your model and hardware.)
vllm serve unsloth/gemma-3-4b-it \
--port 8000 \
--max-model-len 2500 \
--served-model-name "unsloth/gemma-3-4b-it" \
--gpu-memory-utilization 0.95 \
--dtype bfloat16 \
--api-key "YOUR_API_KEY_IF_SERVER_NEEDS_ONE"
2. Run the main.py script in batch mode:
python main.py \
--config config.yaml \
--output-jsonl "results/creative_writing_generations.jsonl" \
--input-hf-dataset "Nitral-AI/Reddit-SFW-Writing_Prompts_ShareGPT" \
--hf-dataset-split "train" \
--threads 40 \
--max-prompts 100 \
--logging-level "INFO" \
--max-new-tokens 1000 \
--request-mode "chunk" \
--chunk-size 20 \
--ftpo-pairs-jsonl "results/ftpo_pairs.jsonl"
config.yaml but overrides some for batch processing.--input-hf-dataset: Specifies the source of prompts.--output-jsonl: Where the generated dataset will be saved.--threads: Number of parallel generation workers.--max-prompts: Limits the number of new prompts processed per run.--ftpo-pairs-jsonl: If specified, saves (chosen, rejected) token pairs for FTPO training (final token preference optimisation).Run AntiSlop as an OpenAI-compatible server. This lets you use any OpenAI client library while automatically applying anti-slop filtering.
1. Start your backend vLLM server:
vllm serve unsloth/gemma-3-4b-it --port 8000 --api-key xxx
2. Start the AntiSlop proxy server:
python main.py --openai-api --openai-api-port 8080 \
--api-base-url "http://localhost:8000/v1" \
--api-key "xxx" \
--model-name "unsloth/gemma-3-4b-it" \
--chat-template-model-id "unsloth/gemma-3-4b-it" \
--slop-phrases-file "banlists/slop_phrases.json" \
--top-n-slop-phrases 500
3. Use with any OpenAI client:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8080/v1", api_key="unused")
response = client.chat.completions.create(
model="unsloth/gemma-3-4b-it",
messages=[{"role": "user", "content": "Write a story about a princess."}],
max_tokens=500,
temperature=0.9
)
print(response.choices[0].message.content)
Supported request parameters: max_tokens, temperature, min_p, top_p, top_k, ban_strength.
See example_api_server.ipynb for a complete example.
auto_unslop.py)The auto_unslop.py script provides a pipeline for iteratively refining ban lists and improving generation quality. In each iteration, it:
main.py to generate a dataset using the current ban lists.banned_ngrams.json and banned_slop_phrases.json files with new entries.This process helps to automatically discover and mitigate model-specific "slop" over several iterations.
To run the iterative pipeline:
python auto_unslop.py
Make sure to configure parameters at the top of auto_unslop.py (like NUM_ITERATIONS, HF_DATASET_NAME, THREADS, paths to ban lists, etc.) and ensure your API server is running. The script will create a timestamped experiment directory under results/ to store outputs from each iteration.
For more detailed examples and an interactive way to explore the functionality, refer to the example_run_antislop_vllm.ipynb notebook in the repository.
antislop-samplerWhile antislop-vllm is based on the concepts of the original antislop-sampler, there are key differences:
antislop-vllm is designed for OpenAI-compatible remote APIs (like vLLM), whereas antislop-sampler worked directly with Hugging Face transformers models loaded locally.antislop-vllm relies entirely on the remote API to provide tokenization (via returned token strings in logprobs) and the logprobs themselves. The original sampler handled tokenization and logit calculation locally.antislop-vllm uses the /v1/completions endpoint, not /v1/chat/completions, as the former typically provides the necessary per-token logprob information required for backtracking.main.py: Main script for single/batch generation.auto_unslop.py: Iterative anti-slop and ban list refinement pipeline.config.yaml (and config-example.yaml): Configuration files.api_client/: Contains ApiClient for interacting with OpenAI-compatible APIs.core/:
sampler.py: ApiAntiSlopSampler - the core logic for generation, validation, and backtracking.models.py: Dataclasses for API results and violation info.state/:
generation_state.py: Manages the state of the text being generated.validators/: Implements different validation strategies (SlopPhraseValidator, RegexValidator, NGramValidator).utils/: Helper functions for configuration, string manipulation, chat templates, refusal detection, etc.banlists/: Directory for example ban list files (JSON format). Users should curate their own lists.data/: Can store auxiliary data like human writing profiles for auto_unslop.py.results/: Default output directory for batch generations and auto_unslop.py experiments.example_run_antislop_vllm.ipynb: Jupyter notebook with usage examples.auto_unslop.py script can help in this process./v1/completions specification and reliably returns top logprobs for backtracking to function effectively.Issues and Pull Requests are welcome!
If you use AntiSlop-vLLM or the concepts from the original antislop-sampler in your research, please consider citing:
@misc{paech2024antislop,
title={AntiSlop Sampler},
author={Samuel J. Paech},
year={2024},
howpublished={\url{https://github.com/sam-paech/antislop-sampler}}
}
And/or link to this repository: https://github.com/sam-paech/antislop-vllm
315 followers · starred Jul 2026
59 followers · starred Oct 2025