Downloads · 30 days
0
Arko007/walnut-rancidity-predictor
walnut-rancidity-predictor is a time series forecasting model from Arko007. Use it for the time series forecasting task on the model card, and read the license before you ship it in a product. It is set up for pytorch. The card lists the license as mit.
Production-grade Stacked LSTM + Attention model for predicting walnut rancidity probability and remaining shelf life from storage condition time-series.
Downloads · 30 days
0
Access
Public
Updated Mar 7, 2026
Repo size
468 MB
Likes
0
Public
Click a slice to open those files.
.pt1.1 MB · 97%
From the Hugging Face model README
Production-grade Stacked LSTM + Attention model for predicting walnut rancidity probability and remaining shelf life from storage condition time-series.
Trained on 90,000 synthetic sequences simulating Indian storage environments using Arrhenius-based lipid oxidation kinetics.
Input (30 days × 8 features)
→ LSTM layer 1 (hidden=64, dropout=0.2)
→ LSTM layer 2 (hidden=64, dropout=0.2)
→ LSTM layer 3 (hidden=64)
→ Attention (soft weighted context)
→ Dropout (0.2)
┌──────────────────────────────────┐
│ Head 1: rancidity_probability │ Linear → ReLU → Linear → Sigmoid
│ Head 2: shelf_life_remaining │ Linear → ReLU → Linear
│ Head 3: decay_curve_value │ Linear → ReLU → Linear → Sigmoid
└──────────────────────────────────┘
| Property | Value |
|---|---|
| Parameters | ~85 K |
| Input features | 8 |
| Sequence length | 30 days |
| LSTM layers | 3 |
| Hidden size | 64 |
| Dropout | 0.2 |
| Epochs trained | 12 / 20 |
| Best val loss | 0.3892 |
| Feature | Unit | Description |
|---|---|---|
temperature | °C | Ambient temperature (2–40 °C) |
humidity | % RH | Relative humidity (30–85 %) |
moisture | % | Walnut moisture content (3–8 %) |
oxygen | fraction | Oxygen exposure (0.18–0.23) |
peroxide_value | meq/kg | Primary oxidation marker |
free_fatty_acids | % | FFA content |
hexanal_level | ppm | Volatile oxidation byproduct |
oxidation_index | — | Composite oxidation score |
| Output | Type | Description |
|---|---|---|
rancidity_probability | [0, 1] | Probability walnuts are rancid |
shelf_life_remaining_days | float | Days until PV > 5 meq/kg |
decay_curve_value | [0, 1] | Normalised peroxide value |
Walnuts are rancid when Peroxide Value > 5 meq/kg (FSSAI / Codex standard).
rancidity_probability = sigmoid(PV − 5)
from huggingface_hub import hf_hub_download
import torch, joblib, numpy as np
# Download artifacts
model_path = hf_hub_download("Arko007/walnut-rancidity-predictor", "models/walnut_rancidity_lstm_attention.pt")
scaler_path = hf_hub_download("Arko007/walnut-rancidity-predictor", "models/feature_scaler.pkl")
# Or clone and use the inference helper directly:
# from model.predict import predict_storage_risk
# Build a 30-day sequence: [temp, humidity, moisture, oxygen, PV, FFA, hexanal, ox_index]
seq = np.column_stack([
np.full(30, 5.0), # cold storage
np.full(30, 50.0),
np.full(30, 4.0),
np.full(30, 0.20),
np.linspace(0.5, 1.2, 30),
np.linspace(0.05, 0.10, 30),
np.linspace(0.1, 0.3, 30),
np.linspace(0.2, 0.5, 30),
])
result = predict_storage_risk(seq)
# → {'rancidity_probability': 0.0312, 'shelf_life_remaining_days': 143.7, 'risk_level': 'LOW'}
risk_level | rancidity_probability |
|---|---|
LOW | < 0.30 |
MEDIUM | 0.30 – 0.70 |
HIGH | > 0.70 |
k(T) = A · exp(−Ea / (R·T)) A=1.5×10¹², Ea=80 kJ/mol, R=8.314 J/mol·K
PV(t) = PV₀ · exp(k · t)
Humidity and moisture accelerate oxidation via empirical correction factors.
models/
walnut_rancidity_lstm_attention.pt ← PyTorch checkpoint (epoch 12)
feature_scaler.pkl ← StandardScaler for inference
metrics.json ← Training metrics
model/
predict.py ← Inference API
train.py ← Training script (resume from checkpoint)
generate_data.py ← Synthetic data generator
requirements.txt
pip install -r requirements.txt
python train.py # resumes from saved checkpoint automatically
MIT