Papers
Topics
Authors
Recent
Search
2000 character limit reached

Grammar-Constrained Shruti HMM

Updated 4 July 2026
  • The paper introduces a GC-SHMM that uses explicit raga grammar to constrain state transitions in a 22-shruti framework for accurate melodic completion.
  • It models microtonal pitch using Gaussian emissions and state-specific shruti representations, ensuring transitions adhere strictly to musical rules.
  • Empirical results show that while GC-SHMM is slower and slightly less accurate for correction, it excels in completing structured missing melodic sequences.

The Grammar-Constrained Shruti Hidden Markov Model (GC-SHMM) is the probabilistic sequence-modeling component of ShrutiSense, a symbolic pitch processing system for Indian classical music that operates in the 22-shruti microtonal framework and encodes explicit raga grammar. Within ShrutiSense, the GC-SHMM is used primarily for melodic completion, especially when pitch observations are missing or unreliable, whereas a Shruti-aware finite-state transducer (FST) is used for correction of noisy or “westernized” pitch sequences. Its defining feature is that transition structure is not learned freely from data: it is built from explicit raga grammar, including arohana, avarohana, allowed and forbidden motions, and pakad weights, so that grammatically invalid melodic paths have zero probability [2508.01498].

1. Definition and conceptual role

ShrutiSense addresses two distinct tasks: correction of noisy or corrupted pitch sequences, and completion of melodic sequences with missing values. The system therefore uses two different models: a Shruti-aware FST for correction and a GC-SHMM for completion. The GC-SHMM works directly in the 22-shruti cent scale, uses raga-specific grammar to constrain transitions between shrutis, and is particularly used where contextual prediction is required [2508.01498].

Conceptually, the model differs from a standard HMM in a precise way. A standard HMM for music would learn transitions from data and allow any state-to-state transition that has non-zero probability. The GC-SHMM instead builds the transition structure from explicit raga grammar and uses that grammar as hard constraints; only transitions allowed by the grammar can occur. This distinction is central because ragas are not just scales; they specify valid melodic motions and characteristic phrases. A purely statistical HMM trained without these constraints can produce sequences that violate the raga.

Within this division of labor, the HMM is the grammar-aware probabilistic engine, mainly for filling in missing shrutis using context, while the FST is the more engineering-oriented edit-operation model for correction. Both share the same underlying raga grammar, but they operationalize it differently: the GC-SHMM uses grammar to define transition probabilities, whereas the FST uses it as path-constraints and a scoring term.

2. State space, observations, and emissions

The GC-SHMM is defined over shruti states specific to a raga. The global 22-shruti set is defined in cents by
[
\mathbf{C} = {0, 90, 112, 182, 204, 294, 316, 386, 408, 498, 520,
590, 612, 702, 792, 814, 884, 906, 996, 1018, 1088, 1110}.
]
For a given raga (r), only a subset of shrutis is active:
[
S = {s_1, s_2, \dots, s_N}, \quad N \in [7,10].
]
Each hidden state (q_t \in S) represents a particular shruti, that is, a fixed cent position allowed in that raga. There is no separate swara or direction label in the state itself; directionality is handled via separate transition matrices [2508.01498].

The observation sequence is
[
O = {o_1,o_2,\dots,o_T},
]
where each (o_t) is a scalar cent value relative to the tonic (shadja), obtained either by pitch tracking, for example from audio via Librosa, or from symbolic input converted to cents. The model therefore couples a discrete hidden representation—a shruti index—with a continuous observation space of cent values near that shruti.

Emission probabilities are modeled as Gaussian distributions centered at the shruti’s theoretical cent value. If (\mu_i) denotes the cent value for state (s_i), the shared standard deviation is (\sigma = 25) cents, described as an empirical pitch deviation. In structural terms, each state generates continuous observations centered at its shruti position, and the same emission model is used throughout except at missing positions, where the observation model is modified for completion.

This design makes the model explicitly microtonal. Relative to systems built around 12-tone equal temperament, the GC-SHMM’s state space is not a semitone lattice but a 22-shruti cent encoding. A plausible implication is that the model is intended to preserve intonational distinctions that would be erased by semitone quantization.

3. Grammar construction and transition constraints

The model’s central innovation lies in its transition system. For each raga, grammar is represented as a directed graph whose nodes are the active shrutis (S) and whose edges are the permissible transitions (T \subseteq S \times S). The grammar function is
[
G(s_i, s_j) =
\begin{cases}
1 & \text{if } (s_i, s_j) \in T \
0 & \text{otherwise.}
\end{cases}
]
This function encodes which shruti motions are allowed [2508.01498].

