TFgram: Dual Applications in Audio and Language
- TFgram is a dual-use concept representing a learned time–frequency representation in audio and a syntax-aware Transformer Grammar in language modeling.
- In anomalous sound detection, TFgramNet employs trainable Conv1D layers to learn discriminative time–frequency filters that reduce false alarms.
- In language modeling, the Transformer Grammar variant leverages a recursive, stack-based attention mask to integrate syntactic structure for improved parsing and evaluation.
Searching arXiv for papers using the term “TFgram” to ground the article and resolve the terminology. TFgram is a label used in two distinct technical senses. In anomalous sound detection, it denotes a learned time–frequency representation extracted directly from raw audio by a small convolutional network, TFgramNet, and used within the one-stage supervised contrastive learning framework for unsupervised anomalous sound detection (Huang et al., 17 Sep 2025). In language modeling, an integrated description of Transformer Grammars uses “TFgram” as a label for a syntax-aware Transformer-XL variant whose typed attention mask implements recursive syntactic composition through stack and compose operations (Sartran et al., 2022). The two usages are unrelated in domain and objective, but both replace fixed or unstructured representations with learned inductive structure.
1. Terminological scope
The term has acquired an overloaded meaning because it appears in both audio representation learning and syntax-aware language modeling. The distinction is substantive rather than cosmetic: in the audio setting, TFgram is a two-dimensional representation with temporal and spectral axes; in the language-modeling setting, “TFgram” refers to a full generative model over linearized trees.
| Usage | Domain | Core definition |
|---|---|---|
| TFgram | Anomalous sound detection | Learned time–frequency representation extracted from raw waveform via TFgramNet |
| TFgram (TG) | Language modeling | Transformer Grammars with a typed stack/compose attention mask |
For anomalous sound detection, the representation is introduced to address frequent false alarms when handling samples of the same type from different machines, and it is evaluated on DCASE 2020 Challenge Task 2 (Huang et al., 17 Sep 2025). For language modeling, the model is evaluated on PTB and BLLIP sentence- and document-level perplexity, syntax-sensitive language modeling evaluation, and parse reranking (Sartran et al., 2022).
2. TFgram as a learned time–frequency representation for anomalous sound detection
In anomalous sound detection, TFgram is defined as a learned time–frequency representation extracted directly from the raw waveform via a small convolutional network, TFgramNet. Formally, is the output of TFgramNet that maps a one-dimensional audio signal to a two-dimensional representation with “frequency” channels and time frames (Huang et al., 17 Sep 2025).
Its role is to complement or replace log-Mel. Unlike a classical spectrogram or log-Mel, which are built on a fixed short-time Fourier transform and Mel-filterbank, TFgram uses trainable one-dimensional convolutions and pooling to discover the most discriminative frequency-like filters and time-local patterns for distinguishing normal versus anomalous machine sounds. It is designed to capture machine-specific spectral patterns, including non-stationary transients, and to use global max-pooling to emphasize salient events.
This design preserves the two-axis organization associated with time–frequency analysis while removing the fixed transform assumptions of and log-Mel. The reported advantages are end-to-end learning of filters tailored to distinguishing normal and anomalous machine sounds, the use of non-linear activations and pooling to emphasize high-energy transients, the injection of invariance to time shifts through global pooling, and the absence of a fixed perceptual filterbank that might discard “high-frequency” components.
3. TFgramNet extraction pipeline and mathematical formulation
The extraction pipeline begins with a single-channel waveform . TFgramNet comprises a Conv1D layer with kernel size , stride , padding , and channels . It is followed by three convolutional blocks. ConvBlock0 contains two Conv1D layers with kernel size 1, stride 2, padding 3 or 4, and dilation 5 or 6, each followed by BatchNorm and ReLU, then a temporal max-pool with pool size 7. ConvBlock8 is identical to ConvBlock9 and is followed by an adaptive max-pool along time to length 0. ConvBlock1 uses 2 channels, the same convolutional structure, and an adaptive max-pool to 3 (Huang et al., 17 Sep 2025).
The first-layer feature map is given by
4
for 5 and 6, with 7 and 8. Each subsequent ConvBlock applies
9
with kernel 0, stride 1, and padding 2 or dilation. Pooling is written as
3
for pool size 4, followed by adaptive max-pooling along time into 5 frames. The final representation is
6
so 7.
Relative to spectrogram and log-Mel, the key contrast is that spectrogram uses a sliding window and FFT to yield fixed linear-frequency bins, log-Mel applies a fixed Mel-warped triangular filterbank and logarithm, and TFgram replaces these fixed transforms with trainable one-dimensional convolutions in the time domain.
4. Integration with OS-SCL and empirical behavior
Within the OS-SCL framework, TFgram features are fused or used alone as input to a lightweight embedding network, MobileFaceNet. TFgram, or the concatenated TFSTgram 8, is passed through MobileFaceNet to produce embeddings 9. A small autoencoder-style Feature Perturbation Head perturbs 0 on the unit sphere after 1-normalization, and the system is jointly optimized with a noisy supervised contrastive loss and a Noisy-ArcMix-augmented cross-entropy loss (Huang et al., 17 Sep 2025).
The noisy supervised contrastive loss is
2
According to the reported rationale, because TFgram encodes richer patterns than log-Mel alone, the embeddings separate normal IDs more distinctly under contrastive learning, reducing false alarms on similar normal samples.
The quantitative results are explicit. Using only log-Mel with OS-SCL yields average 3, 4, and 5. Replacing or augmenting with TFSTgram pushes these to 6 7, 8 9, and 0 1. In a direct ablation on “ArcFace only” versus “OS-SCL,” TFSTgram improves mean AUC from 2 to 3. For the Feature Perturbation Head, compression dimension 4 gives the best AUC of 5, while removing the Feature Perturbation Head drops AUC to 6. The abstract also reports that TFgram extracted from raw audio ultimately achieves 7 AUC, 8 pAUC, and 9 mAUC on DCASE 2020 Challenge Task 2.
A common misconception is to equate TFgram with a conventional spectrogram. The formulation and pipeline make clear that it is not a fixed Fourier-domain representation; it is a learned representation whose “frequency” axis emerges from trainable filters and pooling rather than from a predefined harmonic or perceptual analysis.
5. TFgram as Transformer Grammars
In a separate usage, “TFgram” denotes Transformer Grammars, a class of Transformer LLMs that combines the scalability of Transformers with recursive syntactic compositions. The model builds on the multi-segment, relative-position Transformer-XL backbone but replaces the standard causal or full-context attention mask with a typed mask that implements a stack-based recursive compose operation whenever a constituent closes (Sartran et al., 2022).
The input is a linearized action sequence
0
where each 1 is one of four action types: an opening nonterminal 2, a terminal token of type 3, a compose closing nonterminal 4, or a stack closing nonterminal 5. A shared embedding matrix 6 maps each action to 7.
The tree-aware relative-position matrix is
8
where 9 is the depth of token 0 in the syntax tree. The binary mask is
1
If 2 is 3, then 4 is exactly the indices of the children of that constituent plus the opening 5, so a single composed vector can be formed summarizing the subtree. If 6 is not a compose step, then 7 is the set of all indices currently on the stack, yielding stack attention. The integrated description states that recursive composition emerges layer by layer because every attention layer uses the same mask.
The tree-to-sequence transformation duplicates every 8 into 9 followed immediately by 0. Predicting the resulting action sequence is equivalent to jointly modeling 1. When the model reaches a compose position, the self-attention layer computes
2
which becomes the one-vector representation of the subtree. This bottleneck enforces bottom-up recursive composition because later predictions can only access a phrase through its composed vector once the interior nodes have been popped.
The Transformer-XL configuration used in the experiments is also specified: 3 layers, 4 model dimension, 5, 6 attention heads, segment length 7, memory 8, and total parameters of 9 on PTB and 0 on BLLIP.
6. Training, evaluation, and limitations of Transformer Grammars
Transformer Grammars are trained by maximizing the joint log-likelihood of the action sequence,
1
using plain cross-entropy or next-token prediction. Because marginalizing 2 is intractable, test-time evaluation lower-bounds 3 by summing over 4 candidate trees proposed by a separately trained discriminative RNNG. The reported training regimen uses Adam with 5, 6, and 7, initial learning rate 8, 9 warmup steps, linear decay thereafter, dropout 00 on attention and FFN, batch size 01 segments per GPU with segment length 02, and maximum tokens per batch of approximately 03 (Sartran et al., 2022).
The empirical results are mixed in a principled way. Test-set means 04 standard deviation over 05 random initializations are 06 PTB PPL, 07 BLLIP sentence PPL, 08 BLLIP document PPL, 09 on the syntax-sensitive generalization suite, and 10 parse 11. In the same report, TXL (trees) attains 12, 13, 14, 15, and 16, while TXL (terminals) attains 17, 18, 19, and 20. The integrated description states that TG outperforms all comparably sized baselines on the syntax-sensitive generalization suite and even beats GPT-2, Gopher, and Chinchilla on that benchmark, while its strict single-vector sentence bottleneck harms document-level perplexity.
The ablation results sharpen the interpretation. Replacing gold trees with strictly left-branching, right-branching, or child-order-reversed trees catastrophically degrades TG’s validation perplexity to 21–22 and syntax-sensitive generalization to approximately 23–24, indicating that the mask must reflect true constituency. Dropping all relative-position signals raises perplexity by approximately 25–26 points across models but only mildly affects syntax-sensitive generalization and parse 27. Regression on log-probability differences shows estimated coefficients of approximately 28 for high-frequency words, 29 for medium-frequency words, and 30 for low-frequency words, while copying across sentences incurs a stronger disadvantage of approximately 31. Probing with an MDL-based probe shows that TG and TXL (trees) encode constituency tags more saliently than TXL (terminals), that compose representations in TG are especially good at predicting the top-children of each phrase, and that TXL (trees) retains more global word-content information.
A common misconception is that stronger syntactic inductive bias must uniformly improve all language-modeling regimes. The reported document-level results argue against that interpretation: the recursive composition bottleneck improves syntax-sensitive behavior and sentence-level modeling but weakens lexical memory and cross-sentence copying. This suggests that, in the language-modeling usage of the term, “TFgram” is best understood as a model that exposes the trade-off between strict bottom-up composition and unfettered long-range attention.