ontonotes/conll2012_ontonotesv5
Updated • 1.46k • 44
How to use pahautelman/phi2-ner-dpo-v1 with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="pahautelman/phi2-ner-dpo-v1", trust_remote_code=True)
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("pahautelman/phi2-ner-dpo-v1", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("pahautelman/phi2-ner-dpo-v1", trust_remote_code=True)
messages = [
{"role": "user", "content": "Who are you?"},
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use pahautelman/phi2-ner-dpo-v1 with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "pahautelman/phi2-ner-dpo-v1"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "pahautelman/phi2-ner-dpo-v1",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/pahautelman/phi2-ner-dpo-v1
How to use pahautelman/phi2-ner-dpo-v1 with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "pahautelman/phi2-ner-dpo-v1" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "pahautelman/phi2-ner-dpo-v1",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'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 "pahautelman/phi2-ner-dpo-v1" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "pahautelman/phi2-ner-dpo-v1",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use pahautelman/phi2-ner-dpo-v1 with Docker Model Runner:
docker model run hf.co/pahautelman/phi2-ner-dpo-v1
The model was fine-tuned using one quarter of the ConLL 2012 OntoNotes v5 dataset.
The prompts and expected outputs were constructed as described in [1].
Example input:
I am an excelent linquist. The task is to label location entities in the given sentence. Below are some examples
Input: Only France and Britain backed Fischler's proposal.
Output: Only @@France## and @@Britain## backed Fischler's proposal.
Input: Germany imported 47,000 sheeps from Britain last year, nearly half of total imports.
Output: @@Germany## imported 47,000 sheeps from @@Britain## last year, nearly half of total imports.
Input: It brought in 4275 tonnes of British mutton, some 10% of overall imports.
Output: It brought in 4275 tonnes of British mutton, some 10% of overall imports.
Input: China says Taiwan spoils atmosphere for talks.
Output:
Expected output:
@@China## says @@Taiwan## spoils atmosphere for talks.
This model was trained using DPO AutoTrain trainer. For more information, please visit AutoTrain.
Hyperparameters:
{
"model": "microsoft/phi-2",
"train_split": "train",
"valid_split": null,
"add_eos_token": true,
"block_size": 1024,
"model_max_length": 2048,
"padding": "right",
"trainer": "dpo",
"use_flash_attention_2": false,
"log": "tensorboard",
"disable_gradient_checkpointing": false,
"logging_steps": -1,
"evaluation_strategy": "epoch",
"save_total_limit": 1,
"save_strategy": "epoch",
"auto_find_batch_size": false,
"mixed_precision": "bf16",
"lr": 3e-05,
"epochs": 1,
"batch_size": 2,
"warmup_ratio": 0.05,
"gradient_accumulation": 1,
"optimizer": "adamw_torch",
"scheduler": "linear",
"weight_decay": 0.0,
"max_grad_norm": 1.0,
"seed": 42,
"apply_chat_template": false,
"quantization": "int4",
"target_modules": "",
"merge_adapter": false,
"peft": true,
"lora_r": 16,
"lora_alpha": 32,
"lora_dropout": 0.05,
"model_ref": null,
"dpo_beta": 0.1,
}
from transformers import AutoModelForCausalLM, AutoTokenizer
model_path = "pahautelman/phi2-ner-dpo-v1"
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(
model_path
).eval()
prompt = 'Label the person entities in the given sentence: Russian President Vladimir Putin is due to arrive in Havana a few hours from now to become the first post-Soviet leader to visit Cuba.'
inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors='pt')
outputs = model.generate(
inputs.to(model.device),
max_new_tokens=9,
do_sample=False,
)
output = tokenizer.batch_decode(outputs)[0]
# Model response: "Answer: Russian President, Vladimir Putin"
print(output)
[1] Wang et al., GPT-NER: Named entity recognition via large language models 2023