lab_2_tokenize_by_bpe package
Submodules
Lab 2.
BPE and machine translation evaluation
- lab_2_tokenize_by_bpe.main.calculate_bleu(actual, reference, max_order=3)
Compare two sequences by virtue of BLEU metric.
- Parameters:
- Returns:
A value of BLEU metric
- Return type:
float | None
In case of corrupt input arguments or functions used return None, None is returned
- lab_2_tokenize_by_bpe.main.calculate_geo_mean(precisions, max_order)
Compute geometric mean of sequence of values.
- Parameters:
- Returns:
A value of geometric mean of Precision metric
- Return type:
float | None
In case of corrupt input arguments, None is returned
- lab_2_tokenize_by_bpe.main.calculate_precision(actual, reference)
Compare two sequences by virtue of Precision metric.
- Parameters:
- Returns:
Value of Precision metric
- Return type:
float | None
In case of corrupt input arguments, None is returned.
- lab_2_tokenize_by_bpe.main.collect_frequencies(text, start_of_word, end_of_word)
Count number of occurrences of each word.
- Parameters:
- Returns:
- Dictionary where key - preprocessed word,
value - number of occurrences
- Return type:
In case of corrupt input arguments or functions used return None, None is returned
- lab_2_tokenize_by_bpe.main.collect_ngrams(text, order)
Extract n-grams from the given sequence.
- Parameters:
- Returns:
A sequence of n-grams
- Return type:
In case of corrupt input arguments, None is returned
- lab_2_tokenize_by_bpe.main.count_tokens_pairs(word_frequencies)
Count number of occurrences of each pair of subsequent tokens.
- Parameters:
word_frequencies (dict[tuple[str, ...], int]) – A dictionary where key - preprocessed word, value - number of occurrences
- Returns:
- A dictionary where
key - token pair, value - number of occurrences
- Return type:
In case of corrupt input arguments, None is returned
- lab_2_tokenize_by_bpe.main.decode(encoded_text, vocabulary, end_of_word_token)
Translate encoded sequence into decoded one.
- Parameters:
- Returns:
Decoded sequence
- Return type:
str | None
In case of corrupt input arguments, None is returned
- lab_2_tokenize_by_bpe.main.encode(original_text, vocabulary, start_of_word_token, end_of_word_token, unknown_token)
Translate original text into a sequence of token identifiers.
- Parameters:
- Returns:
A list of token identifiers
- Return type:
In case of corrupt input arguments or functions used return None, None is returned
- lab_2_tokenize_by_bpe.main.get_vocabulary(word_frequencies, unknown_token)
Establish correspondence between tokens and its integer identifier.
- Parameters:
- Returns:
A dictionary where key - token, value - identifier
- Return type:
In case of corrupt input arguments, None is returned
- lab_2_tokenize_by_bpe.main.load_vocabulary(vocab_path)
Read and retrieve dictionary of type <token: identifier>.
- Parameters:
vocab_path (str) – A path to the saved vocabulary
- Returns:
A dictionary where key - token, value - identifier
- Return type:
In case of corrupt input arguments, None is returned
- lab_2_tokenize_by_bpe.main.merge_tokens(word_frequencies, pair)
Update word frequency dictionary by replacing a pair of tokens with a merged one.
- Parameters:
- Returns:
- A dictionary where
key - preprocessed word, value - number of occurrences
- Return type:
In case of corrupt input arguments, None is returned
- lab_2_tokenize_by_bpe.main.prepare_word(raw_word, start_of_word, end_of_word)
Tokenize a word into characters and attach optional boundary tokens.
- Parameters:
- Returns:
Preprocessed word
- Return type:
In case of corrupt input arguments, None is returned
- lab_2_tokenize_by_bpe.main.tokenize_word(word, vocabulary, end_of_word, unknown_token)
Split word into tokens.
- Parameters:
- Returns:
A list of token identifiers
- Return type:
In case of corrupt input arguments, None is returned
- lab_2_tokenize_by_bpe.main.train(word_frequencies, num_merges)
Create required number of new tokens by merging existing ones.
- Parameters:
- Returns:
- A dictionary where
key - preprocessed word, value - number of occurrences
- Return type:
In case of corrupt input arguments or functions used return None, None is returned