



from ...configuration_utils import PretrainedConfig
from ...utils import logging


SCREAMING_SNAKE_CASE_:str					=						logging.get_logger(__name__)

SCREAMING_SNAKE_CASE_:str					=						{"""ctrl""": """https://huggingface.co/ctrl/resolve/main/config.json"""}






class SCREAMING_SNAKE_CASE__					(		SCREAMING_SNAKE_CASE__   ):




    '''simple docstring'''






    __lowerCamelCase      :			List[str] =				"ctrl"
    __lowerCamelCase      :			Any =				["past_key_values"]
    __lowerCamelCase      :			str =				{
        "max_position_embeddings": "n_positions",
        "hidden_size": "n_embd",
        "num_attention_heads": "n_head",
        "num_hidden_layers": "n_layer",
    }






    def __init__(	self,		lowerCamelCase__=24_6534,		lowerCamelCase__=256,		lowerCamelCase__=1280,		lowerCamelCase__=8192,		lowerCamelCase__=48,		lowerCamelCase__=16,		lowerCamelCase__=0.1,		lowerCamelCase__=0.1,		lowerCamelCase__=1e-6,		lowerCamelCase__=0.02,		lowerCamelCase__=True,		**lowerCamelCase__,		):
        A			:	List[Any]										=       vocab_size
        A			:	Union[str, Any]										=       n_positions
        A			:	Dict										=       n_embd
        A			:	str										=       n_layer
        A			:	List[Any]										=       n_head
        A			:	Tuple										=       dff
        A			:	List[str]										=       resid_pdrop
        A			:	Union[str, Any]										=       embd_pdrop
        A			:	Tuple										=       layer_norm_epsilon
        A			:	List[str]										=       initializer_range

        A			:	List[str]										=       use_cache

        super().__init__(**lowerCamelCase__		)







from jiwer import compute_measures

import datasets


SCREAMING_SNAKE_CASE_:str					=						"""\
@inproceedings{inproceedings,
    author = {Morris, Andrew and Maier, Viktoria and Green, Phil},
    year = {2004},
    month = {01},
    pages = {},
    title = {From WER and RIL to MER and WIL: improved evaluation measures for connected speech recognition.}
}
"""

SCREAMING_SNAKE_CASE_:Union[str, Any]					=						"""\
Word error rate (WER) is a common metric of the performance of an automatic speech recognition system.

The general difficulty of measuring performance lies in the fact that the recognized word sequence can have a different length from the reference word sequence (supposedly the correct one). The WER is derived from the Levenshtein distance, working at the word level instead of the phoneme level. The WER is a valuable tool for comparing different systems as well as for evaluating improvements within one system. This kind of measurement, however, provides no details on the nature of translation errors and further work is therefore required to identify the main source(s) of error and to focus any research effort.

This problem is solved by first aligning the recognized word sequence with the reference (spoken) word sequence using dynamic string alignment. Examination of this issue is seen through a theory called the power law that states the correlation between perplexity and word error rate.

Word error rate can then be computed as:

WER = (S + D + I) / N = (S + D + I) / (S + D + C)

where

S is the number of substitutions,
D is the number of deletions,
I is the number of insertions,
C is the number of correct words,
N is the number of words in the reference (N=S+D+C).

This value indicates the average number of errors per reference word. The lower the value, the better the
performance of the ASR system with a WER of 0 being a perfect score.
"""

SCREAMING_SNAKE_CASE_:List[Any]					=						"""
Compute WER score of transcribed segments against references.

Args:
    references: List of references for each speech input.
    predictions: List of transcriptions to score.
    concatenate_texts (bool, default=False): Whether to concatenate all input texts or compute WER iteratively.

Returns:
    (float): the word error rate

Examples:

    >>> predictions = [\"this is the prediction\", \"there is an other sample\"]
    >>> references = [\"this is the reference\", \"there is another one\"]
    >>> wer = datasets.load_metric(\"wer\")
    >>> wer_score = wer.compute(predictions=predictions, references=references)
    >>> print(wer_score)
    0.5
"""






@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION			,						_KWARGS_DESCRIPTION   )
class SCREAMING_SNAKE_CASE__					(		datasets.Metric   ):




    '''simple docstring'''






    def       _lowerCAmelCase (	self		):
        return datasets.MetricInfo(
            description=_DESCRIPTION,		citation=_CITATION,		inputs_description=_KWARGS_DESCRIPTION,		features=datasets.Features(
                {
                    """predictions""": datasets.Value("""string""",		id="""sequence"""		),
                    """references""": datasets.Value("""string""",		id="""sequence"""		),
                }		),		codebase_urls=["""https://github.com/jitsi/jiwer/"""],		reference_urls=[
                """https://en.wikipedia.org/wiki/Word_error_rate""",
            ],		)






    def       _lowerCAmelCase (	self,		lowerCamelCase__=None,		lowerCamelCase__=None,		lowerCamelCase__=False		):
        if concatenate_texts:
            return compute_measures(lowerCamelCase__,		lowerCamelCase__		)["wer"]
        else:
            A			:	str										=       0
            A			:	int										=       0
            for prediction, reference in zip(lowerCamelCase__,		lowerCamelCase__		):
                A			:	Tuple										=       compute_measures(lowerCamelCase__,		lowerCamelCase__		)
                incorrect += measures["substitutions"] + measures["deletions"] + measures["insertions"]
                total += measures["substitutions"] + measures["deletions"] + measures["hits"]
            return incorrect / total