A continuous weight is assigned to each allowed transition:
[
w(s_i, s_j) = G(s_i, s_j)\cdot \exp\left(-\alpha \cdot d(s_i, s_j)\right)\cdot \text{pakad_bonus}(s_i, s_j),
]
where (d(s_i,s_j)) is interval distance in cents or shruti steps, (\alpha = 0.1) imposes a stepwise preference, and (\text{pakad_bonus}(s_i,s_j) > 1) for transitions that belong to characteristic phrases of the raga. Transition probabilities are then normalized as
[
P(s_j \mid s_i) =
\begin{cases}
\dfrac{w(s_i, s_j)}{Z_i} & \text{if } G(s_i, s_j) = 1 \
0 & \text{if } G(s_i, s_j) = 0
\end{cases}
]
with
[
Z_i = \sum_{k : G(s_i, s_k) = 1} w(s_i, s_k).
]

Two consequences follow directly from this construction. First, grammar-forbidden transitions have exact zero probability, so the grammar does not merely regularize the model but fully excludes invalid melodic motions. Second, among allowed transitions, the model favors short moves and pakad-like motions.

The grammar itself is assembled from classical sources. For the five ragas implemented—Yaman, Bhairavi, Bilaval, Kalyan, and Khamaaj—the specification uses arohana and avarohana, vadi-samvadi information indirectly via pakad bonuses, varjya notes and movements encoded as absent edges, and characteristic pakad phrases. Algorithmically, this means selecting the active shruti subset, defining directed edges so that ascending passages conform to arohana and descending passages conform to avarohana while omitting forbidden notes and disallowed leaps, and then weighting each allowed edge by distance and pakad membership.

The model also uses direction-aware transition matrices (A_{\text{up}}) and (A_{\text{down}}), with melodic direction inferred via pitch gradients. Ascending motion therefore uses one transition matrix and descending motion another. This is where directional raga behavior, including arohana, avarohana, and directional forbidden notes, is captured.

4. Analytic parameterization and inference procedures

The paper does not describe a full EM or Baum-Welch training loop. Instead, the GC-SHMM is mostly constructed analytically. Emission means (\mu_i) come from the fixed 22-shruti cent table; the shared (\sigma = 25) cents is chosen empirically rather than learned; and transition parameters are derived from the raga grammar through graph construction, weighting, and normalization. In that sense, the model is closer to a knowledge-engineered HMM than to a data-trained one [2508.01498].

For correction, the GC-SHMM can be used generically with Viterbi decoding:
[
\delta_t(j) =
\left[ \max_{i : G(s_i,s_j)=1} \delta_{t-1}(i) \cdot P(s_j \mid s_i) \right] \cdot P(o_t \mid s_j),
]
or in log space,
[
\log \delta_t(j) = \max_{i : G(s_i,s_j)=1} \left[ \log \delta_{t-1}(i) + \log P(s_j \mid s_i) \right] + \log P(o_t \mid s_j).
]
The most probable state sequence is obtained by backtracking from
[
\hat{q}T = \arg\max_j \delta_T(j), \quad \hat{q}{t-1} = \psi_t(\hat{q}_t).
]
In deployed use, however, ShrutiSense selects the FST rather than the HMM for correction.

The main use of the GC-SHMM is melodic completion. For sequences with missing values, the model applies forward-backward inference:
[
\alpha_t(j) = \left[ \sum_{i : G(s_i,s_j)=1} \alpha_{t-1}(i)\, P(s_j \mid s_i) \right] P(o_t \mid s_j),
]
[
\beta_t(i) = \sum_{j : G(s_i,s_j)=1} P(s_j \mid s_i)\, P(o_{t+1} \mid s_j) \, \beta_{t+1}(j),
]
[
\gamma_t(i) = \frac{\alpha_t(i)\beta_t(i)}{\sum_j \alpha_t(j)\beta_t(j)}.
]
At positions where pitch is missing, the model sets
[
P(o_t \mid s_i) = 1 \quad \forall i.
]
This makes the observation uninformative and forces inference to rely on transitions, that is, on raga grammar and surrounding context. The paper does not spell out a separate maximum a posteriori sequence decoding with missing data, but forward-backward plus local argmax over (\gamma_t) is clearly implied:
[
\hat{s}t = \arg\max_i \gamma_t(i).
]
The filled-in cent value is then the theoretical mean (\mu
{\hat{s}_t}).

Implementation follows standard HMM practice under hard sparsity constraints. Viterbi and forward-backward recursions consider only states (j) for which (G(s_i,s_j)=1). Practically, this can be done either by pre-computing adjacency lists or by setting impossible transitions to (-\infty) in log space. With (N) between 7 and 10 active shrutis per raga, the model has time complexity (O(TN2)) per sequence and space complexity (O(TN)).

5. Empirical behavior in ShrutiSense

Evaluation is conducted on synthetic data: 1000 pitch sequences generated from canonical raga grammar rules, not from model samples, and then corrupted. The five ragas are Yaman, Bhairavi, Bilaval, Kalyan, and Khamaaj. Completion is evaluated under random, clustered, and structured missing values at rates from 10% to 50%, while correction is evaluated under random substitutions at 10% to 50% of positions. The reported metrics are Shruti Classification Accuracy and Average Pitch Error (APE, in cents); Grammar Compliance and Pakad Recognition are defined but not reported per-model for the HMM versus FST in detail [2508.01498].

