Skip to main content

Compute Word Error Rate for Tibetan language text.

Project description

Tibetan-WER

Word Error Rate (WER) and Syllable Error Rate (SER) metrics for Tibetan ASR evaluation, with three word segmentation methods.

Install

pip install tibetan-wer

For BERT-based segmentation:

pip install "tibetan-wer[bert]"

For Gemini-based segmentation:

pip install "tibetan-wer[gemini]"

Functions

Function Segmentation method Extra dependency
wer / botok_wer botok morphological tokenizer (none)
ser tsek (་) syllable boundary (none)
bert_wer KoichiYasuoka/tibetan-bert-base-upos tibetan-wer[bert]
gemini_wer Gemini API tibetan-wer[gemini]

All functions accept either a single string or a list of strings and return a dict with micro_wer/macro_wer (or micro_ser/macro_ser), plus substitutions, insertions, deletions, and num_sentences.

Usage

WER (botok)

from tibetan_wer import wer

predictions = ['གཞོན་ནུར་གྱུར་པ་ལ་ཕྱག་འཚལ་ལོ༔']
references  = ['འཇམ་དཔལ་གཞོན་ནུར་གྱུར་པ་ལ་ཕྱག་འཚལ་ལོ༔']

result = wer(predictions, references)

print(f'Micro-WER: {result["micro_wer"]:.3f}')
print(f'Macro-WER: {result["macro_wer"]:.3f}')
print(f'Substitutions: {result["substitutions"]}')
print(f'Insertions:    {result["insertions"]}')
print(f'Deletions:     {result["deletions"]}')

SER

from tibetan_wer import ser

result = ser(predictions, references)

print(f'Micro-SER: {result["micro_ser"]:.3f}')
print(f'Macro-SER: {result["macro_ser"]:.3f}')

BERT WER

from tibetan_wer import bert_wer

result = bert_wer(predictions, references)          # auto-detects CUDA
result = bert_wer(predictions, references, device=0)  # force GPU 0

Gemini WER

from tibetan_wer import gemini_wer

result = gemini_wer(predictions, references)
# api_key defaults to the GEMINI_API_KEY environment variable
result = gemini_wer(predictions, references, api_key="YOUR_KEY")

Usage for Model Evaluation

import evaluate
from tibetan_wer import wer as tib_wer, ser as tib_ser

cer_metric = evaluate.load("cer")

def compute_metrics(pred):
    pred_ids = pred.predictions
    label_ids = pred.label_ids

    label_ids[label_ids == -100] = tokenizer.pad_token_id

    pred_str  = tokenizer.batch_decode(pred_ids,   skip_special_tokens=True)
    label_str = tokenizer.batch_decode(label_ids,  skip_special_tokens=True)

    cer         = cer_metric.compute(predictions=pred_str, references=label_str)
    wer_result  = tib_wer(pred_str, label_str)
    ser_result  = tib_ser(pred_str, label_str)

    return {
        "cer":                    cer,
        "tib_macro_wer":          wer_result["macro_wer"],
        "tib_micro_wer":          wer_result["micro_wer"],
        "word_substitutions":     wer_result["substitutions"],
        "word_insertions":        wer_result["insertions"],
        "word_deletions":         wer_result["deletions"],
        "tib_macro_ser":          ser_result["macro_ser"],
        "tib_micro_ser":          ser_result["micro_ser"],
        "syllable_substitutions": ser_result["substitutions"],
        "syllable_insertions":    ser_result["insertions"],
        "syllable_deletions":     ser_result["deletions"],
    }
trainer = Seq2SeqTrainer(
    args=training_args,
    model=model,
    train_dataset=dataset["train"],
    eval_dataset=dataset["test"],
    data_collator=data_collator,
    compute_metrics=compute_metrics,
    tokenizer=processor.feature_extractor,
)

trainer.train()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tibetan_wer-1.1.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tibetan_wer-1.1.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file tibetan_wer-1.1.0.tar.gz.

File metadata

  • Download URL: tibetan_wer-1.1.0.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for tibetan_wer-1.1.0.tar.gz
Algorithm Hash digest
SHA256 22f863e3ce046cd6a367595d2d0a3e9651eb3dc05b0d7a972a29e033fdb6153e
MD5 bf41e6ce26d71cf34bed09f2bf908bf6
BLAKE2b-256 dd9893ca775ac19a8afcfb828df18a4af6654c0efa32809dcae66b1e163f8f16

See more details on using hashes here.

File details

Details for the file tibetan_wer-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: tibetan_wer-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for tibetan_wer-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 36416f589dc036a9ddd96c4345f97c412b564befa72279d307d0122017771afd
MD5 35b86520e6e0dc7bf1bb05ae2ec8d620
BLAKE2b-256 ac96664d656823ca35e2368f168caf26ab828f7c2788bf2b09c52d73ad1c5578

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page