antislop-sampler  by sam-paech

Sampler for reducing undesirable LLM outputs via backtracking

created 10 months ago
310 stars

Top 87.8% on sourcepulse

GitHubView on GitHub
1 Expert Loves This Project
Project Summary

This project provides a novel sampler for Large Language Models (LLMs) designed to prevent repetitive or undesirable phrases ("slop") in generated text. It targets LLM developers and researchers seeking to improve output quality by enforcing custom content constraints, offering a more robust alternative to per-token logit biasing.

How It Works

The AntiSlop sampler employs a backtracking mechanism. When a disallowed phrase is detected in the generated output, the sampler reverts to the point where the phrase began and adjusts token probabilities to avoid that sequence. This approach is advantageous because it operates on full phrases rather than individual tokens, preventing the unintended down-regulation of common word beginnings. It supports string and regex matching for greater flexibility in constraint definition.

Quick Start & Requirements

  • API Server:
    git clone https://github.com/sam-paech/antislop-sampler.git && cd antislop-sampler
    pip install fastapi uvicorn ipywidgets IPython transformers bitsandbytes accelerate
    python3 run_api.py --model unsloth/Llama-3.2-3B-Instruct --slop_adjustments_file slop_phrase_prob_adjustments.json
    
  • Prerequisites: Python 3.11+ (for Open-WebUI integration), transformers, fastapi, uvicorn, bitsandbytes, accelerate. GPU recommended for model inference.
  • Integration: Can be used with Open-WebUI (requires Python 3.11) or directly via the OpenAI-compatible API server.
  • Docs: Backtracking visualisation notebook, Generate example notebook

Highlighted Details

  • Supports string and regex matching for phrase banning.
  • Backtracks and down-regulates probabilities of tokens leading to disallowed phrases.
  • Offers an OpenAI-compatible API server for easy integration.
  • Can enforce long-range constraints, demonstrated with a JSON validator.
  • Default slop list derived from over-represented LLM-generated words.

Maintenance & Community

  • Actively developed with recent updates in October 2024.
  • Research-grade code, indicating potential for bugs and ongoing development.
  • No explicit community links (Discord/Slack) mentioned.

Licensing & Compatibility

  • No license is explicitly stated in the README.
  • Compatibility with commercial or closed-source projects is uncertain without a license.

Limitations & Caveats

The API is minimalist, lacks concurrency support, and is geared towards local use and testing. Regex bans currently do not support streaming. The default slop list is auto-generated and not well-curated. The implementation is noted as research-grade and may contain bugs.

Health Check
Last commit

5 days ago

Responsiveness

1 day

Pull Requests (30d)
1
Issues (30d)
0
Star History
23 stars in the last 90 days

Explore Similar Projects

Starred by Chip Huyen Chip Huyen(Author of AI Engineering, Designing Machine Learning Systems), Andreas Jansson Andreas Jansson(Cofounder of Replicate), and
1 more.

lm-format-enforcer by noamgat

0.2%
2k
Format enforcer for language model outputs (JSON, regex, etc.)
created 1 year ago
updated 5 months ago
Starred by Tobi Lutke Tobi Lutke(Cofounder of Shopify), Stas Bekman Stas Bekman(Author of Machine Learning Engineering Open Book; Research Engineer at Snowflake), and
21 more.

guidance by guidance-ai

0.1%
21k
Guidance is a programming paradigm for steering LLMs
created 2 years ago
updated 1 day ago
Feedback? Help us improve.