Skip to content

A C++/Python library for efficiently iterating over high-probability label-assignments

License

Notifications You must be signed in to change notification settings

ArthurDevNL/lazyk

Repository files navigation

main

lazyk

A C++/Python library for efficiently iterating over high-probability label-assignments.

Installation

You know the drill

pip install lazy-k

Usage

The library can be used to iterate over the high-probability label-assignments of a given probability matrix. The following example shows how to use the library to iterate over the high-probability label-assignments of a 3x3 probability matrix.

from lazyk import lazyk
import numpy as np

probs = np.arange(1, 10).reshape(3, -1)
probs = probs / probs.sum(axis=1, keepdims=True)

for seq in lazyk(probs, cache_assignments=True): # cache_assignments is true by default, but can be turned off for lower memory usage but might be slower
    print(seq)

The cache_assignments parameter indicates whether the algorithm should cache the intermediate label-assignments. This will improve the running speed of the algorithm but also require more memory. The default value is True but can be turned off if memory is a concern.

More information can be found in the paper "Lazy-k Decoding: Constrained Decoding for Information Extraction".

About

A C++/Python library for efficiently iterating over high-probability label-assignments

Resources

License

Stars

Watchers

Forks

Packages

No packages published