Skip to main content

Nerpii

Nerpii is a Python library developed to perform Named Entity Recognition (NER) on structured datasets and synthesize Personal Identifiable Information (PII).

NER is performed with Presidio and with a NLP model available on HuggingFace, while the PII generation is based on Faker.

Installation

You can install Nerpii by using pip:

pip install nerpii

Quickstart

Named Entity Recognition

You can import the NamedEntityRecognizer using

from nerpii.named_entity_recognizer import NamedEntityRecognizer

You can create a recognizer passing as parameter a path to a csv file or a Pandas Dataframe

recognizer = NamedEntityRecognizer('./csv_path.csv', lang)

The lang parameter is used to define the language of the dataset. The deafult value is en (english), but it can be also selelcted it (italian).

Please note that if there are columns in the dataset containing names of people consisting of first and last names (e.g. John Smith), before creating a recognizer, it is necessary to split the name into two different columns called first_name and last_name using the function split_name().

from nerpii.named_entity_recognizer import split_name

df = split_name('./csv_path.csv', name_of_column_to_split)

The NamedEntityRecognizer class contains three methods to perform NER on a dataset:

recognizer.assign_entities_with_presidio()

which assigns Presidio entities, listed here

recognizer.assign_entities_manually()

which assigns manually ZIPCODE and CREDIT_CARD_NUMBER entities

recognizer.assign_organization_entity_with_model()

which assigns ORGANIZATION entity using a NLP model available on HuggingFace.

To perform NER, you have to run these three methods sequentially, as reported below:

recognizer.assign_entities_with_presidio()
recognizer.assign_entities_manually()
recognizer.assign_organization_entity_with_model()

The final output is a dictionary in which column names are given as keys and assigned entities and a confidence score as values.

This dictionary can be accessed using

recognizer.dict_global_entities

PII generation

After performing NER on a dataset, you can generate new PII using Faker.

You can import the FakerGenerator using

from nerpii.faker_generator import FakerGenerator

You can create a generator using

generator = FakerGenerator(dataset, recognizer.dict_global_entities)

If you want to generate Italian PII, add lang = "it" as parameter to the previous object (default: lang = "en")

To generate new PII you can run

generator.get_faker_generation()

The method above can generate the following PII:

  • address
  • phone number
  • email naddress
  • first name
  • last name
  • city
  • state
  • url
  • zipcode
  • credit card
  • ssn
  • country

Examples

You can find a notebook example in the notebook folder.

Release files for nerpii 0.2.4

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

Source distribution (sdist)

Source distribution for nerpii 0.2.4
File Size Uploaded
nerpii-0.2.4.tar.gz 9.5 kB Details

Built distribution (wheel)

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

Total release size: 19.3 kB

Release files / nerpii-0.2.4.tar.gz

Download URL nerpii-0.2.4.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ae68e5f8a873a3311ebcd25ad81a21a5ae255055fbeef9bcbea79d0186756af4
BLAKE2b-256 checksum
How to use checksums
591696156fb41e57a2b09448b82576b55317b28012854dc4f61bfe16847c21ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.9.19 Linux/6.5.0-1018-azure

Release files / nerpii-0.2.4-py3-none-any.whl

Download URL nerpii-0.2.4-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f6dedfd1daee0a06ef0ea7b39500f1a9cdaaf9f5b5aa2c63994a9241a598ba4c
BLAKE2b-256 checksum
How to use checksums
37fc3097742ff307eeb59bdbb76c9a8f0883ed02cd8e8c79bd31c03cb8000f70
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.9.19 Linux/6.5.0-1018-azure

Release history Release notifications | RSS feed

This release

0.2.4 This release

2 release files

0.2.3

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 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