For correction, a representative comparison is reported for Yaman at corruption level 0.4. The GC-SHMM attains (84 \pm 0.4\%) shruti accuracy, mean error (107.6 \pm 3.6) cents, and 12.5 ms per sequence. Under the same condition, the Shruti FST attains (91.3 \pm 0.2\%), (45.6 \pm 1.4) cents, and 0.1 ms; nearest-cent quantization attains (89.4 \pm 0.3\%), (51.8 \pm 1.4) cents, and 0.1 ms; and a random baseline attains (12.6 \pm 0.3\%), (452.6 \pm 2.4) cents, and 0 ms. These results explain why the system chooses the FST for correction in practice: the GC-SHMM clearly outperforms the random baseline, but it is weaker than both nearest-cent quantization and the FST on this task, and it is slower.

For completion, the results differ by missingness pattern. Combined across ragas, the GC-SHMM attains 57.1% accuracy and 203.0 cents error for random missingness, 40.3% and 344.9 cents for clustered missingness, and 82.9% and 48.5 cents for structured missingness. The corresponding FST values are 62.6% and 158.7 cents, 26.6% and 317.0 cents, and 70.5% and 228.1 cents. The authors also report overall mean completion accuracy of (60.1 \pm 30.9\%) for the HMM and (48.6 \pm 22.2\%) for the FST.

The pattern of results is therefore task-dependent. Structured missingness, described as musically aligned gaps, is the regime in which the GC-SHMM performs substantially better than the FST, with both higher shruti accuracy and much lower pitch error. Under random and clustered missingness, results are mixed. For low corruption and specific ragas, the FST can even slightly beat the HMM, which the paper presents as a trade-off between grammar-weighted edit operations and full probabilistic modeling. Taken together, the reported evidence supports the GC-SHMM as the stronger model for completion, especially when contextual dependencies are structured and long-range.

6. Limitations, misconceptions, and broader theoretical context

Several limits are explicit. The model assumes note-level granularity rather than continuous ornament representation, so gamak and meend are difficult to segment into discrete shruti states. For pitch deviations greater than (\pm 75) cents, even the Gaussian emissions with (\sigma = 25) cents may fail to identify the shruti correctly. The GC-SHMM uses a single raga grammar at a time and therefore does not model cross-raga modulation. Long contiguous missing blocks of five or more notes significantly reduce completion accuracy because grammar alone cannot fully determine the melodic path [2508.01498].

These constraints also clarify several common misconceptions. The GC-SHMM is not simply a conventional HMM with raga-flavored priors; its transition support is explicitly restricted by grammar. Nor is it the primary correction engine in ShrutiSense. A further misconception would be to treat its states as joint swara-direction labels; the paper states that no separate swara or direction label is built into the state, with direction instead handled through separate transition matrices.

The broader literature on grammar-constrained HMMs provides a more general formal setting. In "Marginal Inference queries in Hidden Markov Models under context-free grammar constraints" [2206.12862], a grammar-constrained HMM is described through the unnormalized distribution
[
f_{GC}(w) = f_{A'}(w)\,\delta_{L_G}(w),
]
with normalization determined by the total grammar-valid mass
[
Z_L = f_{A'}(L_G \cap \SigmaL).
]
That work shows that exact computation of this normalizing constant is polynomial-time for unambiguous CFGs, NP-hard even when grammar ambiguity degree is at most 2, and approximable by an FPRAS for polynomially ambiguous CFGs. The GC-SHMM in ShrutiSense does not use a CFG; it uses a directed raga graph with hard transition constraints. This suggests a structural distinction: ShrutiSense encodes grammar locally at the transition level rather than through a higher-order context-free language, which avoids the ambiguity issues emphasized in the CFG-based theory while still realizing a grammar-constrained HMM design.

The future directions suggested for the ShrutiSense framework would naturally extend the GC-SHMM. These include adaptive raga learning using unsupervised corpora to refine transition weights or learn new grammars under grammar constraints, enhanced ornament modeling in which gamakas and microtonal inflections become additional states or hierarchical sequences above the shruti level, multi-voice or polyphonic extensions that may require coupled HMMs or factorial models, and cross-cultural adaptation to other microtonal traditions such as Carnatic music or Middle Eastern maqam. In that sense, the GC-SHMM serves as a knowledge-driven HMM whose states are raga-specific shrutis, whose emissions are microtonal Gaussians, and whose transitions are strictly constrained by raga grammar; its main significance is to show how explicit cultural knowledge can be embedded directly into probabilistic sequence modeling for melodic completion.

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 Grammar-Constrained Shruti Hidden Markov Model (GC-SHMM).