Skip to main content

A python library to perform NER on structured data and generate PII with Faker

Project description

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')

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.

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.

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

nerpii-0.2.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

nerpii-0.2.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file nerpii-0.2.0.tar.gz.

File metadata

  • Download URL: nerpii-0.2.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.9.18 Linux/6.2.0-1018-azure

File hashes

Hashes for nerpii-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5ac749de2d1b3eb16fc40e9f5ad5adeb0202425f10c6079c5e2ae00ef8118cf7
MD5 27271e9c94d8d737afe96ae5b65af74b
BLAKE2b-256 967d34c35b29c10400538791fd150ace858bf1282ab7dd4a736e2801e27e7ae1

See more details on using hashes here.

File details

Details for the file nerpii-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: nerpii-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.9.18 Linux/6.2.0-1018-azure

File hashes

Hashes for nerpii-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cfc073c11cde1cb12478a0924a22a6e8c42c58cca2f3b8fe9633ad603ade5cd1
MD5 e2b3a2e42b60236c381702a3230af9d4
BLAKE2b-256 18e4408f057651aa75b41def91a69c7cfcd9d3ceee5d76ae9549267ad46aa37f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page