š„ž TSM Diff

A similarity measure for music scores based on Tree Score Model (TSM) DAG representations

Description

TSM Diff calculates a list of differences and a similarity distance value between two digital music scores, based on an abstract representation called the Tree Score Model (TSM) — labelled trees with sharing, formally labelled Directed Acyclic Graphs (DAGs).

TSM Diff workflow from score encodings to TSM DAGs, diff-list, and similarity value
Workflow of TSM Diff

Starting from two scores in an XML encoding (MusicXML or MEI), it converts them into two TSM DAGs (left and right respectively) and performs a recursive comparison. During the comparison, two separate computations are carried out in parallel:

An export of the TSM DAGs of both scores with differences highlighted is in preparation.

Description of TSM

TSM is an intermediate representation of music scores inspired by rhythm trees [1], where a score is encoded as a labelled DAG. Every node has an ordered sequence of incoming and outgoing edges.

We assume a unique node with zero incoming edges, called the root. Nodes with zero outgoing edges are called leaves and represent basic score elements (notes, rests, etc.). Non-leaf nodes are called inner.

Every node and every edge is associated with a time interval, expressed as a fraction of a bar, closed on the left and open on the right — it may be an empty interval [t, t). The root node is associated with a fixed interval covering the whole score. The interval of every other node is the union of the intervals of its incoming edges. The intervals of incoming edges form a partition.

The label of every inner node is an operator dividing one time interval into sub-intervals. The available inner-node labels are:

Leaf-node labels:

A pseudo-leaf is a leaf node labelled by one of the above, or by Chord.

Normal form

Input TSM DAGs are assumed to be in the following normal form:

The yield of a sub-DAG is the sequence of its pseudo-leaves.

Example of a TSM Diff comparison
TSM DAG representation of a music score excerpt. The index below the graph lists the pitches of the score without rhythmic information.

Annotations

The TSM DAG also carries annotations:

During comparison, annotations are also taken into account in the diff-list. They contribute to the surface distance, but not to the time distance, since they do not change the time interval represented by a TSM node.

Differences

Every entry in the diff-list (called a diff) consists of:

At least one of the two sets of nodes must be a singleton. An empty left (resp. right) set corresponds to the case of an insertion (resp. deletion). A set with more than one node, with a singleton node on the other side, occurs in the case of shared nodes in the DAG, for resynchronizing. The general principle is that a difference always covers the same time interval in both scores.

The relevant information in a diff reported to the user is the labels of these nodes and the corresponding time intervals.

Moreover, a name of edit operation (also called diff code) can optionally be added to help interpret the musical meaning of the diff. In the following demos, the diff codes are chosen among:

The names of the two latter codes are borrowed from Mongeau & Sankoff [15], and correspond to the replacement of a single note by several notes preserving the total duration. The replacement can be horizontal (e.g. replacement of a quarter note by two eighth notes, or vice versa) or vertical (replacement of a note by a chord, or vice versa).

The first three categories of codes are the primitive operations of classical edit distances. We consider moreover some specific subclasses of replace:

Finally, multi corresponds to the case of more than one node on one side and a singleton node on the other.

The above choice of codes is arbitrary; their selection occurs only in a post-processing step (it depends on the algorithms used for comparison). This list of codes could easily be adapted as required for different case studies.

Distances

Two normalised distance values are computed:

The similarity measure is 1 minus the harmonic mean of the two distances above.

Computation of the Diff-List and Distances

The diff-list and distances are constructed in five steps.

1. Normalisation

Each score is parsed using the music21 toolkit and converted into a TSM. Both TSMs are then transformed into the normal form described above via term-rewriting rules, guaranteeing a unique representative per score and enabling a fair comparison (not possible by diffing XML encodings directly).

2. Bar-level alignment by LCS

A Longest Common Subsequence (LCS) algorithm aligns equal bars between the two scores. Equality tests are accelerated using hash codes. Bar equality is considered modulo voice permutation to avoid problems from inconsistent voice numbering; for this purpose, voice hashes are combined by sum. The complement of the alignment is a sequence of diff-blocks, each being a pair of sub-sequences of successive bars between alignment points.

Bar-level alignment by Longest Common Subsequence
Bar-level alignment by LCS

3. Diff-block resolution

A Levenshtein edit-distance is computed between the two sequences of bars in each diff-block, using the following bar-level operations:

Diff-block resolution by Levenshtein edit-distance on bars
Diff-block resolution

4. Comparison of bars and voice sets

A bar contains a sequence of homophonic voices under a Fork label. Given two bars to compare, a matching between voices is computed by first pairing equal voices (via hash codes), then finding an optimal sequence of voice insertions, voice deletions, or voice replacements (resolved in step 5).

Matching voices within a bar
Comparison of bars and voice sets

5. Comparison of two voices

The content of two matched voices is compared by recursive descent through their DAG representations. Starting from a pair of nodes:

Recursive parallel descent comparing two voices' DAGs
Comparison of two voices (recursive descent)