Код: Выделить всё
mention_embeddings = [M, dim]
class_index = [M, 1] # (already sorted) . Eg [0,0,0,1,1,2,3,4...] means 3 first mentions have the same class and so on.
# Note: max(class_index) = N - 1 as we have N classes and M >= N
Код: Выделить всё
cluster_index = [M, 1] # an array indicates which mention index are in the same cluster. E.g [0, 1, 0, 2, 3, 3, .... ] means mention at index 0, and 2 are the same cluster,...
num_clusters = torch.unquie(cluster_index) # -> K cluster. N from [N, 1] => [M, 1]
positive_labels = positive_labels[cluster_label_index] # choose K indices from M indices from [M, 1] => [K, 1]
Я это вижу для этого подхода мне нужно назвать метку кластера по индексу от 0 -> K-1, поэтому, когда я вычисляю встраивания кластера с помощью index_add_, она сопоставляется с упорядоченным индексом, я думаю, от 0 -> K-1
также эта строка код:
Код: Выделить всё
cluster_label_index = torch.cat([item.view(-1, )
for item in cluster_label_index_mapping.values()]
)
Этот подход довольно длинный и непростой
Подробнее здесь: https://stackoverflow.com/questions/793 ... ge-mapping
Мобильная версия