Update README.md
Browse files
README.md
CHANGED
|
@@ -9,3 +9,51 @@ base_model:
|
|
| 9 |
- Qwen/Qwen3-0.6B
|
| 10 |
---
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
- Qwen/Qwen3-0.6B
|
| 10 |
---
|
| 11 |
|
| 12 |
+
### example(En)
|
| 13 |
+
```
|
| 14 |
+
system = """
|
| 15 |
+
You are an AI that dynamically performs Named Entity Recognition (NER).
|
| 16 |
+
You receive a sentence and a list of entity types the user wants to extract, and then identify all entities of those types within the sentence.
|
| 17 |
+
If you cannot find any suitable entities within the sentence, return an empty list.
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
text = """
|
| 21 |
+
Once upon a time, a little boy named Tim went to the park with his mom. They saw a big fountain with water going up and down. Tim was very happy to see it.
|
| 22 |
+
Tim asked his mom, "Can I go near the fountain?" His mom answered, "Yes, but hold my hand tight." Tim held his mom's hand very tight and they walked closer to the fountain. They saw fish in the water and Tim laughed.
|
| 23 |
+
A little girl named Sue came to the fountain too. She asked Tim, "Do you like the fish?" Tim said, "Yes, I like them a lot!" Sue and Tim became friends and played near the fountain until it was time to go home.
|
| 24 |
+
""".strip()
|
| 25 |
+
|
| 26 |
+
named_entity = """
|
| 27 |
+
[{'type': 'PERSON', 'description': 'Names of individuals'}, {'type': 'LOCATION', 'description': 'Specific places or structures'}, {'type': 'ANIMAL', 'description': 'Names or types of animals'}]
|
| 28 |
+
""".strip()
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
user = f"<sentence>\n{text}\n</sentence>\n\n<entity_list>\n{named_entity}\n</entity_list>\n\n"
|
| 32 |
+
chat = [{"role":"system", "content":system}, {"role":"user", "content":user}]
|
| 33 |
+
chat_text = tokenizer.apply_chat_template(
|
| 34 |
+
chat,
|
| 35 |
+
enable_thinking=False,
|
| 36 |
+
add_generation_prompt=True,
|
| 37 |
+
tokenize=False
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
model_inputs = tokenizer([chat_text], return_tensors="pt").to(model.device)
|
| 41 |
+
|
| 42 |
+
generated_ids = model.generate(
|
| 43 |
+
**model_inputs,
|
| 44 |
+
max_new_tokens=512
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
generated_ids = [
|
| 48 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
| 49 |
+
]
|
| 50 |
+
|
| 51 |
+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
### result (en)
|
| 55 |
+
```
|
| 56 |
+
<entities>
|
| 57 |
+
[{'text': 'Tim', 'type': 'PERSON'}, {'text': 'mom', 'type': 'PERSON'}, {'text': 'Sue', 'type': 'PERSON'}, {'text': 'park', 'type': 'LOCATION'}, {'text': 'fountain', 'type': 'LOCATION'}, {'text': 'fish', 'type': 'ANIMAL'}]
|
| 58 |
+
</entities>
|
| 59 |
+
```
|