Downloads · 30 days
0
UlrikKoren/PIIMask-EN
PIIMask-EN is a machine learning model from UlrikKoren. 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 gemma.
The PIIMask-EN model is a specialized language model fine-tuned for the task of Personal Identifiable Information (PII) redaction. It is based on the "google/gemma-1.1-2b-it" model and trained to identify and redact v…
Downloads · 30 days
0
Access
Public
Updated Jul 4, 2024
Repo size
472 MB
Likes
0
Public
Click a slice to open those files.
.safetensors314 MB · 66%
From the Hugging Face model README
The PIIMask-EN model is a specialized language model fine-tuned for the task of Personal Identifiable Information (PII) redaction. It is based on the "google/gemma-1.1-2b-it" model and trained to identify and redact various types of PII in text while maintaining the grammatical structure of sentences.
english_balanced_10k.jsonl subset)The PIIMask-EN model was fine-tuned using the ai4privacy/pii-masking-65k dataset, which contains various text entries annotated with different types of PII. The training process involved several epochs to improve the model's ability to accurately redact PII from text. The quantization configuration was applied to make the model more efficient for deployment.
To use the PIIMask-EN model, you need to have the transformers and datasets libraries installed. You can install them using pip:
pip install transformers datasets
Here is a code example to load and use the PIIMask-EN model for PII redaction:
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline, BitsAndBytesConfig
import torch
# Quantization configuration
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.float16,
bnb_4bit_use_double_quant=True,
)
# System instructions for PII redaction
system_instructions = """Replace the following types of personal information in the text below with '[REDACTED]': [FIRST_NAME_x], [CITY_x], [STATE_x]. Ensure that each type of information is replaced in a way that maintains the grammatical structure of the sentence. You should only return the new text with the relevant replacements made, without the original text or any additional annotations.
Input:"""
example_prompt = "My name is Clara and I live in Berkeley, California."
# Load model function
def load_model(repo, step):
model = AutoModelForCausalLM.from_pretrained(repo,
device_map="cuda:0",
trust_remote_code=True,
quantization_config=bnb_config,
adapter_kwargs={"subfolder": f"checkpoint-{step}"},
attn_implementation="flash_attention_2")
return model
# Initialize tokenizer and model
device = "cuda"
tokenizer = AutoTokenizer.from_pretrained("google/gemma-1.1-2b-it", use_fast=True)
# Apply chat template for input
chat = [
{"role": "system", "content": system_instructions},
{"role": "user", "content": example_prompt},
]
inputs = tokenizer.apply_chat_template(chat, tokenize=False, return_tensors="pt", padding=True, truncation=False)
model = load_model("UlrikKoren/PIIMask-EN", step=1159)
outputs = model.generate(input_ids=inputs['input_ids'].to(device), max_new_tokens=2048)
decoded_outputs = [tokenizer.decode(output, skip_special_tokens=False) for output in outputs]
print(decoded_outputs[0])
The model checkpoints for different training epochs can be accessed as follows:
UlrikKoren/PIIMask-EN/tree/main/checkpoint-579UlrikKoren/PIIMask-EN/checkpoint-1159UlrikKoren/PIIMask-EN/checkpoint-1739UlrikKoren/PIIMask-EN/checkpoint-2316This model is a derivative of the "google/gemma-1.1-2b-it" model and complies with the Gemma Terms of Use:
The PIIMask-EN model is distributed under the same terms as the base model. For more details, please refer to the Gemma Terms of Use.