Skip to main content

UGLD

Uncertainty-Gated Lexical Decoding (UGLD) logits processors for HuggingFace Transformers.

Install

pip install ugld

Usage

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, LogitsProcessorList
from ugld import UGLD_Towards, UGLDTowardsConfig

model_name = "gpt2"
tok = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

simple_words = [
        " simple", " easy", " basic", " clear",
        " small", " big", " light", " heavy",
        " fast", " slow", " old", " new",
        " good", " bad", " near", " far",
        " start", " end", " help", " use",
    ]

green_ids = []
for w in simple_words:
    green_ids.extend(tok.encode(w, add_special_tokens=False))

green_ids = list(set(green_ids))

proc = LogitsProcessorList([
    UGLD_Towards(UGLDTowardsConfig(
        green_token_ids=green_ids,
        alpha_max=0.5,
        tau=1.0,
        s=0.3,
        prior="renorm",
    ))
])

inputs = tok("Explain gravity in", return_tensors="pt")

out = model.generate(
    **inputs,
    max_new_tokens=50,
    logits_processor=proc,
)
print(tok.decode(out[0], skip_special_tokens=True))

Metadata

Release files for ugld 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ugld 1.0.0
File Size Uploaded Provenance Actions
ugld-1.0.0.tar.gz 10.6 kB Without provenance Details for ugld-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ugld 1.0.0
File Interpreter ABI Platform Actions
ugld-1.0.0-py3-none-any.whl Python 3 none any Details for ugld-1.0.0-py3-none-any.whl

Total release size: 20.3 kB

Release files / ugld-1.0.0.tar.gz

Download URL ugld-1.0.0.tar.gz
Size 10.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0a496d4ff96ce3e39a6a1286e0e70b12dafdffb44481320ac43ebc641bd91087
BLAKE2b-256 checksum
How to use checksums
d95e5d0dc94ce7025c690b921b85f5240591dfe41e202b94a75ab2a2357d947d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Release files / ugld-1.0.0-py3-none-any.whl

Download URL ugld-1.0.0-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e25278c64a4a1d65d60bffab1b7629175f8cccea0061e409c3389e970079246c
BLAKE2b-256 checksum
How to use checksums
da32c930fbd355636de5084d885e5714d1b68cc42231fed6e20c92a640b8776d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Security for ugld 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page