Skip to content

Commit

Permalink
Try dotting all pairs of vectors for orthogonality, not just neighbors
Browse files Browse the repository at this point in the history
  • Loading branch information
AngledLuffa committed Dec 17, 2024
1 parent ed45fe1 commit d0018cd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions stanza/models/constituency/parser_training.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections import Counter, namedtuple
import copy
import itertools
import logging
import os
import random
Expand Down Expand Up @@ -689,13 +690,13 @@ def build_losses(con_values, tree):
subtrees = [x for x in tree.children if not x.is_preterminal()]
for subtree in subtrees:
build_losses(con_values, subtree)
for subtree_idx in range(len(subtrees)-1):
left = str(subtrees[subtree_idx])
right = str(subtrees[subtree_idx+1])
for left, right in itertools.combinations(subtrees, 2):
left = str(left)
right = str(right)
if left in con_values and right in con_values:
left_value = con_values[left].squeeze(0)
right_value = con_values[right].squeeze(0)
mse = torch.dot(left_value, right_value)
mse = torch.dot(left_value, right_value) / (len(subtrees) - 1)
orthogonal_losses.append(mse)
for result in gold_results:
gold_constituents = result.constituents
Expand Down

0 comments on commit d0018cd

Please sign in to comment.