初始化项目,由ModelHub XC社区提供模型

Model: Vaisu23/ner-qwen_model
Source: Original Platform
This commit is contained in:
ModelHub XC
2026-05-02 04:33:07 +08:00
commit d481d68d58
6 changed files with 370 additions and 0 deletions

68
README.md Normal file
View File

@@ -0,0 +1,68 @@
---
base_model: unsloth/qwen2.5-0.5b-unsloth-bnb-4bit
tags:
- text-generation-inference
- transformers
- unsloth
- qwen2
license: apache-2.0
language:
- en
---
# Uploaded finetuned model
- **Developed by:** Vaisu23
- **License:** apache-2.0
- **Finetuned from model :** unsloth/qwen2.5-0.5b-unsloth-bnb-4bit
This qwen2 model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
# Financial NER Qwen
This model is fine-tuned for high-accuracy Named Entity Recognition (NER), outputting structured JSON.
## How to use
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model_id = "Vaisu23/ner-qwen_model" # Update this to your repo ID
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.float16,
device_map="auto"
)
# 1. Set the ChatML template
tokenizer.chat_template = "{{% for message in messages %}}{{{{'<|im_start|>' + message['role'] + '\\n' + message['content'] + '<|im_end|>' + '\\n'}}}}% endfor %}{{% if add_generation_prompt %}}{{{{ '<|im_start|>assistant\\n' }}}}{% endif %}}"
# 2. Prepare the input
messages = [
{{"role": "system", "content": "Extract all entities from the text in a structured JSON format."}},
{{"role": "user", "content": "Yesterday, Vaisakh P K spent 1250.50 USD at Google."}}
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
return_tensors="pt",
return_dict=True
).to("cuda")
# 3. Generate and clean the output
with torch.no_grad():
outputs = model.generate(**inputs, max_new_tokens=128, temperature=0.1)
# Skip the prompt tokens to show ONLY the JSON
prediction_ids = outputs[0][len(inputs['input_ids'][0]):]
prediction = tokenizer.decode(prediction_ids, skip_special_tokens=True)
print(prediction)
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)