ies4-turtle-instruct / scripts /build_refusals.py
fabsssss's picture
Upload folder using huggingface_hub
6256b19 verified
Raw
History Blame Contribute Delete
4.52 kB
"""Refusal/boundary pairs: prompts asking for things IES4 cannot express (subjective
qualities, speculation, opinions, non-RDF outputs). Teaches the model to explain the
limit and offer the nearest representable alternative instead of hallucinating a graph."""
import json, pathlib, random
random.seed(31)
ROOT = pathlib.Path("/Users/fabio/projects/qwen-ies-ft")
SYS = ("You are an expert in the UK Government Information Exchange Standard (IES4), "
"a 4D RDF ontology. You explain IES concepts precisely and write valid IES4 "
"RDF/Turtle using only real IES4 terms.")
CASES = [
("Record that Fred Smith is a kind and trustworthy person.",
"IES4 models objective, exchangeable facts (entities, states, events, periods, identifiers), "
"not subjective character judgements like kindness or trustworthiness. I can encode Fred Smith "
"as an ies:Person with names, identifiers, states and event participations. If an authority "
"issued a formal assessment, that assessment event itself could be modelled (who assessed, "
"when), but the subjective quality cannot be asserted as a fact. Shall I encode the person "
"record or an assessment event instead?"),
("Encode that Alice will probably move to Manchester next year.",
"IES4 asserts facts about states of the world, not probabilities or speculation about the "
"future. 'Probably moves next year' is a prediction, not an exchangeable fact. What IES4 can "
"represent: a possible-world construct for hypotheticals (ies:PossibleWorld) used in assessment "
"contexts, or a recorded statement/assessment event in which an analyst asserted this "
"prediction on a given date. Tell me which and I will encode it."),
("Write the IES4 Turtle showing that the merger caused the redundancies.",
"IES4 has no causal relation between events; it records what happened, who participated, when "
"and where, but not that one event caused another. I can encode both events with their periods "
"and participants, and, if an analyst made a causal assessment, the assessment itself as an "
"event. Should I do that?"),
("Give me the IES4 representation of Fred's opinion that the policy is bad.",
"Opinions are not exchangeable facts in IES4. What can be modelled is the communication act: "
"Fred issuing a statement at a time, via a channel, with the statement content held as a "
"representation. The truth or sentiment of the opinion is out of scope. Want the communication "
"encoding?"),
("Encode Fred Smith's IQ of 140 and his star sign in IES4.",
"A measured value like an IQ score can be attached via the characteristics/measure pattern if "
"you need it, but a star sign is an astrological label, not a fact IES4 exchanges. I can encode "
"the person, identifiers, and any objectively measured characteristics with their measurement "
"provenance. Confirm which measured characteristics you want included."),
("Output this scenario as SQL INSERT statements using IES table names.",
"IES4 is an RDF Schema; its conformant serialisations are RDF formats (Turtle, JSON-LD, "
"N-Triples), not SQL tables. I can produce the scenario as IES4 Turtle, which you can load "
"into a triple store. Shall I proceed with Turtle?"),
("Model that the organisation is evil in IES4.",
"Moral judgements are outside IES4's scope. I can model the organisation, its posts, assets, "
"events it participated in, and formal assessments made about it by named assessors at given "
"times. Which facts should I encode?"),
("Encode that Fred loves Alice in IES4 Turtle.",
"Emotional states are not part of IES4's exchangeable model. What IES4 can express: a "
"relationship state between two people over a period (for formalised relationships such as "
"marriage or partnership via states of the persons), or communication events between them. "
"Tell me which representable relationship you mean and I will encode it."),
]
VARIANTS = [
"As IES4 Turtle: {q}", "{q} Output only Turtle.", "Using the IES ontology, {q}",
"{q}", "For our knowledge graph, {q}",
]
pairs = []
for q, a in CASES:
for v in random.sample(VARIANTS, 5):
pairs.append({"messages":[
{"role":"system","content":SYS},
{"role":"user","content":v.format(q=q[0].lower()+q[1:]) if v!="{q}" else q},
{"role":"assistant","content":a}]})
out = ROOT/"data"/"pairs_refusal.jsonl"
with out.open("w") as f:
for p in pairs: f.write(json.dumps(p)+"\n")
print(f"refusal pairs: {len(pairs)} -> {out}")