Views
No views yet
Qwen/Qwen3-4B-Base is a 4B base model suitable for custom post-training. In this project, we apply continuous pretraining (CPT) on the pymlex/datasciencejobs-tg dataset to make the model more fluent on machine learning and data science job posts, vacancy patterns, salary and hiring phrasing, and domain vocabulary for further usage on platforms like HeadHunter or LinkedIn.iddateviewstext1Date: YYYY-MM-DD HH:MM:SS
2<job post text><eos>90/5/5:
10246431e-4adamw_torch16320.05
1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3from peft import PeftModel
4
5base_model_id = "Qwen/Qwen3-4B-Base"
6adapter_id = "pymlex/qwen3-4b-ds-jobs-expert"
7
8tokenizer = AutoTokenizer.from_pretrained(base_model_id, trust_remote_code=True)
9if tokenizer.pad_token is None:
10 tokenizer.pad_token = tokenizer.eos_token
11
12base_model = AutoModelForCausalLM.from_pretrained(
13 base_model_id,
14 device_map="auto",
15 torch_dtype=torch.bfloat16 if torch.cuda.is_available() and torch.cuda.is_bf16_supported() else torch.float16,
16 trust_remote_code=True,
17)
18
19model = PeftModel.from_pretrained(base_model, adapter_id)
20model.eval()1def generate_continuation(model, tokenizer, prompt, max_new_tokens=260):
2 inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
3 prompt_len = inputs.input_ids.shape[1]
4
5 outputs = model.generate(
6 **inputs,
7 max_new_tokens=max_new_tokens,
8 temperature=0.7,
9 top_p=0.9,
10 do_sample=True,
11 repetition_penalty=1.08,
12 eos_token_id=tokenizer.eos_token_id,
13 pad_token_id=tokenizer.pad_token_id,
14 )
15
16 decoded = tokenizer.decode(outputs[0][prompt_len:], skip_special_tokens=True)
17 return decoded.strip()
18
19
20sample_prompt = (
21 "#вакансия #ml #python #удаленно\n"
22 "Ищем Machine Learning Engineer в продуктовую команду. "
23 "Задачи: построение и запуск моделей, работа с данными, эксперименты, "
24 "поддержка ML-пайплайнов, участие в развитии продукта. "
25)
26
27output = generate_continuation(model, tokenizer, sample_prompt, max_new_tokens=1000)
28print("Prompt:")
29print(sample_prompt)
30print("\nGenerated continuation:")
31print(output)| Model | Perplexity | Loss |
|---|---|---|
| Base Model | 7.014 | 1.9479 |
| Tuned Model | 5.409 | 1.6881 |
22.9% and loss by about 13.3%. This shows that CPT makes the model substantially more confident and accurate on domain-specific job-post text.