All problems
HMM Transition Count
Problem
Count tag transitions in a sequence, including boundary transitions. Insert a '<s>' start symbol before the first tag and a '</s>' end symbol after the last tag, then count adjacent pairs.
Return a dictionary keyed by 'from to'. An empty tag sequence yields an empty dictionary.
Hint
Track the previous symbol starting from '<s>' and finish with '</s>'.
Test cases
case 1
in: [["A","B","A"]]
expected: {"<s> A":1,"A B":1,"B A":1,"A </s>":1}
case 2
in: [[]]
expected: {}
case 3
in: [["X"]]
expected: {"<s> X":1,"X </s>":1}
case 4
in: [["A","A"]]
expected: {"<s> A":1,"A A":1,"A </s>":1}
Starter codePython
def hmm_transition_count(tags):
# Your code here
pass4 test cases · run your code against them in the editor