Instructions to use KRISHNAPURI/q-trust-crypto-detector with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use KRISHNAPURI/q-trust-crypto-detector with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="KRISHNAPURI/q-trust-crypto-detector")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("KRISHNAPURI/q-trust-crypto-detector") model = AutoModelForSequenceClassification.from_pretrained("KRISHNAPURI/q-trust-crypto-detector", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Q-Trust Crypto Detector (v4)
Binary classifier that labels a source file as crypto-containing or not, across C, C++, Java, Go, Rust, Python, JavaScript/TypeScript, Solidity, C#, PHP, Zig and Swift. It is the ML layer of the Q-Trust cryptographic-discovery pipeline (CBOM generation for post-quantum migration).
- Base model:
huggingface/CodeBERTa-small-v1(fine-tuned for sequence classification, 2 labels) - Input: source code (truncated to 256 tokens; the detector chunks long files at inference)
- Output:
LABEL_1= crypto present,LABEL_0= not crypto
Intended use
Flag source files that use cryptographic primitives (RSA/ECC, AES/ChaCha20, SHA/BLAKE, X.509, and PQC: ML-KEM/Kyber, ML-DSA/Dilithium, SLH-DSA/SPHINCS+, Falcon, HQC) so they can be inventoried in a CycloneDX CBOM and prioritized for post-quantum migration.
This is usage discovery, not cryptographic misuse detection. It answers "does this file use crypto?", not "is this crypto used correctly?".
Training
| Corpus | Q-Trust code corpus v4 — 17,171 files / 58 source repositories / 8,814 crypto-labelled |
| Split | repo-disjoint, digest-keyed (SHA-256 source buckets), seed 42 |
| Epochs | 3 |
| Max length | 256 tokens |
| Batch size | 16 |
| Optimizer | AdamW, lr 2e-5 |
| Hardware | CPU |
Evaluation (honest, leakage-audited)
All numbers are on held-out repositories with zero exact-path overlap with training (verified by an evaluation-leakage audit — 87.6% / 92.2% of a naive shared-split eval would have been memorized by earlier checkpoints; this v4 checkpoint is 0.0%).
| Split | Precision | Recall | F1 | n |
|---|---|---|---|---|
| Digest, de-duplicated (primary, E-15) | 0.9492 | 0.8626 | 0.9039 | 1,779 |
| Digest, raw records (as originally reported) | 0.9429 | 0.8546 | 0.8966 | 2,238 |
| Native (10 held-out repos, incl. new) | 0.9444 | 0.8737 | 0.9077 | 2,566 |
The primary digest row keeps one record per (source, path) — the longest copy, chosen without
looking at the label — because the raw held-out set repeats 197 paths (459 extra records, 22 label
conflicts). Both views are reported: de-duplication changes the metric by +0.0073 F1, not the model
(EXPERIMENTS.md E-15, qtrust_ai/artifacts/eval_dedup_v4.json).
- Beats a TF-IDF + LogisticRegression baseline (F1 0.6675 on the native split) by +0.24 F1.
- Calibration: temperature T = 1.8416 (Brier 0.0853 → 0.0845).
Limitations (read before trusting the number)
- Labels are regex-derived (
is_crypto= "contains a crypto keyword"). The attainable F1 is therefore bounded by the labeler's own error, not model capacity. More epochs (5) and more data (v5, +8 repos) were both tried and regressed — the ceiling is the label, not the learner. - Cross-language accuracy varies; C dominates the evaluation set.
- Not a vulnerability scanner and not a substitute for human review.
Usage
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
name = "KRISHNAPURI/q-trust-crypto-detector"
tok = AutoTokenizer.from_pretrained(name)
model = AutoModelForSequenceClassification.from_pretrained(name)
code = "from cryptography.hazmat.primitives.asymmetric import rsa\nkey = rsa.generate_private_key(public_exponent=65537, key_size=2048)"
enc = tok(code, return_tensors="pt", truncation=True, max_length=256)
with torch.no_grad():
p = torch.softmax(model(**enc).logits, -1)[0, 1].item()
print("crypto probability:", round(p, 3))
Provenance
Part of the Q-Trust project (post-quantum migration assurance). Training/eval artifacts:
training_report_v4.json, eval_leakage_audit.json, calibration_v4.json.
- Downloads last month
- -
Model tree for KRISHNAPURI/q-trust-crypto-detector
Base model
huggingface/CodeBERTa-small-v1Dataset used to train KRISHNAPURI/q-trust-crypto-detector
Evaluation results
- F1 (de-duplicated held-out, 0% train overlap) on Q-Trust code corpus v4 (repo-disjoint digest split)self-reported0.904
- Precision on Q-Trust code corpus v4 (repo-disjoint digest split)self-reported0.949
- Recall on Q-Trust code corpus v4 (repo-disjoint digest split)self-reported0.863