Text Classification
Transformers
ONNX
Safetensors
English
reflex_decision
feature-extraction
dual-encoder
multiple-choice
dynamic-labels
research
custom_code
reflex
Eval Results (legacy)
Instructions to use gai-labs/reflex-1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use gai-labs/reflex-1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="gai-labs/reflex-1", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("gai-labs/reflex-1", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 1,658 Bytes
5e054a6 1fe108b 5e054a6 1fe108b 5e054a6 1fe108b 5e054a6 1fe108b 5e054a6 | 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 | """Download Reflex-1 and exercise single-request and batch inference."""
import argparse
import json
from dataclasses import asdict
import torch
from transformers import AutoModel
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--model", default="gai-labs/reflex-1")
parser.add_argument("--revision", help="Explicit Hub checkpoint branch, tag or commit")
parser.add_argument("--local-files-only", action="store_true")
args = parser.parse_args()
torch.set_num_threads(1)
model = AutoModel.from_pretrained(args.model, trust_remote_code=True,
revision=args.revision, local_files_only=args.local_files_only)
requests = [
{"state": "The lamp is red.", "question": "Which color is the lamp?",
"options": ["red", "blue", "green"]},
{"state": "The customer was charged twice for one card payment.",
"question": "Choose the matching issue.",
"options": ["duplicate charge", "lost card", "unknown fee", "cash withdrawal"]},
]
single = model.predict(requests[0])[0]
batch = model.predict_batch(requests)
assert single.choice == "red"
assert [decisions[0].choice for decisions in batch] == ["red", "duplicate charge"]
torch.testing.assert_close(torch.tensor(single.probabilities),
torch.tensor(batch[0][0].probabilities), atol=2e-5, rtol=1e-4)
print(json.dumps({"passed": True, "revision": getattr(model.config, "_commit_hash", None),
"decisions": [asdict(row[0]) for row in batch]}, indent=2))
if __name__ == "__main__":
main()
|