$$\rightleftharpoonup{xx}$$
$$\longleftharp{xx}$$,
$$\longrightharp{xx}$$,
This study uses only publicly available datasets (UCF-Crime13 and ShanghaiTech14). All videos were obtained from the official releases of the datasets, which anonymize personally identifiable information to the extent provided by the dataset maintainers. No additional data collection or human subject interaction was conducted by the authors; therefore, no new IRB approval was required. Data usage complies with the licenses and terms of use of the respective datasets.
Data preparation and feature extraction
Dataset preparation:The UCF-Crime13 (1,610 train/290 test videos) and ShanghaiTech14 (238 train/199 test videos) datasets were adopted under their standard splits. Videos were preprocessed using FFmpeg to ensure reproducibility, re-encoded to H.264, resampled to 25 fps, and resized to 256 x 256 resolution with the command: ffmpeg -i v.mp4 -vf "fps=25,scale=256:256" -c:v libx264 -crf 23 -preset veryfast pre/.
Feature extraction: RGB features were extracted by an I3D backbone15 pre-trained on the Kinetics dataset16. Videos were split into non-overlapping 16-frameclips; each clip was center-cropped to 224 x 224 pixels. The penultimate layer activations were average-pooled to obtain a 1024-D feature per clip. In PyTorch, this corresponds to forwarding tensors of shape [B, 3, T, H, W] through the I3D backbone and applying adaptive_avg_pool3d followed by flattening. The extracted features were saved in .npy files (one per video) together with clip timestamps for exact reproducibility (seed = 123). For each video, features///
Model architecture and methodology
Basic detection: temporal context fusion
Given a video clip sequence represented by a feature matrix Z
RTx1024, the Temporal Context Fusion (TCF) module first computed query, key, and value representations through three learned linear projections:
Q = ZWQ, K = ZWK, V = ZWV (1)
where WQ, WK, WV
RTx1024xd are trainable parameters (PyTorch: three nn.Linear (1024,d) layers). The intersegment affinity was S =
, a Temporal Relationality Embedding (TRE) was incorporated, where each element was computed as Rij = α exp (
) + β . The location-aware affinity was
= S + R. A global-context map A = softmax(
) aggregated V to obtain wide-area features G = AV. Local features L were computed with a depthwise 1-D convolution (nn.Conv1d) of kernel size 3 over Z. A dynamic gate g = σ(MLP ([G;L])) mixed the two: U = g
G + (1 - g)
L . Finally, layer normalization and a residual linear layer were applied to produce Y (Pytorch:LayerNorm+Linear+residual).
Basic detection: causal temporal predictor
The output Y was passed through two causal 1-D convolutions with GELU and dropout (Pytorch:padding='causal' or masked conv) to obtain per-clip anomaly logits. Applying the sigmoid function yielded probability values
[0,1]T.
Semantic enhancement: prompt learning with external knowledge
Construct semantic anchors : For each anomaly class c, Kc concepts were queried from Wikidata11, and encoded each concept phrase was encoded with BLIP's12text encoder to ei
R768. The class anchor was the l2-normalized mean Dc = norm(
Σiei) . To reduce noise, concepts with cosine similarity to the class name below 0.2 were dropped, and the top-M by TF-IDF score were kept.
Perform context-sensitive separation : Foreground weights αt = softmax(rst) were computed from base detector scores st, and background weights bt = softmax(r(1 - st)). The weighted features are ffg = Σtαzt and fbg = Σtbzt .
Align visual and semantic features
Define the alignment objective: During the alignment step, the objective is to minimize the distance between the foreground visual feature and its corresponding semantic anchor of the anomalous category within the feature space. Create a collection of semantic guides,
, comprising C anomalous category semantic guides and one standard normal semantic guide. Determine the likelihood, P(Dk|v), that a visual feature, v, corresponds to the k-th semantic guide, Dk. Calculate this using temperature-scaled cosine similarity followed by Softmax normalization, as shown in Eq. (2).
(2)
Cross-entropy was minimized to push positive pairs together and negatives apart, with being set τs as a learnable parameter and initializing it to 10. Accomplish the alignment by optimizing the likelihood of correlating positive sample pairs while reducing the likelihood of correlating negative sample pairs.
Template-based interpretability module
Based on the prompt learning with external knowledge (PLE)-enhanced feature representation, a linear classifier produces per-class logits, which were subsequently normalized into class probabilities by the softmax function; the predicted anomaly type was determined as the category with the highest probability. Meanwhile, a global anomaly score was computed from the detector output. To determine the severity level, this score was compared against three predefined thresholds optimized through grid search on the validation set.
The default thresholds were set to θhigh = 0.8, θmedium = 0.5, and θlow = 0.2. Specifically, if the score was greater than θhigh, the severity was labeled as high; if the score falls between θmedium and θhigh, it was labeled as medium; if between θlow and θmedium, it was labeled as low; otherwise, it was marked as none.
During the explanation generation phase, a template corresponding to the predicted type was selected from a predefined template library, Supplementary File 1. This library contains multiple template variants that have been cross-validated by multiple annotators17 to enhance the diversity of the generated text. If the predicted type exists in the template library, a corresponding template was randomly selected; otherwise, a default template for the Unknown type was used. Finally, a structured explanatory text was generated by integrating the predicted type, global anomaly score, severity description, and the selected template. The system returns the predicted anomaly type, global anomaly score, and the generated explanatory text as the final output. The results are illustrated in Figure 2.
All threshold parameters were optimized using grid search on the validation set, and the quality of the generated explanations was comprehensively evaluated using both human assessment and automated metrics. The results are presented in Table 1.
Model training and evaluation
Training: The model was trained end-to-end with Adam (lr 1 x 10-4, weight decay 5 x 10-4), batch size 128, 50 epochs, cosine annealing for lr. Random seeds were set to 123 for Python/Numpy/Pytorch and enabled torch.backends.cudnn.deterministic=True. Checkpoints were saved every 5 epochs to checkpoints//epoch_XX.pt, and the best model was selected by validation AUC. All experiments were conducted on a system with an NVIDIA GeForce RTX 4060 Ti (16GB) GPU running Windows 11, with Python 3.8.20, PyTorch 1.8.0, and CUDA 11.1. The approximate training time per epoch was 30 s for the ShanghaiTech dataset and 3.5 min for the UCF-Crime dataset.
Loss: The overall objective is L = LMIL+ λ • Lalign. The hyperparameter λ was swept across the set {0.01,0.1,0.5,1,5,10} on the validation set, and fixed the best value was fixed for test reporting. See Figure 3 for top-K MIL aggregation and Eq.(3-4) for definitions.
(3)
(4)
Evaluation: Frame-level AUC was computed following the standard protocol used by prior WS-VAD works2,5. For fine-grained type recognition on UCF-Crime, mAP at IoU 0.1-0.5 and AVG mAP were reported, as summarized in Table 2; per-class AUCs are shown in Figure 4 and overall results in Table 3 and Table 4; embedding separability and anomaly-score dynamics are in Figure 4, Figure 5, and Figure 6.