An open API service indexing awesome lists of open source software.

https://github.com/codycollier/wer

A word error rate util for golang
https://github.com/codycollier/wer

asr speech-recognition speech-to-text word-error-rate

Last synced: 7 months ago
JSON representation

A word error rate util for golang

Awesome Lists containing this project

README

          

## Word Error Rate (wer)

`wer` is a golang package which provides a function for calculating word error rate and word accuracy. It expects a pair of pre-tokenized and optionally pre-processed strings.

References:

* https://martin-thoma.com/word-error-rate-calculation/
* https://en.wikipedia.org/wiki/Word_error_rate

## Example Usage

```
package main

import (
"fmt"
"strings"

"github.com/codycollier/wer"
)

func main() {

// strings to be evaluated
knownGoodTranscript := "The quick brown fox jumps over the lazy dog"
candidateTranscript := "the slow grey snail jumps over the lazy cat"

// optionally lowercase / pre-process
knownGoodTranscript = strings.ToLower(knownGoodTranscript)
candidateTranscript = strings.ToLower(candidateTranscript)

// convert to a list of words/tokens
reference := strings.Split(knownGoodTranscript, " ")
candidate := strings.Split(candidateTranscript, " ")

// compare
wer, wacc := wer.WER(reference, candidate)

fmt.Printf("reference: %s\n", reference)
fmt.Printf("candidate: %s\n", candidate)
fmt.Printf("word error rate: %v\n", wer)
fmt.Printf("word accuracy: %v\n", wacc)

}
```

```
[host]$ go run example/example.go
reference: [the quick brown fox jumps over the lazy dog]
candidate: [the slow grey snail jumps over the lazy cat]
word error rate: 0.4444444444444444
word accuracy: 0.5555555555555556
```