


'''simple docstring'''





from jiwer import compute_measures

import datasets


__lowerCamelCase												=						'''\
@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.}
}
'''

__lowerCamelCase												=						'''\
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.
'''

__lowerCamelCase												=						'''
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 				UpperCAmelCase			(			datasets.Metric						):


 def        __SCREAMING_SNAKE_CASE					(      self							:	Tuple ):
    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        __SCREAMING_SNAKE_CASE					(      self							:	Optional[Any]			,       __lowerCamelCase							:	Dict=None			,       __lowerCamelCase							:	str=None			,       __lowerCamelCase							:	List[Any]=False ):
    if concatenate_texts:
       return compute_measures(__lowerCamelCase			,       __lowerCamelCase )["wer"]
    else:
       UpperCAmelCase__	:str      =      0
       UpperCAmelCase__	:List[Any]      =      0
       for prediction, reference in zip(__lowerCamelCase			,       __lowerCamelCase ):
          UpperCAmelCase__	:Optional[int]      =      compute_measures(__lowerCamelCase			,       __lowerCamelCase )
          incorrect += measures["substitutions"] + measures["deletions"] + measures["insertions"]
          total += measures["substitutions"] + measures["deletions"] + measures["hits"]
       return incorrect / total







'''simple docstring'''





from multiprocessing import Lock, Pipe, Process

# lock used to ensure that two processes do not access a pipe at the same time
__lowerCamelCase												=						Lock()


def        a__     (					UpperCamelCase_						:      str,   UpperCamelCase_						:      Any,   UpperCamelCase_						:      Any,   UpperCamelCase_						:      int,   UpperCamelCase_						:      Union[str, Any],   UpperCamelCase_						:      List[str],   UpperCamelCase_						:      Optional[int]						):
   global process_lock

   # we perform n swaps since after n swaps we know we are sorted
   # we *could* stop early if we are sorted already, but it takes as long to
   # find out we are sorted as it does to sort the list with this algorithm
   for i in range(0,   10						):
      if (i + position) % 2 == 0 and r_send is not None:
         # send your value to your right neighbor
         process_lock.acquire()
         r_send[1].send(UpperCamelCase_						)
         process_lock.release()

         # receive your right neighbor's value
         process_lock.acquire()
         UpperCAmelCase__	:Union[str, Any]      =      rr_cv[0].recv()
         process_lock.release()

         # take the lower value since you are on the left
         UpperCAmelCase__	:List[Any]      =      min(UpperCamelCase_,   UpperCamelCase_						)
      elif (i + position) % 2 != 0 and l_send is not None:
         # send your value to your left neighbor
         process_lock.acquire()
         l_send[1].send(UpperCamelCase_						)
         process_lock.release()

         # receive your left neighbor's value
         process_lock.acquire()
         UpperCAmelCase__	:List[str]      =      lr_cv[0].recv()
         process_lock.release()

         # take the higher value since you are on the right
         UpperCAmelCase__	:List[Any]      =      max(UpperCamelCase_,   UpperCamelCase_						)
    # after all swaps are performed, send the values back to main
   result_pipe[1].send(UpperCamelCase_						)


def        a__     (					UpperCamelCase_						:      int						):
   UpperCAmelCase__	:List[str]      =      []
   UpperCAmelCase__	:Any      =      []
   # initialize the list of pipes where the values will be retrieved
   for _ in arr:
      result_pipe.append(Pipe()						)
   # creates the processes
   # the first and last process only have one neighbor so they are made outside
   # of the loop
   UpperCAmelCase__	:str      =      Pipe()
   UpperCAmelCase__	:Dict      =      Pipe()
   process_array_.append(
       Process(
           target=UpperCamelCase_,   args=(0, arr[0], None, temp_rs, None, temp_rr, result_pipe[0]),   )						)
   UpperCAmelCase__	:Optional[Any]      =      temp_rs
   UpperCAmelCase__	:Any      =      temp_rr

   for i in range(1,   len(UpperCamelCase_						) - 1						):
      UpperCAmelCase__	:Optional[int]      =      Pipe()
      UpperCAmelCase__	:List[str]      =      Pipe()
      process_array_.append(
          Process(
              target=UpperCamelCase_,   args=(i, arr[i], temp_ls, temp_rs, temp_lr, temp_rr, result_pipe[i]),   )						)
      UpperCAmelCase__	:Optional[Any]      =      temp_rs
      UpperCAmelCase__	:str      =      temp_rr

   process_array_.append(
       Process(
           target=UpperCamelCase_,   args=(
               len(UpperCamelCase_						) - 1,
               arr[len(UpperCamelCase_						) - 1],
               temp_ls,
               None,
               temp_lr,
               None,
               result_pipe[len(UpperCamelCase_						) - 1],
           ),   )						)

   # start the processes
   for p in process_array_:
      p.start()

   # wait for the processes to end and write their values to the list
   for p in range(0,   len(UpperCamelCase_						)						):
      UpperCAmelCase__	:List[str]      =      result_pipe[p][0].recv()
      process_array_[p].join()
   return arr


def        a__     (					):
   UpperCAmelCase__	:Optional[Any]      =      list(range(10,   0,   -1						)						)
   print('''Initial List'''						)
   print(*UpperCamelCase_						)
   UpperCAmelCase__	:str      =      odd_even_transposition(UpperCamelCase_						)
   print('''Sorted List\n'''						)
   print(*UpperCamelCase_						)


if __name__ == "__main__":
    main()



