A shape mismatch error is often created by a wrongly shaped input.
I don’t know what the shape of your current input is and what shape is expected, but you might want to check the reference implementations and what inputs are used in the original code.
PS: you can post code snippets by wrapping them into three backticks ```, which makes debugging easier