Downloads · 30 days
16
15% of all-time downloads
Khriis/PAIR
PAIR is a text classification model from Khriis. Use it when you need a label for a piece of text. It is set up for transformers.
This repository provides weights for a PAIR‑style cross‑encoder that scores the quality of counselor reflections in Motivational Interviewing (MI). Given a client/patient prompt and a counselor response, the model out…
Downloads · 30 days
16
15% of all-time downloads
All-time downloads
105
Public
Repo size
498 MB
Likes
0
Public
Click a slice to open those files.
.pt498 MB · 100%
From the Hugging Face model README
This repository provides weights for a PAIR‑style cross‑encoder that scores the quality of counselor reflections in Motivational Interviewing (MI). Given a client/patient prompt and a counselor response, the model outputs a scalar score in [0,1] indicating how strongly the response reflects the prompt.
This model is based on the approach described in:
Please credit the authors above when using this model or derivative work.
PAIR trains a prompt‑aware cross‑encoder that contrasts positive and negative (prompt, response) pairs. The key idea is to learn, for a given prompt, to rank higher‑quality reflections above lower‑quality or mismatched responses using margin‑based ranking losses.
High‑level components reflected by this implementation:
roberta-base cross‑encoder over concatenated (prompt, response).The included cross_scorer_model.py shows the MLP head and margin losses consistent with a PAIR‑style training setup.
reflection_scorer_weight.pt — fine‑tuned cross‑encoder weights (encoder + head).cross_scorer_model.py — CrossScorerCrossEncoder module used for inference/training.min_pair_2022.txt — text version summary of the PAIR paper (for reference in this repo).from huggingface_hub import hf_hub_download
from transformers import AutoModel, AutoTokenizer
import torch, importlib.util, sys
repo_id = "Khriis/PAIR" # replace if you fork
# 1) Download weights and model code from the repo
ckpt_path = hf_hub_download(repo_id=repo_id, filename="reflection_scorer_weight.pt")
code_path = hf_hub_download(repo_id=repo_id, filename="cross_scorer_model.py")
# 2) Import model definition
spec = importlib.util.spec_from_file_location("cross_scorer_model", code_path)
mod = importlib.util.module_from_spec(spec)
sys.modules["cross_scorer_model"] = mod
spec.loader.exec_module(mod)
# 3) Build encoder + head and load state dict
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
encoder = AutoModel.from_pretrained("roberta-base", add_pooling_layer=False)
model = mod.CrossScorerCrossEncoder(encoder).to(device)
tokenizer = AutoTokenizer.from_pretrained("roberta-base")
state = torch.load(ckpt_path, map_location=device)
sd = state.get("model_state_dict", state)
model.load_state_dict(sd)
model.eval()
# 4) Score a (prompt, response) pair
prompt = "I’ve been overwhelmed at work and can’t focus."
response = "It sounds like you’re under a lot of pressure, and it’s affecting your ability to concentrate."
batch = tokenizer(prompt, response, padding="longest", truncation=True, return_tensors="pt").to(device)
with torch.no_grad():
score = model.score_forward(**batch).sigmoid().item()
print("Reflection score:", round(score, 3))
The toolkit can download the file automatically (public repo). For offline use, place reflection_scorer_weight.pt locally and set REFLECTION_CKPT_PATH to that path.
If you use this model or code, please cite the PAIR paper:
Informal citation: “PAIR: Prompt‑Aware margIn Ranking for Counselor Reflection Scoring in Motivational Interviewing” (Min et al., EMNLP 2022). https://aclanthology.org/2022.emnlp-main.11/
BibTeX (adapt based on official entry):
@inproceedings{min-etal-2022-pair,
title = {PAIR: Prompt-Aware margIn Ranking for Counselor Reflection Scoring in Motivational Interviewing},
author = {Min, Do June and P{\'e}rez-Rosas, Ver{\'o}nica and Resnicow, Kenneth and Mihalcea, Rada},
booktitle = {Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing},
year = {2022},
url = {https://aclanthology.org/2022.emnlp-main.11/}
}
Also cite RoBERTa:
@misc{liu2019roberta,
title = {{RoBERTa}: A Robustly Optimized {BERT} Pretraining Approach},
author = {Liu, Yinhan and others},
year = {2019},
url = {https://arxiv.org/abs/1907.11692}
}