The transkun project includes a specialized NeuralSemiCRF module optimized for event-based piano transcription. This module takes a score tensor (representing interval scores) and a noise score (representing non-interval scores) to decode event intervals using dynamic programming (Viterbi).
Input Dimensions:
score: [TEnd, TBegin, NBatch] (only the lower triangular part is used)noiseScore: [TBegin, TBegin+1] (representing the score for not being an interval)intervals: A list of lists containing non-overlapping tuples (TBegin, TEnd) for each batch.
import CRF
import torch
T = 200
NBatch = 4
# representing the score for the interval [TBegin, TEnd]
# dimensions: [TEnd, TBegin, NBatch]
score = ((torch.randn(T, T, NBatch))).cuda()
# representing the score for being not an interval, dimensions [TBegin, TBegin+1]
noiseScore= ((torch.randn(T-1, NBatch))).cuda()
# a list of list of non-overlapping intervals
intervals = [
[(0,2), (4,6),(6,6), (7,8)],
[(1,2), (3,5), (19,19)],
[(0,0),(4,7)],
[],
]
crf = CRF.NeuralSemiCRFInterval(score, noiseScore)
## log probability
logP = crf.logProb(intervals)
## decoding
decoded = crf.decode()
## decoding starting from a given position, useful for segment based processing
decoded = crf.decode(forcedStartPos = [4]*NBatch)