Text Classification
Transformers
ONNX
Safetensors
ai-detection
machine-generated-text
knowledge-distillation
modernbert
mmbert
webgpu
webassembly
lightgbm
treeshap
Run this model with HF Jobs
Run ElderRyan/proseguard on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/ElderRyan/proseguard. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/ElderRyan/proseguard on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use ElderRyan/proseguard with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ElderRyan/proseguard with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="ElderRyan/proseguard")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("ElderRyan/proseguard", device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 7,302 Bytes
1ddf025 | 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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | //! DivEye 9-Dimensional Surprisal Time-Series Dynamics (Basani & Chen, TMLR 2026) and
//! Rescaled-Range ($R/S$) Fractal Hurst Exponent (`diveye`).
//!
//! Basis: Captures higher-order temporal fluctuations in conditional surprisal $s_1, \dots, s_T$
//! (distributional shape, first/second-order discrete derivatives, serial autocorrelation,
//! rhythm entropy, and multi-scale long-range memory) orthogonal to mean cross-entropy.
/// Summary of higher-order surprisal time-series features for a document.
#[derive(Debug, Clone, Copy)]
pub struct DivEyeProfile {
/// First moment $\mu_s$ (mean human conditional surprisal in bits).
pub mean: f64,
/// Standard deviation $\sigma_s$.
pub std_dev: f64,
/// Coefficient of variation $\sigma_s / \mu_s$.
pub cv: f64,
/// Standardized third central moment (skewness $\gamma_1$).
pub skewness: f64,
/// Standardized fourth central moment minus 3 (excess kurtosis $\gamma_2$).
pub excess_kurtosis: f64,
/// Mean absolute first-order difference $\frac{1}{T-1} \sum |s_{t+1} - s_t|$.
pub diff1_mean_abs: f64,
/// Standard deviation of first-order differences $\sigma(\Delta s)$.
pub diff1_std: f64,
/// Mean absolute second-order difference (acceleration) $\frac{1}{T-2} \sum |s_{t+2} - 2s_{t+1} + s_t|$.
pub diff2_mean_abs: f64,
/// Lag-1 Pearson autocorrelation $\rho_1 \in [-1, 1]$.
pub autocorr_lag1: f64,
/// 8-bin quantized surprisal histogram Shannon entropy in bits (`[0, 3]`).
pub rhythm_entropy: f64,
/// Multi-scale Rescaled-Range ($R/S$) Hurst exponent $H \in [0, 1]$.
pub hurst_exponent: f64,
}
impl Default for DivEyeProfile {
fn default() -> Self {
Self {
mean: 5.0,
std_dev: 1.0,
cv: 0.20,
skewness: 0.0,
excess_kurtosis: 0.0,
diff1_mean_abs: 0.8,
diff1_std: 0.6,
diff2_mean_abs: 1.2,
autocorr_lag1: 0.0,
rhythm_entropy: 2.0,
hurst_exponent: 0.55,
}
}
}
/// Computes the 9 DivEye rhythmic unpredictability features + rhythm entropy + Hurst exponent
/// over a conditional surprisal sequence `s`.
#[must_use]
pub fn compute_diveye_profile(s: &[f64]) -> DivEyeProfile {
let n = s.len();
if n < 4 {
return DivEyeProfile::default();
}
let nf = n as f64;
let mean = s.iter().copied().sum::<f64>() / nf;
let mut m2 = 0.0f64;
let mut m3 = 0.0f64;
let mut m4 = 0.0f64;
let mut bins = [0usize; 8];
for &x in s {
let d = x - mean;
let d2 = d * d;
m2 += d2;
m3 += d2 * d;
m4 += d2 * d2;
// Surprisal spans roughly [0.5, 12.5] bits -> 8 bins of width 1.5 bits
let b = (((x - 0.5) / 1.5).floor().clamp(0.0, 7.0)) as usize;
if let Some(slot) = bins.get_mut(b) {
*slot = slot.saturating_add(1);
}
}
let var = (m2 / nf).max(1e-9);
let std_dev = var.sqrt();
let cv = std_dev / mean.max(0.25);
let skewness = ((m3 / nf) / (std_dev * var)).clamp(-6.0, 6.0);
let excess_kurtosis = ((m4 / nf) / (var * var) - 3.0).clamp(-3.0, 15.0);
let mut rhythm_entropy = 0.0f64;
for &cnt in &bins {
if cnt > 0 {
let p = (cnt as f64) / nf;
rhythm_entropy -= p * p.log2();
}
}
let (diff1_mean_abs, diff1_std) = compute_first_differences(s);
let diff2_mean_abs = compute_second_differences(s);
let autocorr_lag1 = compute_lag1_autocorr(s, mean, m2);
let hurst_exponent = estimate_hurst_rs(s);
DivEyeProfile {
mean,
std_dev,
cv,
skewness,
excess_kurtosis,
diff1_mean_abs,
diff1_std,
diff2_mean_abs,
autocorr_lag1,
rhythm_entropy,
hurst_exponent,
}
}
fn compute_first_differences(s: &[f64]) -> (f64, f64) {
let mut diffs = Vec::with_capacity(s.len().saturating_sub(1));
let mut abs_sum = 0.0f64;
for pair in s.windows(2) {
if let (Some(&a), Some(&b)) = (pair.first(), pair.get(1)) {
let d = b - a;
abs_sum += d.abs();
diffs.push(d);
}
}
if diffs.is_empty() {
return (0.0, 0.0);
}
let df = diffs.len() as f64;
let d_mean = diffs.iter().copied().sum::<f64>() / df;
let d_var = diffs.iter().map(|&d| (d - d_mean).powi(2)).sum::<f64>() / df;
(abs_sum / df, d_var.sqrt())
}
fn compute_second_differences(s: &[f64]) -> f64 {
let mut abs_sum = 0.0f64;
let mut cnt = 0usize;
for win in s.windows(3) {
if let (Some(&a), Some(&b), Some(&c)) = (win.first(), win.get(1), win.get(2)) {
abs_sum += (c - 2.0 * b + a).abs();
cnt = cnt.saturating_add(1);
}
}
if cnt == 0 {
0.0
} else {
abs_sum / (cnt as f64)
}
}
fn compute_lag1_autocorr(s: &[f64], mean: f64, m2: f64) -> f64 {
if m2 <= 1e-9 || s.len() < 3 {
return 0.0;
}
let mut cov = 0.0f64;
for pair in s.windows(2) {
if let (Some(&a), Some(&b)) = (pair.first(), pair.get(1)) {
cov += (a - mean) * (b - mean);
}
}
(cov / m2).clamp(-1.0, 1.0)
}
/// Estimates the Rescaled-Range ($R/S$) Hurst exponent $H \in [0, 1]$ across dyadic block sizes.
#[must_use]
pub fn estimate_hurst_rs(s: &[f64]) -> f64 {
const SCALES: [usize; 5] = [6, 12, 24, 48, 96];
let mut xs = [0.0f64; 5];
let mut ys = [0.0f64; 5];
let mut pts = 0usize;
for &k in &SCALES {
if s.len() < k * 2 {
continue;
}
let mut rs_sum = 0.0f64;
let mut blocks = 0usize;
for chunk in s.chunks_exact(k) {
let kf = k as f64;
let c_mean = chunk.iter().copied().sum::<f64>() / kf;
let mut cum = 0.0f64;
let mut c_min = 0.0f64;
let mut c_max = 0.0f64;
let mut sq_sum = 0.0f64;
for &v in chunk {
let dev = v - c_mean;
cum += dev;
c_min = c_min.min(cum);
c_max = c_max.max(cum);
sq_sum += dev * dev;
}
let std_c = (sq_sum / kf).sqrt();
if std_c > 1e-7 {
rs_sum += (c_max - c_min) / std_c;
blocks = blocks.saturating_add(1);
}
}
if blocks > 0 {
let mean_rs = rs_sum / (blocks as f64);
if mean_rs > 1e-7 {
if let (Some(px), Some(py)) = (xs.get_mut(pts), ys.get_mut(pts)) {
*px = (k as f64).ln();
*py = mean_rs.ln();
pts = pts.saturating_add(1);
}
}
}
}
if pts < 2 {
return 0.55;
}
let valid_x = xs.get(..pts).unwrap_or(&[]);
let valid_y = ys.get(..pts).unwrap_or(&[]);
let pf = pts as f64;
let mx = valid_x.iter().copied().sum::<f64>() / pf;
let my = valid_y.iter().copied().sum::<f64>() / pf;
let mut num = 0.0f64;
let mut den = 0.0f64;
for (&x, &y) in valid_x.iter().zip(valid_y.iter()) {
num += (x - mx) * (y - my);
den += (x - mx) * (x - mx);
}
if den <= 1e-9 {
0.55
} else {
(num / den).clamp(0.10, 0.98)
}
}
|