File size: 5,091 Bytes
402010f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
335b5d4
 
 
402010f
66da75d
402010f
335b5d4
402010f
 
335b5d4
 
 
 
402010f
335b5d4
597eeb7
402010f
 
 
 
 
 
 
 
 
 
 
e4bac41
402010f
 
 
 
 
e4bac41
402010f
 
 
 
 
 
 
 
 
 
e4bac41
402010f
e4bac41
402010f
e4bac41
 
 
 
 
 
402010f
 
e4bac41
 
402010f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
---
base_model: Qwen/Qwen3-4B
library_name: peft
pipeline_tag: text-generation
language:
- en
tags:
- peft
- lora
- data-to-text
- text-to-data
- factual-consistency
- hallucination-detection
---

# XQDT E2E verifier: qwen3 4B

This repository contains the LoRA adapter for the **qwen3 4B**
XQDT verifier from *XQDT: eXplainable and Quantitative Data-Text Alignment Metric
with Feedback Signals*. It is used with
[`Qwen/Qwen3-4B`](https://huggingface.co/Qwen/Qwen3-4B).

This E2E checkpoint was trained on the joint WebNLG--E2E synthetic training set.

## Overview

XQDT verifies alignment between English text and structured triples. It returns
`missing`, `extra`, and `incorrect` units, or `All correct`. `missing` identifies
an input unit omitted from the text, `extra` identifies text content unsupported
by the input, and `incorrect` identifies an input unit realised with incorrect
information.

Example inputs and outputs are provided in `smoke_test.json`.
Generated text may vary slightly across inference libraries and package versions.

## Prompt format

```text
Verify if the triples align with the text. Find missing, extra, or incorrect triples.
TEXT: {text}
TRIPLES:
1. [S] {subject} [P] {predicate} [O] {object}
Output as markdown table with Type and Triple columns.
```

## ms-swift

```python
import os
os.environ.setdefault("USE_HF", "1")
import torch
from swift.infer_engine import InferRequest, RequestConfig, TransformersEngine

BASE_MODEL = "Qwen/Qwen3-4B"
ADAPTER_ID = "Loria-MosAIk/xqdt-e2e-qwen3-4b"
SYSTEM_PROMPT = "Identify extra, missing and incorrect triples precisely."
QUERY = """Verify if the triples align with the text. Find missing, extra, or incorrect triples.
TEXT: Blue Spice is a coffee shop in city centre.
TRIPLES:
1. [S] Blue Spice [P] area [O] city centre
2. [S] Blue Spice [P] eat type [O] coffee shop
Output as markdown table with Type and Triple columns."""
MESSAGES = [{"role": "system", "content": SYSTEM_PROMPT}, {"role": "user", "content": QUERY}]

engine = TransformersEngine(
    BASE_MODEL,
    adapters=[ADAPTER_ID],
    max_batch_size=1,
    torch_dtype=torch.bfloat16,
    device_map="auto",
    template_type="qwen3",
    use_hf=True,
)
response = engine.infer(
    [InferRequest(messages=MESSAGES)],
    RequestConfig(max_tokens=1024, temperature=0.3, seed=2023),
    use_tqdm=False,
)[0]
print(response.choices[0].message.content)
```

## Transformers and PEFT

```python
import torch
from peft import PeftModel
from transformers import set_seed

BASE_MODEL = "Qwen/Qwen3-4B"
ADAPTER_ID = "Loria-MosAIk/xqdt-e2e-qwen3-4b"
SYSTEM_PROMPT = "Identify extra, missing and incorrect triples precisely."
QUERY = """Verify if the triples align with the text. Find missing, extra, or incorrect triples.
TEXT: Blue Spice is a coffee shop in city centre.
TRIPLES:
1. [S] Blue Spice [P] area [O] city centre
2. [S] Blue Spice [P] eat type [O] coffee shop
Output as markdown table with Type and Triple columns."""
MESSAGES = [{"role": "system", "content": SYSTEM_PROMPT}, {"role": "user", "content": QUERY}]
set_seed(2023)

from transformers import AutoModelForCausalLM, AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
base = AutoModelForCausalLM.from_pretrained(
    BASE_MODEL, torch_dtype=torch.bfloat16, device_map="auto"
)
model = PeftModel.from_pretrained(base, ADAPTER_ID).eval()
prompt = tokenizer.apply_chat_template(MESSAGES, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.inference_mode():
    output = model.generate(**inputs, max_new_tokens=1024, do_sample=True, temperature=0.3)
generated = output[0, inputs["input_ids"].shape[-1]:]
print(tokenizer.decode(generated, skip_special_tokens=True))
```

## vLLM

```python
from huggingface_hub import snapshot_download
from vllm import LLM, SamplingParams
from vllm.lora.request import LoRARequest

BASE_MODEL = "Qwen/Qwen3-4B"
ADAPTER_ID = "Loria-MosAIk/xqdt-e2e-qwen3-4b"
SYSTEM_PROMPT = "Identify extra, missing and incorrect triples precisely."
QUERY = """Verify if the triples align with the text. Find missing, extra, or incorrect triples.
TEXT: Blue Spice is a coffee shop in city centre.
TRIPLES:
1. [S] Blue Spice [P] area [O] city centre
2. [S] Blue Spice [P] eat type [O] coffee shop
Output as markdown table with Type and Triple columns."""
MESSAGES = [{"role": "system", "content": SYSTEM_PROMPT}, {"role": "user", "content": QUERY}]

adapter_path = snapshot_download(ADAPTER_ID)
llm = LLM(model=BASE_MODEL, enable_lora=True)
outputs = llm.chat(
    MESSAGES,
    SamplingParams(max_tokens=1024, temperature=0.3, seed=2023),
    lora_request=LoRARequest("xqdt", 1, adapter_path),
)
print(outputs[0].outputs[0].text)
```

## Citation

```bibtex
@inproceedings{efimov-zhang-etal-2026-xqdt,
  title = {XQDT: eXplainable and Quantitative Data-Text Alignment Metric with Feedback Signals},
  author = {Efimov-Zhang, Kun and Song, Yifei and Gardent, Claire},
  booktitle = {Proceedings of the 2026 Conference on Empirical Methods in Natural Language Processing},
  year = {2026}
}
```