Skip to main content

A collection of sampling methods for machine learning implemented on numpy.

Project description

Samplings

=========

A collection of sampling methods for machine learning implemented on numpy.

Author: Sander Wood

Provides

  1. Gamma sampling for controllable generation
  2. Local temperature sampling with weights
  3. Nucleus sampling (top-p sampling)
  4. Top-k sampling
  5. Random sampling

How to use


As you probably know, sampling means randomly picking the next token according to its conditional probability distribution. In other words, given the same probability distribution, you may get a different result each time. If you want to get rid of this uncertainty, you can set seed to a fixed value.

By default, all the functions in samplings return the index of the next token. However, you can ask them to return the modified probability distribution by set return_probs as True. Then, you can make further manipulations based on this probability distribution.

In addition to the probability distribution, most sampling methods require other parameters for modifying the probability distribution to achieve desired results. Please refer to the docstring of each function for details.

About gamma sampling


Gamma sampling is a method of tuning probabilities of target tokens to achieve controlling specific properties of the generated sequence. The basic assumption is that some attributes of sequences are closely related to the frequencies of some tokens. As long as the controllable attribute can be defined at the token level, prior knowledge can be directly brought into the sampling process, allowing arbitrary models to support customisable and controllable generation.

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

samplings-0.1.7.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

samplings-0.1.7-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file samplings-0.1.7.tar.gz.

File metadata

  • Download URL: samplings-0.1.7.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.9

File hashes

Hashes for samplings-0.1.7.tar.gz
Algorithm Hash digest
SHA256 647f85b0bed5651b3717c05528e37f00b6c710e5679b641e129554eecc135d1c
MD5 82961960ffcdba262dc0cf126181d9fa
BLAKE2b-256 38cdd92f0ef943e7fd3208cf611fd06e945bea4ec37844616129da2a7bb20527

See more details on using hashes here.

File details

Details for the file samplings-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: samplings-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.9

File hashes

Hashes for samplings-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 e822913cf7498a5465027461a4b6986d19fb379c346492683236c77da98f8284
MD5 69969f550580980bcf37e56b2b521421
BLAKE2b-256 00c9fb82c0010e855425537f5ddbecb8b8cd47277a2ca52d9cec687426f2ab37

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