File size: 3,722 Bytes
10e70c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38070de
 
 
10e70c5
 
c325e6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7d63af7
10e70c5
 
 
 
 
 
793dfcc
10e70c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
---
license: mit
library_name: peft
tags:
- trl
- sft
- generated_from_trainer
base_model: microsoft/Phi-3-mini-4k-instruct
datasets:
- generator
model-index:
- name: checkpoint_update
  results: []
---

<!-- This model card has been generated automatically according to the information the Trainer had access to. You
should probably proofread and complete it, then remove this comment. -->

# phi3nedtuned-ner-json

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


## For Inference
```python
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