Views
No views yet
Nested Named-Entity Recognition on Vietnamese COVID-19: Dataset and Experiments
[https://arxiv.org/abs/2504.21016]
1import torch
2from transformers import AutoModel, AutoTokenizer
3
4model_path = "myduy/dream-diffusion-ner-recovery"
5model = AutoModel.from_pretrained(model_path, torch_dtype=torch.bfloat16, trust_remote_code=True)
6tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
7model = model.to("cuda").eval()
8
9
10test = [
11 {
12 "instruction": "<ner>\nTiêm chủng vaccine ngừa virus SARS-CoV-2 là biện pháp hiệu quả.\n</ner>",
13 "output": ""
14 },
15 {
16 "instruction": "<ner>\nBệnh nhân được chẩn đoán mắc bệnh lao phổi và được điều trị theo phác đồ của WHO.\n</ner>",
17 "output": ""
18 },
19 {
20 "instruction": "<ner>\nKhoa Hồi sức tích cực tại Bệnh viện Bạch Mai đã tiếp nhận bệnh nhân nguy kịch.\n</ner>",
21 "output": ""
22 },
23 {
24 "instruction": "<ner>\nThuốc Paracetamol 500mg được sử dụng để hạ sốt cho trẻ em.\n</ner>",
25 "output": ""
26 },
27 {
28 "instruction": "<ner>\nTrung tâm Kiểm soát bệnh tật TP. Hồ Chí Minh khuyến cáo người dân đeo khẩu trang y tế.\n</ner>",
29 "output": ""
30 },
31 {
32 "instruction": "<ner>\nPhác đồ điều trị HIV/AIDS được cập nhật mới nhất năm 2025.\n</ner>",
33 "output": ""
34 }
35]
36
37messages = [
38 {"role": "user", "content": "<ner>\nPhác đồ điều trị HIV/AIDS được cập nhật mới nhất năm 2025.\n</ner>"}
39]
40inputs = tokenizer.apply_chat_template(
41 messages, return_tensors="pt", return_dict=True, add_generation_prompt=True
42)
43input_ids = inputs.input_ids.to(device="cuda")
44attention_mask = inputs.attention_mask.to(device="cuda")
45
46output = model.diffusion_generate(
47 input_ids,
48 attention_mask=attention_mask,
49 max_new_tokens=512,
50 output_history=True,
51 return_dict_in_generate=True,
52 steps=512,
53 temperature=0.2,
54 top_p=0.95,
55 alg="entropy",
56 alg_temp=0.,
57)
58generations = [
59 tokenizer.decode(g[len(p) :].tolist())
60 for p, g in zip(input_ids, output.sequences)
61]
62
63print(generations[0].split(tokenizer.eos_token)[0])