Skip to content

Instantly share code, notes, and snippets.

@joaofig
Last active July 9, 2023 21:09
Show Gist options
  • Select an option

  • Save joaofig/9208a3e07b672bdb617bd41cf5366046 to your computer and use it in GitHub Desktop.

Select an option

Save joaofig/9208a3e07b672bdb617bd41cf5366046 to your computer and use it in GitHub Desktop.
def compute_probability(token_list: list[int]) -> float:
nodes = token_list[1:-1]
prob = 0.0
if len(nodes) > 2:
prob = 1.0
for i in range(len(nodes)-2):
t0, t1, t2 = nodes[i:i+3]
cnt = get_successors(int(t0), int(t1))
if len(cnt):
prob *= cnt[t2] / cnt.total()
else:
prob = 0.0
return prob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment