Edit model card

phi3nedtuned-ner-json

This model is a fine-tuned version of microsoft/Phi-3-mini-4k-instruct on the dataset: https://huggingface.co/datasets/shujatoor/ner_instruct-json.

For Inference

from peft import PeftModel, PeftConfig
from transformers import AutoModelForCausalLM
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline

config = PeftConfig.from_pretrained("shujatoor/phi3nedtuned-ner-json")
model = AutoModelForCausalLM.from_pretrained(
    "microsoft/Phi-3-mini-4k-instruct", 
    device_map="cuda", 
    torch_dtype="auto", 
    trust_remote_code=True, 
)
model = PeftModel.from_pretrained(model, "shujatoor/phi3nedtuned-ner-json")
model.config.to_json_file('adapter_config.json')


torch.random.manual_seed(0)
tokenizer = AutoTokenizer.from_pretrained("shujatoor/phi3nedtuned-ner-json")


text = "Tehzeeb Bakers STRN3277876134234 Block A. Police Foundation,PwD Islamabad 051-5170713-4.051-5170501 STRN#3277876134234 NTN#7261076-2 Sales Receipt 05/04/202405:56:40PM CashierM J Payment:Cash Rate Qty. Total # Descriptlon 80.512.000 190.00 1.VEGETABLESAMOSA Sub Total 161.02 Total Tax: 28.98 POS Service Fee 1.00 Total 191.00 Cash 200.00 Change Due 9.00 SR#th007-220240405175640730 Goods Once Sold Can Not Be Taken Back or Replaced All Prices Are Inclusive Sales Tax 134084240405175640553"
q_json = "extracted_data': {'store_name': '', 'address': '', 'receipt_number': '', 'drug_license_number': '', 'gst_number': '', 'vat_number': '', 'date': '', 'time': '', 'items': [], 'total_items': '', 'gst_tax': '', 'vat_tax': '', 'gross_total': '', 'discount': '', 'net_total': '', 'contact': ''}"
qs = f'{text}. {q_json}'
print('Question:',qs, '\n')
messages = [
    #{"role": "system", "content": ""},
    {"role": "user", "content": qs},

]

pipe = pipeline(
    "text-generation",
    model=model,
    tokenizer=tokenizer,
)

generation_args = {
    "max_new_tokens": 512,
    "return_full_text": False,
    #"temperature": 0.0,
    "do_sample": False,
}

output = pipe(messages, **generation_args)

print('Answer:', output[0]['generated_text'], '\n')

Model description

More information needed

Intended uses & limitations

Named Entity Recognition (NER)

Training and evaluation data

More information needed

Training procedure

Training hyperparameters

The following hyperparameters were used during training:

  • learning_rate: 0.0002
  • train_batch_size: 1
  • eval_batch_size: 1
  • seed: 0
  • optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
  • lr_scheduler_type: cosine
  • lr_scheduler_warmup_ratio: 0.2
  • num_epochs: 5

Training results

Training Loss Epoch Step Validation Loss
1.1904 0.5618 500 1.0617
0.765 1.1236 1000 0.9442
0.782 1.6854 1500 0.8690
0.5591 2.2472 2000 0.8647
0.5669 2.8090 2500 0.8296
0.4205 3.3708 3000 0.8820
0.3812 3.9326 3500 0.8859
0.3323 4.4944 4000 0.9360

Framework versions

  • PEFT 0.10.1.dev0
  • Transformers 4.41.0.dev0
  • Pytorch 2.2.1+cu121
  • Datasets 2.19.0
  • Tokenizers 0.19.1
Downloads last month
2
Inference API
Unable to determine this model’s pipeline type. Check the docs .

Model tree for shujatoor/phi3nedtuned-ner-json

Adapter
(292)
this model