Papers
Topics
Authors
Recent
Search
2000 character limit reached

TFgram: Dual Applications in Audio and Language

Updated 4 July 2026
  • 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, TFgramRF×T\mathrm{TFgram} \in \mathbb{R}^{F\times T} is the output of TFgramNet that maps a one-dimensional audio signal xRLx\in\mathbb{R}^L to a two-dimensional representation with FF “frequency” channels and TT 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 STFT|\mathrm{STFT}| 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 xRLx\in\mathbb{R}^L. TFgramNet comprises a Conv1D layer with kernel size K1=11K_1=11, stride s=5s=5, padding p1=K1/2p_1=\lfloor K_1/2\rfloor, and channels C1=64C_1=64. It is followed by three convolutional blocks. ConvBlockxRLx\in\mathbb{R}^L0 contains two Conv1D layers with kernel size xRLx\in\mathbb{R}^L1, stride xRLx\in\mathbb{R}^L2, padding xRLx\in\mathbb{R}^L3 or xRLx\in\mathbb{R}^L4, and dilation xRLx\in\mathbb{R}^L5 or xRLx\in\mathbb{R}^L6, each followed by BatchNorm and ReLU, then a temporal max-pool with pool size xRLx\in\mathbb{R}^L7. ConvBlockxRLx\in\mathbb{R}^L8 is identical to ConvBlockxRLx\in\mathbb{R}^L9 and is followed by an adaptive max-pool along time to length FF0. ConvBlockFF1 uses FF2 channels, the same convolutional structure, and an adaptive max-pool to FF3 (Huang et al., 17 Sep 2025).

The first-layer feature map is given by

FF4

for FF5 and FF6, with FF7 and FF8. Each subsequent ConvBlock applies

FF9

with kernel TT0, stride TT1, and padding TT2 or dilation. Pooling is written as

TT3

for pool size TT4, followed by adaptive max-pooling along time into TT5 frames. The final representation is

TT6

so TT7.

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 TT8, is passed through MobileFaceNet to produce embeddings TT9. A small autoencoder-style Feature Perturbation Head perturbs STFT|\mathrm{STFT}|0 on the unit sphere after STFT|\mathrm{STFT}|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

STFT|\mathrm{STFT}|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 STFT|\mathrm{STFT}|3, STFT|\mathrm{STFT}|4, and STFT|\mathrm{STFT}|5. Replacing or augmenting with TFSTgram pushes these to STFT|\mathrm{STFT}|6 STFT|\mathrm{STFT}|7, STFT|\mathrm{STFT}|8 STFT|\mathrm{STFT}|9, and xRLx\in\mathbb{R}^L0 xRLx\in\mathbb{R}^L1. In a direct ablation on “ArcFace only” versus “OS-SCL,” TFSTgram improves mean AUC from xRLx\in\mathbb{R}^L2 to xRLx\in\mathbb{R}^L3. For the Feature Perturbation Head, compression dimension xRLx\in\mathbb{R}^L4 gives the best AUC of xRLx\in\mathbb{R}^L5, while removing the Feature Perturbation Head drops AUC to xRLx\in\mathbb{R}^L6. The abstract also reports that TFgram extracted from raw audio ultimately achieves xRLx\in\mathbb{R}^L7 AUC, xRLx\in\mathbb{R}^L8 pAUC, and xRLx\in\mathbb{R}^L9 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

K1=11K_1=110

where each K1=11K_1=111 is one of four action types: an opening nonterminal K1=11K_1=112, a terminal token of type K1=11K_1=113, a compose closing nonterminal K1=11K_1=114, or a stack closing nonterminal K1=11K_1=115. A shared embedding matrix K1=11K_1=116 maps each action to K1=11K_1=117.

The tree-aware relative-position matrix is

K1=11K_1=118

where K1=11K_1=119 is the depth of token s=5s=50 in the syntax tree. The binary mask is

s=5s=51

