Skip to main content

niacin

A Python library for replacing the missing variation in your text data.

PyPI version travis codecov readthedocs DOI

Why should I use this?

Data collected for model training necessarily undersamples the likely variance in the input space. This library is a collection of tools for inserting typical kinds of perturbations to better approximate population variance; and, for creating similar-but-incorrect examples to aid in reducing the total size of the hypothesis space. These are commonly known as ENRICHMENT and NEGATIVE SAMPLING, respectively.

How do I use this?

Functions in niacin are separated into submodules for specific data types. Functions expose a similar API, with two input arguments: the data to be transformed, and the probability of applying a specific transformation.

enrichment:

from niacin.text import en
data = "This is the song that never ends and it goes on and on my friends"
print(en.add_misspelling(data, p=1.0))
This is teh song tath never ends adn it goes on anbd on my firends

negative sampling:

from niacin.text import en
data = "This is the song that never ends and it goes on and on my friends"
print(en.add_hypernyms(data, p=1.0))
This is the musical composition that never extremity and it exit on and on my person

How do I install this?

with pip:

pip install niacin

from source:

git clone git@github.com:deniederhut/niacin.git && cd niacin && python setup.py install

If you have installed niacin from source, you can run the test suite to verify that everything is working properly. We use pytest, which you will first need to install:

pip install pytest

then you can run the library's tests with

pytest -m 'not slow'

if you would like to see the coverage report, you can do so with pytest-cov like so:

pip install pytest-cov
pytest -m 'not slow' --cov=niacin && coverage html

How can I install the optional dependencies?

If you want to use the backtranslate functionality, niacin will need pytorch and some other libraries. These can be installed as extras with:

pip install niacin[backtranslate]

If you are on macos, this might fail with a warning about your version of gcc:

Your compiler (g++) is not compatible with the compiler Pytorch was
built with for this platform, which is clang++ on darwin.

You can avoid this error by executing the following:

CFLAGS='-stdlib=libc++' pip install niacin[backtranslate]

Metadata

Release files for niacin 0.5.2

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

Source distribution (sdist)

Source distribution for niacin 0.5.2
File Size Uploaded
niacin-0.5.2.tar.gz 2.0 MB Details

Built distribution (wheel)

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

Total release size: 4.1 MB

Release files / niacin-0.5.2.tar.gz

Download URL niacin-0.5.2.tar.gz
Size 2.0 MB
Tags Source
SHA-256 checksum
How to use checksums
e2b8a714330c699fa384c8d2d8b1e3d502515d9be9d6c5a318d26426191b997a
BLAKE2b-256 checksum
How to use checksums
8b41403ae558a2456d437558636a2439373fba30aaca7782fdc8dc0e71628bfa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/0.0.0 pkginfo/1.9.6 readme-renderer/24.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/2.0.3 tqdm/4.65.0 importlib-metadata/6.8.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.12

Release files / niacin-0.5.2-py3-none-any.whl

Download URL niacin-0.5.2-py3-none-any.whl
Size 2.1 MB
Tags Python 3
SHA-256 checksum
How to use checksums
34d14216b06dd0740640ea83ab7b978a789d9df15d67b091284c082b10463202
BLAKE2b-256 checksum
How to use checksums
b5fe0bb65def689ed1519ad5a8da2585c67ef571f91862b7d1a0b37b9481f1e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/0.0.0 pkginfo/1.9.6 readme-renderer/24.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/2.0.3 tqdm/4.65.0 importlib-metadata/6.8.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.5.2 This release

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

1 release file

0.1.1

3 release files

0.1.0

3 release files

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