laya-clinc150 / code /layatasks /tasks /clinc150.py
VibeHash's picture
Release laya-clinc150, seed 0
0e9d0a1 verified
Raw History Blame Contribute Delete
4.36 kB
"""CLINC150: 150 requests a person makes to a voice assistant, plus queries that are none of them.
The "plus" version of the dataset: 100 training queries for each of the 150 intents and 250 out-of-scope ones, and a
test of 4,500 in-scope and 1,000 out-of-scope queries. The out-of-scope class is the point of this task. A deployed
model meets requests it was never built for, and the benchmark scores how many of those it lets through.
The out-of-scope label is `oos` in the source, which reads as nothing to a model that reads its options as text, so
its option reads "none of these". Every other option is the label name with underscores written as spaces.
The benchmark (Larson et al. 2019) reports two numbers, and so does this task: in-scope accuracy, where answering
"none of these" to an in-scope query counts as wrong, and out-of-scope recall, the share of out-of-scope queries
answered "none of these". With Laya's threshold there is a third way to stop an off-topic query: answering below the
threshold sends it to a person, so recall is reported with and without the threshold.
"""
from __future__ import annotations
from typing import Any, Dict, List, Optional
from layatasks import metrics
from layatasks.task import Task
OOS_LABEL = "oos"
OOS_OPTION = "none of these"
def option_text(name: str) -> str:
return OOS_OPTION if name == OOS_LABEL else name.replace("_", " ").strip().lower()
TASK = Task(
name="clinc150",
title="CLINC150",
repo="clinc/clinc_oos",
revision="155b9c710419136e17307b80d0a13e68cd46b4ec",
license="CC BY 3.0",
attribution=("Larson et al., An Evaluation Dataset for Intent Classification and Out-of-Scope Prediction, "
"EMNLP-IJCNLP 2019. Dataset: clinc/clinc_oos on Hugging Face, CC BY 3.0."),
files={
"train": ("plus/train-00000-of-00001.parquet",
"30188119cf9f86fc9db27e1c22442d091cb5cb0913c9496f945fe11e7a02a28f"),
"test": ("plus/test-00000-of-00001.parquet",
"3e60e45b25bf86543aa5df8ba4fcc674114164e6184f0197690648c2908d0102"),
},
text_column="text",
label_column="intent",
question_id="intent",
# Short on purpose: the 151 options take about 470 of the 512 tokens, and the longest query needs the rest.
instructions="Which request is this?",
option_text=option_text,
test_sha256="470ec9495a074a3c8ab3a738ee99497f334f2a2e5caa9d214673bbeba9c6316c",
release_name="laya-clinc150",
)
def extra_scores(preds: List[Dict[str, Any]], gate: Optional[float]) -> Dict[str, Any]:
"""In-scope accuracy and out-of-scope recall, the benchmark's two numbers, with and without the threshold."""
ins = [p for p in preds if p["gold"] != OOS_OPTION]
oos = [p for p in preds if p["gold"] == OOS_OPTION]
if not ins or not oos:
raise ValueError("the test must hold both in-scope and out-of-scope queries")
in_right = sum(1 for p in ins if p["pred"] == p["gold"])
oos_caught = sum(1 for p in oos if p["pred"] == OOS_OPTION)
result: Dict[str, Any] = {
"in_scope": {"n": len(ins), "right": in_right, "accuracy": in_right / len(ins),
"ci95": list(metrics.wilson(in_right, len(ins))),
"answered_none_of_these": sum(1 for p in ins if p["pred"] == OOS_OPTION)},
"out_of_scope": {"n": len(oos), "recall": oos_caught / len(oos), "caught": oos_caught,
"ci95": list(metrics.wilson(oos_caught, len(oos)))},
}
if gate is not None:
# Acting on a query means naming one of the 150 intents at or above the threshold. Everything else goes to
# the fallback: "none of these", or not sure enough.
def acts(p):
return p["pred"] != OOS_OPTION and p["confidence"] >= gate
in_acted = [p for p in ins if acts(p)]
in_acted_right = sum(1 for p in in_acted if p["pred"] == p["gold"])
oos_let_through = sum(1 for p in oos if acts(p))
result["with_gate"] = {
"threshold": gate,
"in_scope_acted": len(in_acted), "in_scope_coverage": len(in_acted) / len(ins),
"in_scope_acted_accuracy": (in_acted_right / len(in_acted)) if in_acted else None,
"out_of_scope_let_through": oos_let_through,
"out_of_scope_recall": 1 - oos_let_through / len(oos),
}
return result