Downloads · 30 days
0
King-Harry/Ninja-Masker-2-PII-Redaction
Ninja-Masker-2-PII-Redaction is a machine learning model from King-Harry. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
Downloads · 30 days
0
Access
Public
Updated Aug 23, 2024
Repo size
169 MB
Likes
4
Public
Click a slice to open those files.
.safetensors168 MB · 94%
From the Hugging Face model README

Ninja Masker 2
Model Name: Ninja-Masker-2-PII-Redaction
Model Type: Language Model for PII Redaction
License: Apache 2.0
Model Creator: Harry Roy McLaughlin
Model Repository: Hugging Face Hub - Ninja-Masker-2-PII-Redaction
Ninja-Masker-2-PII-Redaction is an updated fine-tuned language model designed to identify and redact Personally Identifiable Information (PII) from text data. The model is based on the Meta-Llama-3.1-8B architecture and has been fine-tuned on a dataset of over 30,000 input-output pairs to perform accurate PII masking using a set of predefined tags. It is nice and small and thus fairly cost efficient, yet powerful.
The training data was formatted using a specific Alpaca-style prompt structure. Each prompt was paired with an instruction and input context, and the model was trained to generate the appropriate redacted output. The model was trained on a variety of PII types, including but not limited to names, email addresses, phone numbers, and credit card information.
To optimize performance and reduce memory usage, the model was fine-tuned using 4-bit quantization. Additional optimizations included the use of Flash Attention (Xformers) and gradient checkpointing, which allowed for efficient training and inference.
The model was evaluated based on its ability to accurately redact PII from text while maintaining the original context and meaning. The fine-tuning process resulted in a model that effectively identifies and replaces PII with the appropriate tags in various text scenarios.
The model is designed for responsible data management, ensuring that sensitive information is properly anonymized. However, users should be aware of the limitations and should not rely solely on automated redaction for highly sensitive data.
To use this model, you can load it from the Hugging Face Hub and integrate it into your Python or API-based applications. Below is an example of how to load and use the model:
# Install necessary packages from the unsloth GitHub repository and others required for model handling and optimizations.
!pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
!pip install --no-deps "xformers<0.0.27" "trl<0.9.0" peft accelerate bitsandbytes
# Import the necessary classes from the transformers and unsloth libraries.
from transformers import AutoModelForCausalLM, AutoTokenizer
from unsloth import FastLanguageModel
# Specify the name of the fine-tuned model hosted on Hugging Face Hub and load it along with its tokenizer.
# The model is loaded in 4-bit precision to optimize memory usage and speed.
model_name = "King-Harry/Ninja-Masker-2-PII-Redaction"
model, tokenizer = FastLanguageModel.from_pretrained(model_name, load_in_4bit=True)
# Prepare the model for inference mode, ensuring it's optimized for generating predictions.
FastLanguageModel.for_inference(model)
# Define a prompt template in the style of the Alpaca instruction-based format.
# This template will be used to format the input text for the model.
alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
### Instruction:
{}
### Input:
{}
### Response:
{}"""
# Format the input text using the Alpaca-style prompt with a specific instruction and input.
# The tokenizer encodes the formatted text into tensors suitable for the model to process.
inputs = tokenizer(
[
alpaca_prompt.format(
"Replace all the PII from this text and use only the following tags: [FULLNAME], [NAME], [EMAIL], [CITY], [JOBAREA], [FIRSTNAME], [STATE], [STREETADDRESS], [URL], [USERNAME], [NUMBER], [JOBTITLE], [LASTNAME], [ACCOUNTNUMBER], [AMOUNT], [BUILDINGNUMBER], [ZIPCODE], [CURRENCY], [STREET], [PASSWORD], [IPV4], [CURRENCYNAME], [ACCOUNTNAME], [GENDER], [COUNTY], [CREDITCARDNUMBER], [DISPLAYNAME], [IPV6], [USERAGENT], [BITCOINADDRESS], [CURRENCYCODE], [JOBTYPE], [IBAN], [ETHEREUMADDRESS], [MAC], [IP], [CREDITCARDISSUER], [CREDITCARDCVV], [MASKEDNUMBER], [SEX], [JOBDESCRIPTOR]", # instruction
"Write an email to Kendra Harvey at [email protected] summarizing the key findings from a recent cognitive therapy conference they attended.", # input
"" # output - leave this blank for generation!
)
],
return_tensors="pt" # Return the encoded inputs as PyTorch tensors.
).to("cuda") # Move the tensors to the GPU (CUDA) for faster processing.
# Generate the model's output based on the input prompt, limiting the output to a maximum of 64 new tokens.
# The use_cache parameter is set to True to utilize past key values for faster generation.
outputs = model.generate(**inputs, max_new_tokens=64, use_cache=True)
# Decode the generated output from the model, converting the tokenized output back into human-readable text.
# The skip_special_tokens argument ensures that special tokens used by the model (like padding or start tokens) are omitted.
redacted_text = tokenizer.batch_decode(outputs, skip_special_tokens=True)
# Print the first item in the list of decoded texts, which should be the redacted version of the input text.
print(redacted_text[0])
If you use this model, please consider citing the model repository:
@misc{ninja_masker_2024,
author = {King Harry (Roy)},
title = {Ninja-Masker-2-PII-Redaction},
year = {2024},
url = {https://huggingface.co/King-Harry/Ninja-Masker-2-PII-Redaction},
}