Views
No views yet
QwenTokenizer (same as base)transformers)1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4model_id = "Rithankoushik/job-parser-model-qwen-2.0" # or your HF repo
5
6tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
7model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
8model.eval()
9
10def get_structured_jd(jd_text):
11 system_prompt = (
12 "You are an expert JSON extractor specifically trained to parse job descriptions into a structured JSON format using a given schema. "
13 "Your ONLY goal is to extract exactly and only what is explicitly stated in the job description text. "
14 "Do NOT guess, infer, or add any information that is not mentioned. "
15 "If a field is not present in the job description, fill it with empty or null values as specified by the schema. "
16 "Always perfectly follow the provided JSON schema. "
17 "Return ONLY the JSON object with no extra commentary or formatting."
18 )
19
20 schema = '''{
21 "job_titles": [],
22 "organization": { "employers": [], "websites": [] },
23 "job_contact_details": { "email_address": [], "phone_number": [], "websites": [] },
24 "location": { "hiring": [], "org_location": [] },
25 "employment_details": { "employment_type": [], "work_mode": [] },
26 "compensation": {
27 "salary": [{
28 "amount_in_text": "",
29 "time_frequency": "",
30 "parsed": { "min": "", "max": "", "currency": "" }
31 }],
32 "benefits": []
33 },
34 "technical_skills": [{ "skill_name": "" }],
35 "soft_skills": [],
36 "work_experience": {
37 "min_in_years": null,
38 "max_in_years": null,
39 "role_experience": [{ "min_in_years": null, "max_in_years": null, "skill": "" }],
40 "skill_experience": [{ "min_in_years": null, "max_in_years": null, "skill": "" }]
41 },
42 "qualifications": [{ "qualification": [], "specilization": [] }],
43 "certifications": [],
44 "languages": []
45 }'''
46
47 prompt = f"""
48Please extract all explicitly stated information from the following job description and format it as per the JSON schema provided.
49
50Job Description:
51\"\"\"
52{jd_text}
53\"\"\"
54
55JSON Schema:
56{schema}
57
58Return ONLY the JSON object.
59"""
60
61 messages = [
62 {"role": "system", "content": system_prompt},
63 {"role": "user", "content": prompt}
64 ]
65
66 input_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
67 inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
68
69 with torch.no_grad():
70 output = model.generate(**inputs, max_new_tokens=1200, do_sample=False)
71
72 response = tokenizer.decode(output[0][inputs.input_ids.shape[-1]:], skip_special_tokens=True)
73 return response
74
75# Example
76jd = """
77Job Title: Machine Learning Engineer
78Company: ZentrixAI
79Location: Remote (Singapore timezone preferred)
80Salary: SGD 7,500 - 10,000 monthly
81"""
82
83print(get_structured_jd(jd))