added inference code
Browse files
README.md
CHANGED
|
@@ -9,4 +9,37 @@ tags:
|
|
| 9 |
- fine-tune
|
| 10 |
- salary-normalizer
|
| 11 |
- salary-parser
|
| 12 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
- fine-tune
|
| 10 |
- salary-normalizer
|
| 11 |
- salary-parser
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# Implementation Code
|
| 15 |
+
|
| 16 |
+
```
|
| 17 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 18 |
+
|
| 19 |
+
model_name = "Draup/salary-normalizer"
|
| 20 |
+
|
| 21 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 22 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 23 |
+
|
| 24 |
+
salary_text = "12 to 12.5 US $ per hr"
|
| 25 |
+
country = "United States"
|
| 26 |
+
|
| 27 |
+
prompt = (
|
| 28 |
+
f"<start_of_turn>user\n"
|
| 29 |
+
f"summarize salary: {salary_text}\n"
|
| 30 |
+
f"country: {country}<end_of_turn>\n"
|
| 31 |
+
f"<start_of_turn>model\n"
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
|
| 35 |
+
outputs = model.generate(
|
| 36 |
+
**inputs,
|
| 37 |
+
max_new_tokens=70,
|
| 38 |
+
do_sample=False,
|
| 39 |
+
eos_token_id=tokenizer.convert_tokens_to_ids("<end_of_turn>")
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
result = tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True)
|
| 43 |
+
print(result)
|
| 44 |
+
# Output: {"currency": "US $", "iso_code": "USD", "min_amount": 12, "max_amount": 12.5, "pay_rate": "HOURLY"}
|
| 45 |
+
```
|