Skip to content

fix: Unigram prune_sentence_pieces uses alternatives[id].len() not alternatives.len() - #2394

Open
VirajMishra1 wants to merge 1 commit into
huggingface:mainfrom
VirajMishra1:fix-unigram-prune-loss-alternatives-len
Open

fix: Unigram prune_sentence_pieces uses alternatives[id].len() not alternatives.len()#2394
VirajMishra1 wants to merge 1 commit into
huggingface:mainfrom
VirajMishra1:fix-unigram-prune-loss-alternatives-len

Conversation

@VirajMishra1

Copy link
Copy Markdown

Problem

prune_sentence_pieces computes the log-normaliser after hypothetically removing piece id using:

let logsum_alt = (sum + freq[id] * (alternatives.len() - 1) as f64).ln();

alternatives.len() is the total number of pieces in the vocabulary. The comment immediately above says:

new_sum = current_sum - freq[i] + freq[i] * alternatives.size()

but alternatives.size() here means alternatives[id].size() — the number of re-segmentation pieces for piece id specifically — not the whole alternatives vector length (which is pieces.len()).

Using the wrong length makes the probability mass appear to be redistributed over all pieces.len() - 1 alternatives instead of just the alternatives[id].len() - 1 that actually replace piece id, producing an incorrect logsum_alt and therefore incorrect pruning loss for every piece.

This was first reported in #1536.

Fix

let logsum_alt = (sum + freq[id] * (alternatives[id].len() - 1) as f64).ln();

One character change. The comment is updated to match.

Fixes #2069

…ternatives.len()

The loss computation for piece removal used alternatives.len() (the total
number of pieces) instead of alternatives[id].len() (the number of
re-segmentation alternatives for the specific piece being scored).

This made the logsum_alt term wrong: the probability mass was redistributed
over all pieces rather than just the alternatives for piece uid=501(viraj) gid=20(staff) groups=20(staff),12(everyone),61(localaccounts),79(_appserverusr),80(admin),81(_appserveradm),98(_lpadmin),33(_appstore),100(_lpoperator),204(_developer),250(_analyticsusers),395(com.apple.access_ftp),398(com.apple.access_screensharing),399(com.apple.access_ssh),400(com.apple.access_remote_ae), producing
an incorrect loss and therefore incorrect pruning decisions.

Fixes huggingface#2069
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unigram trainer: prune loss uses alternatives.len() instead of alternatives[id].len()

1 participant