# Datasets.load\_metric("cer") does not work

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdatasets-load-metric-cer-does-not-work%2F11931%3E%5C
**Category:** 🤗Datasets\
**Created:** [November 17, 2021, 3:22am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdatasets-load-metric-cer-does-not-work%2F11931 "2021-11-17T03:22:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gmarus](https://avatars.discourse-cdn.com/v4/letter/g/82dd89/32.png) [@gmarus](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fgmarus)%5C
**Post date:** [November 17, 2021, 3:22am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdatasets-load-metric-cer-does-not-work%2F11931%2F1 "2021-11-17T03:22:32Z")

</div>

CER function does not work properly, even when one tries to execute the example in help. Code is below

```auto
from datasets import load_metric
cer = load_metric("cer")
predictions = ["this is the prediction", "there is an other sample"]
references = ["this is the reference", "there is another one"]

cer_score = cer.compute(predictions=predictions, references=references)
print(cer_score)

```

outputs

```auto
ValueError Traceback (most recent call last)
/tmp/ipykernel_5923/623465361.py in <module>
      4 references = ["this is the reference", "there is another one"]
      5 
----> 6 cer_score = cer.compute(predictions=predictions, references=references)
      7 print(cer_score)

/opt/conda/lib/python3.7/site-packages/datasets/metric.py in compute(self, predictions, references, **kwargs)
    402 references = self.data["references"]
    403 with temp_seed(self.seed):
--> 404 output = self._compute(predictions=predictions, references=references, **kwargs)
    405 
    406 if self.buf_writer is not None:

~/.cache/huggingface/modules/datasets_modules/metrics/cer/4e547cc82fc2e597c84fe25f48ed77e3a9acfd354308fe654ccbc6ea9473a61a/cer.py in _compute(self, predictions, references, concatenate_texts)
    132 prediction,
    133 truth_transform=cer_transform,
--> 134 hypothesis_transform=cer_transform,
    135 )
    136 incorrect += measures["substitutions"] + measures["deletions"] + measures["insertions"]

/opt/conda/lib/python3.7/site-packages/jiwer/measures.py in compute_measures(truth, hypothesis, truth_transform, hypothesis_transform, **kwargs)
    208 # Preprocess truth and hypothesis
    209 truth, hypothesis = _preprocess(
--> 210 truth, hypothesis, truth_transform, hypothesis_transform
    211 )
    212 

/opt/conda/lib/python3.7/site-packages/jiwer/measures.py in _preprocess(truth, hypothesis, truth_transform, hypothesis_transform)
    327 raise ValueError(
    328 "number of ground truth inputs ({}) and hypothesis inputs ({}) must match.".format(
--> 329 len(transformed_truth), len(transformed_hypothesis)
    330 )
    331 )

ValueError: number of ground truth inputs (21) and hypothesis inputs (22) must match.

```

---

<div class="post-metadata">

**Author:** ![mariosasko](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mariosasko/32/31548_2.png) [@mariosasko](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmariosasko)%5C
**Post date:** [November 17, 2021, 11:42am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdatasets-load-metric-cer-does-not-work%2F11931%2F2 "2021-11-17T11:42:20Z")

</div>

Hi,

this issue was fixed a few days ago, and it will be included in the next release of `datasets`.

In the meantime, you can download the updated version of the metric script as follows:

```python
cer_metric = load_metric("cer", revision="master")

```

---

<div class="post-metadata">

**Author:** ![gmarus](https://avatars.discourse-cdn.com/v4/letter/g/82dd89/32.png) [@gmarus](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fgmarus)%5C
**Post date:** [November 17, 2021, 5:32pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdatasets-load-metric-cer-does-not-work%2F11931%2F3 "2021-11-17T17:32:34Z")

</div>

Thank you!
