Skip to main content

Modification of cpython `re` module in which patterns match any string that is a prefix of a matching string under its regex

Project description

Modified Regex for Syntactically Constrained LLM Sampling

The scs_re package is a modified version of the python re module that returns a match for any prefix of a string matching the original regex pattern. For example, the pattern ^abcd matches the string abc. This behavior is used to consider the validity of beams under a particular regex pattern during a language model's output generation.

Note: This behavior is only expected for patterns that begin with ^ and end with $ and therefore define a match contstraint over all characters in a sequence.

Building from source

We use the _sre module from the python 3.11 branch of Python/cpython/Modules/_sre. You can clone the original source by running

svn export https://github.com/python/cpython/branches/3.11/Modules/_sre _sre

The module requires python 3.11 headers to compile. To install run

wget https://www.python.org/ftp/python/3.11.3/Python-3.11.3.tar.xz
tar xf Python-3.11.3.tar.xz
cd Python-3.11.3
./configure --enable-optimizations --enable-shared
make -j$(nproc)
sudo make altinstall

Then you can install the package with sudo python3.11 setup.py install to install. The python version you install to must be the same version whose headers were compiled against.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scs_re-1.0.3.tar.gz (43.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scs_re-1.0.3-py3.11-linux-x86_64.egg (313.5 kB view details)

Uploaded Egg

File details

Details for the file scs_re-1.0.3.tar.gz.

File metadata

  • Download URL: scs_re-1.0.3.tar.gz
  • Upload date:
  • Size: 43.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for scs_re-1.0.3.tar.gz
Algorithm Hash digest
SHA256 9fdc3086ec3720bf87d3f80bf9d946e96d05537fc56bffad9b9f8591d3487ed4
MD5 49480a6ce695fdd39848d8bc91b5bc0b
BLAKE2b-256 03591a553d28b71c64df76133b296df7bd6c2cb591790f7d9427af8ea87d092d

See more details on using hashes here.

File details

Details for the file scs_re-1.0.3-py3.11-linux-x86_64.egg.

File metadata

  • Download URL: scs_re-1.0.3-py3.11-linux-x86_64.egg
  • Upload date:
  • Size: 313.5 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for scs_re-1.0.3-py3.11-linux-x86_64.egg
Algorithm Hash digest
SHA256 d4e565caf9a451b4ae562eaf803b0f258e3ea5bd3dc9993d94c81e88d1469066
MD5 4b57da19334f2de28eae877f5d0f8a63
BLAKE2b-256 ee79315368f9dc3e63f0499f0ecac0100efc5fc80f9a5d637ae21d3480467f35

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page