Instructions to use dcipheranalytics/phi-2-pii-bbi with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use dcipheranalytics/phi-2-pii-bbi with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="dcipheranalytics/phi-2-pii-bbi", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("dcipheranalytics/phi-2-pii-bbi", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("dcipheranalytics/phi-2-pii-bbi", trust_remote_code=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use dcipheranalytics/phi-2-pii-bbi with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "dcipheranalytics/phi-2-pii-bbi" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "dcipheranalytics/phi-2-pii-bbi", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/dcipheranalytics/phi-2-pii-bbi
- SGLang
How to use dcipheranalytics/phi-2-pii-bbi with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "dcipheranalytics/phi-2-pii-bbi" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "dcipheranalytics/phi-2-pii-bbi", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "dcipheranalytics/phi-2-pii-bbi" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "dcipheranalytics/phi-2-pii-bbi", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use dcipheranalytics/phi-2-pii-bbi with Docker Model Runner:
docker model run hf.co/dcipheranalytics/phi-2-pii-bbi
Definition
[phi-2] for [P]ersonal [I]dentifiable [I]nformation with [B]anking [B]anking [I]nsurance Dataset
How to use model
Load model and tokenizer
import torch
from transformers import AutoModelForCausalLM, BitsAndBytesConfig, AutoTokenizer
torch.set_default_device("cuda")
model_name = "dcipheranalytics/phi-2-pii-bbi"
quantization_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_compute_dtype=torch.bfloat16,
bnb_4bit_quant_type="nf4",
)
model = AutoModelForCausalLM.from_pretrained(
model_name,
device_map="auto",
# torch_dtype="auto",
torch_dtype=torch.bfloat16,
trust_remote_code=True,
quantization_config=quantization_config,
)
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
Call generate method
def generate(msg: str, max_new_tokens = 300, temperature=0.3):
chat_template = "<|im_start|>user\n{msg}<|im_end|><|im_start|>assistant\n"
prompt = chat_template.format(msg=msg)
with torch.no_grad():
token_ids = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
output_ids = model.generate(
token_ids.to(model.device),
max_new_tokens=max_new_tokens,
do_sample=True,
temperature=temperature,
pad_token_id=tokenizer.eos_token_id,
eos_token_id=tokenizer.eos_token_id,
)
output = tokenizer.decode(output_ids[0][token_ids.size(1):-1]).strip()
return output
instruction_template = "List the personally identifiable information in the given text below.\nText:########\n{text}\n########"
text_with_pii = "My passport number is 123456789."
generate(instruction_template.format(text=text_with_pii))
Batch predictions
from transformers import TextGenerationPipeline
def get_prompt(text):
instruction_template = "List the personally identifiable information in the given text below.\nText:########\n{text}\n########"
msg = instruction_template.format(text=text)
chat_template = "<|im_start|>user\n{msg}<|im_end|><|im_start|>assistant\n"
prompt = chat_template.format(msg=msg)
return prompt
generator = TextGenerationPipeline(
model=model,
tokenizer=tokenizer,
max_new_tokens=300,
do_sample=True,
temperature=0.3,
pad_token_id=tokenizer.eos_token_id,
eos_token_id=tokenizer.eos_token_id,
)
texts = ["My passport number is 123456789.",
"My name is John Smith.",
]
prompts = list(map(get_prompt, texts))
outputs = generator(prompts,
return_full_text=False,
batch_size=2)
Train Data
GPT4 generated customer service conversations.
- 100 unique banking topics, 8 examples per each,
- New 100 banking topics, 4 examples per each,
- 100 insurance topics, 4 examples per each.
Evaluation Results
Average
precision 0.836223
recall 0.781132
f1 0.801837
Per topic:
On TAB test split:
precision 0.506118
recall 0.350976
f1 0.391614
- Downloads last month
- 37
