@@ -13,7 +13,7 @@ def clean_and_create_vocabulary(
1313 vocabulary_to_add : list [str ],
1414 token_remove_regex : re .Pattern [str ] | None ,
1515) -> TokenizerModel :
16- """Cleans a vocabulary by removing duplicates and tokens that were already in the vocabulary."""
16+ """Clean a vocabulary by removing duplicates and tokens that were already in the vocabulary."""
1717 seen_tokens = set ()
1818
1919 n_duplicate = 0
@@ -22,10 +22,9 @@ def clean_and_create_vocabulary(
2222
2323 internal_tokens : list [str ] = model .sorted_vocabulary
2424 if token_remove_regex :
25- len_before = len (internal_tokens )
2625 tokens_to_remove = [token for token in internal_tokens if token_remove_regex .match (token )]
2726 model = model .remove_tokens_from_vocabulary (tokens_to_remove )
28- n_regex_removed = len_before - len (internal_tokens )
27+ n_regex_removed = len (tokens_to_remove )
2928 preprocessor = model .preprocessor
3029
3130 seen_tokens = set (internal_tokens )
@@ -38,7 +37,7 @@ def clean_and_create_vocabulary(
3837 n_empty += 1
3938 continue
4039 if len (preprocessed ) > 1 :
41- tokens_as_str = [f"'{ subword } '" for subword in token ]
40+ tokens_as_str = [f"'{ subword } '" for subword in preprocessed ]
4241 split_into = "," .join (tokens_as_str )
4342 logger .warning (f"Token '{ token } ' was split into multiple tokens after preprocessing: [{ split_into } ]" )
4443 added_tokens_to_add .append (token )
@@ -65,7 +64,7 @@ def clean_and_create_vocabulary(
6564
6665
6766def _report_statistics (n_multiword : int , n_duplicate : int , n_regex_removed : int , n_empty : int ) -> None :
68- """Helper function to avoid increasing complexity in main function ."""
67+ """Report statistics on the various types of issues we found ."""
6968 if n_multiword :
7069 logger .info (f"Added { n_multiword } multi-word tokens to the vocabulary." )
7170 if n_duplicate :
0 commit comments