Uncertainty-Gated Lexical Decoding (UGLD) logits processors for HuggingFace Transformers.
Project description
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))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ugld-1.0.0.tar.gz
(10.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
ugld-1.0.0-py3-none-any.whl
(9.8 kB
view details)
File details
Details for the file ugld-1.0.0.tar.gz.
File metadata
- Download URL: ugld-1.0.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a496d4ff96ce3e39a6a1286e0e70b12dafdffb44481320ac43ebc641bd91087
|
|
| MD5 |
d2ca47561a8a82af3fb934f7bbf5d374
|
|
| BLAKE2b-256 |
d95e5d0dc94ce7025c690b921b85f5240591dfe41e202b94a75ab2a2357d947d
|
File details
Details for the file ugld-1.0.0-py3-none-any.whl.
File metadata
- Download URL: ugld-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e25278c64a4a1d65d60bffab1b7629175f8cccea0061e409c3389e970079246c
|
|
| MD5 |
57d0955b69c8c7661064bc45beb6d78a
|
|
| BLAKE2b-256 |
da32c930fbd355636de5084d885e5714d1b68cc42231fed6e20c92a640b8776d
|