If s=5s=52 is s=5s=53, then s=5s=54 is exactly the indices of the children of that constituent plus the opening s=5s=55, so a single composed vector can be formed summarizing the subtree. If s=5s=56 is not a compose step, then s=5s=57 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 s=5s=58 into s=5s=59 followed immediately by p1=K1/2p_1=\lfloor K_1/2\rfloor0. Predicting the resulting action sequence is equivalent to jointly modeling p1=K1/2p_1=\lfloor K_1/2\rfloor1. When the model reaches a compose position, the self-attention layer computes

p1=K1/2p_1=\lfloor K_1/2\rfloor2

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: p1=K1/2p_1=\lfloor K_1/2\rfloor3 layers, p1=K1/2p_1=\lfloor K_1/2\rfloor4 model dimension, p1=K1/2p_1=\lfloor K_1/2\rfloor5, p1=K1/2p_1=\lfloor K_1/2\rfloor6 attention heads, segment length p1=K1/2p_1=\lfloor K_1/2\rfloor7, memory p1=K1/2p_1=\lfloor K_1/2\rfloor8, and total parameters of p1=K1/2p_1=\lfloor K_1/2\rfloor9 on PTB and C1=64C_1=640 on BLLIP.

6. Training, evaluation, and limitations of Transformer Grammars

Transformer Grammars are trained by maximizing the joint log-likelihood of the action sequence,

C1=64C_1=641

using plain cross-entropy or next-token prediction. Because marginalizing C1=64C_1=642 is intractable, test-time evaluation lower-bounds C1=64C_1=643 by summing over C1=64C_1=644 candidate trees proposed by a separately trained discriminative RNNG. The reported training regimen uses Adam with C1=64C_1=645, C1=64C_1=646, and C1=64C_1=647, initial learning rate C1=64C_1=648, C1=64C_1=649 warmup steps, linear decay thereafter, dropout xRLx\in\mathbb{R}^L00 on attention and FFN, batch size xRLx\in\mathbb{R}^L01 segments per GPU with segment length xRLx\in\mathbb{R}^L02, and maximum tokens per batch of approximately xRLx\in\mathbb{R}^L03 (Sartran et al., 2022).

The empirical results are mixed in a principled way. Test-set means xRLx\in\mathbb{R}^L04 standard deviation over xRLx\in\mathbb{R}^L05 random initializations are xRLx\in\mathbb{R}^L06 PTB PPL, xRLx\in\mathbb{R}^L07 BLLIP sentence PPL, xRLx\in\mathbb{R}^L08 BLLIP document PPL, xRLx\in\mathbb{R}^L09 on the syntax-sensitive generalization suite, and xRLx\in\mathbb{R}^L10 parse xRLx\in\mathbb{R}^L11. In the same report, TXL (trees) attains xRLx\in\mathbb{R}^L12, xRLx\in\mathbb{R}^L13, xRLx\in\mathbb{R}^L14, xRLx\in\mathbb{R}^L15, and xRLx\in\mathbb{R}^L16, while TXL (terminals) attains xRLx\in\mathbb{R}^L17, xRLx\in\mathbb{R}^L18, xRLx\in\mathbb{R}^L19, and xRLx\in\mathbb{R}^L20. 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 xRLx\in\mathbb{R}^L21–xRLx\in\mathbb{R}^L22 and syntax-sensitive generalization to approximately xRLx\in\mathbb{R}^L23–xRLx\in\mathbb{R}^L24, indicating that the mask must reflect true constituency. Dropping all relative-position signals raises perplexity by approximately xRLx\in\mathbb{R}^L25–xRLx\in\mathbb{R}^L26 points across models but only mildly affects syntax-sensitive generalization and parse xRLx\in\mathbb{R}^L27. Regression on log-probability differences shows estimated coefficients of approximately xRLx\in\mathbb{R}^L28 for high-frequency words, xRLx\in\mathbb{R}^L29 for medium-frequency words, and xRLx\in\mathbb{R}^L30 for low-frequency words, while copying across sentences incurs a stronger disadvantage of approximately xRLx\in\mathbb{R}^L31. 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.

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to TFgram.