asr-evaluation icon indicating copy to clipboard operation
asr-evaluation copied to clipboard

Allow library to be imported and used as a module

Open yeoji opened this issue 3 years ago • 0 comments

Hello, thanks for this awesome library!

Not too sure if this PR would be of any value, so let me know if I should close it.

Purpose

This PR will allow the library to be used as a module in another application.

It exposes the results from the evaluation and returns it as a dict so it is accessible instead of just printing it out.

To do this, the changes in the PR also removed the use of global variables that keeps track of the counters/word confusions.

Example Usage

from asr_evaluation.asr_evaluation import evaluate as asr_evaluation

class AsrEvaluationArgs(dict):
    def __getattr__(self, name):
        return self[name]

ref = open('./ref.txt', 'r')
hyp = open('./hyp.txt', 'r')

results = asr_evaluation(AsrEvaluationArgs({
         'ref': ref,
         'hyp': hyp,
         'print_instances': True,
         'print_errors': False,
         'head_ids': False,
         'tail_ids': False,
         'confusions': True,
         'min_word_count': 1,
         'print_wer_vs_length': False,
         'case_insensitive': True,
         'remove_empty_refs': False
}))

yeoji avatar Sep 01 '20 06:09 yeoji