Repository: jitsi/jiwer

Issue:
Version 3.0.0 can produce wrong results
Hi,

when I use jiwer version 3.0.0 with the following commands:

```python
wer_transform = jiwer.Compose(
    [
        jiwer.ToLowerCase(),
        jiwer.RemoveMultipleSpaces(),
        jiwer.Strip(),
        jiwer.ReduceToListOfListOfWords(),
    ]
    )
wer = jiwer.wer(
        truth = 'This is a short Sentence with a few Words with upper and Lower cases',
        hypothesis = 'His is a short Sentence with a few Words with upper and Lower cases',
        truth_transform = wer_transform,
        hypothesis_transform = wer_transform,
        )
```
I get wer=0.0714, which is the expected result based on the WER formula.

But when I use the non-deprecated keywords 'reference' and 'reference_transform' instead of 'truth' and 'truth_transform':
```python
wer = jiwer.wer(
        reference = 'This is a short Sentence with a few Words with upper and Lower cases',
        hypothesis = 'His is a short Sentence with a few Words with upper and Lower cases',
        reference_transform = wer_transform,
        hypothesis_transform = wer_transform,
        )
```
I get wer=0.2857, which is clearly wrong.
This does not happen if the 'jiwer.ToLowerCase()' transform is removed from the transformation, thus I expect the bug to be related to that.

Cheers,
   Paul

Discussion:

Patch:
diff --git a/jiwer/measures.py b/jiwer/measures.py
index 29ba0b9..ba55a6f 100644
--- a/jiwer/measures.py
+++ b/jiwer/measures.py
@@ -69,7 +69,7 @@ def wer(
     reference_transform: Union[tr.Compose, tr.AbstractTransform] = wer_default,
     hypothesis_transform: Union[tr.Compose, tr.AbstractTransform] = wer_default,
     truth: Union[str, List[str]] = None,
-    truth_transform: Union[tr.Compose, tr.AbstractTransform] = wer_default,
+    truth_transform: Union[tr.Compose, tr.AbstractTransform] = None,
 ) -> float:
     """
     Calculate the word error rate (WER) between one or more reference and
@@ -100,18 +100,17 @@ def wer(
         reference_transform,
         hypothesis_transform,
     ) = _deprecate_truth(
-        reference,
-        hypothesis,
-        truth,
-        reference_transform,
-        truth_transform,
-        hypothesis_transform,
+        reference=reference,
+        hypothesis=hypothesis,
+        truth=truth,
+        reference_transform=reference_transform,
+        truth_transform=truth_transform,
+        hypothesis_transform=hypothesis_transform,
     )
 
     output = process_words(
         reference, hypothesis, reference_transform, hypothesis_transform
     )
-
     return output.wer
 
 
@@ -121,7 +120,7 @@ def mer(
     reference_transform: Union[tr.Compose, tr.AbstractTransform] = wer_default,
     hypothesis_transform: Union[tr.Compose, tr.AbstractTransform] = wer_default,
     truth: Union[str, List[str]] = None,
-    truth_transform: Union[tr.Compose, tr.AbstractTransform] = wer_default,
+    truth_transform: Union[tr.Compose, tr.AbstractTransform] = None,
 ) -> float:
     """
     Calculate the match error rate (MER) between one or more reference and
@@ -152,12 +151,12 @@ def mer(
         reference_transform,
         hypothesis_transform,
     ) = _deprecate_truth(
-        reference,
-        hypothesis,
-        truth,
-        reference_transform,
-        truth_transform,
-        hypothesis_transform,
+        reference=reference,
+        hypothesis=hypothesis,
+        truth=truth,
+        reference_transform=reference_transform,
+        truth_transform=truth_transform,
+        hypothesis_transform=hypothesis_transform,
     )
 
     output = process_words(
@@ -173,7 +172,7 @@ def wip(
     reference_transform: Union[tr.Compose, tr.AbstractTransform] = wer_default,
     hypothesis_transform: Union[tr.Compose, tr.AbstractTransform] = wer_default,
     truth: Union[str, List[str]] = None,
-    truth_transform: Union[tr.Compose, tr.AbstractTransform] = wer_default,
+    truth_transform: Union[tr.Compose, tr.AbstractTransform] = None,
 ) -> float:
     """
     Calculate the word information preserved (WIP) between one or more reference and
@@ -204,12 +203,12 @@ def wip(
         reference_transform,
         hypothesis_transform,
     ) = _deprecate_truth(
-        reference,
-        hypothesis,
-        truth,
-        reference_transform,
-        truth_transform,
-        hypothesis_transform,
+        reference=reference,
+        hypothesis=hypothesis,
+        truth=truth,
+        reference_transform=reference_transform,
+        truth_transform=truth_transform,
+        hypothesis_transform=hypothesis_transform,
     )
 
     output = process_words(
@@ -225,7 +224,7 @@ def wil(
     reference_transform: Union[tr.Compose, tr.AbstractTransform] = wer_default,
     hypothesis_transform: Union[tr.Compose, tr.AbstractTransform] = wer_default,
     truth: Union[str, List[str]] = None,
-    truth_transform: Union[tr.Compose, tr.AbstractTransform] = wer_default,
+    truth_transform: Union[tr.Compose, tr.AbstractTransform] = None,
 ) -> float:
     """
     Calculate the word information lost (WIL) between one or more reference and
@@ -256,12 +255,12 @@ def wil(
         reference_transform,
         hypothesis_transform,
     ) = _deprecate_truth(
-        reference,
-        hypothesis,
-        truth,
-        reference_transform,
-        truth_transform,
-        hypothesis_transform,
+        reference=reference,
+        hypothesis=hypothesis,
+        truth=truth,
+        reference_transform=reference_transform,
+        truth_transform=truth_transform,
+        hypothesis_transform=hypothesis_transform,
     )
 
     output = process_words(
@@ -337,7 +336,7 @@ def cer(
     hypothesis_transform: Union[tr.Compose, tr.AbstractTransform] = cer_default,
     return_dict: bool = False,
     truth: Union[str, List[str]] = None,
-    truth_transform: Union[tr.Compose, tr.AbstractTransform] = cer_default,
+    truth_transform: Union[tr.Compose, tr.AbstractTransform] = None,
 ) -> Union[float, Dict[str, Any]]:
     """
     Calculate the character error rate (CER) between one or more reference and
@@ -373,12 +372,12 @@ def cer(
         reference_transform,
         hypothesis_transform,
     ) = _deprecate_truth(
-        reference,
-        hypothesis,
-        truth,
-        reference_transform,
-        truth_transform,
-        hypothesis_transform,
+        reference=reference,
+        hypothesis=hypothesis,
+        truth=truth,
+        reference_transform=reference_transform,
+        truth_transform=truth_transform,
+        hypothesis_transform=hypothesis_transform,
     )
 
     output = process_characters(


Test patch:
diff --git a/tests/test_measures.py b/tests/test_measures.py
index 88677ed..50fc744 100644
--- a/tests/test_measures.py
+++ b/tests/test_measures.py
@@ -359,6 +359,50 @@ class TestMeasuresDefaultTransform(unittest.TestCase):
                 method(reference="only ref")
                 method(hypothesis="only hypothesis")
 
+    def test_deprecated_truth_and_ref_with_transform(self):
+        wer_transform = jiwer.Compose(
+            [
+                jiwer.ToLowerCase(),
+                jiwer.RemoveMultipleSpaces(),
+                jiwer.Strip(),
+                jiwer.ReduceToListOfListOfWords(),
+            ]
+        )
+        cer_transform = jiwer.Compose(
+            [
+                jiwer.ToLowerCase(),
+                jiwer.RemoveMultipleSpaces(),
+                jiwer.Strip(),
+                jiwer.ReduceToListOfListOfChars(),
+            ]
+        )
+
+        for key, method in [
+            ("wer", jiwer.wer),
+            ("mer", jiwer.mer),
+            ("wil", jiwer.wil),
+            ("wip", jiwer.wip),
+            ("cer", jiwer.cer),
+        ]:
+            if key == "cer":
+                tr = cer_transform
+            else:
+                tr = wer_transform
+
+            result = method(
+                truth="This is a short Sentence with a few Words with upper and Lower cases",
+                hypothesis="His is a short Sentence with a few Words with upper and Lower cases",
+                truth_transform=tr,
+                hypothesis_transform=tr,
+            )
+            result_same = method(
+                reference="This is a short Sentence with a few Words with upper and Lower cases",
+                hypothesis="His is a short Sentence with a few Words with upper and Lower cases",
+                reference_transform=tr,
+                hypothesis_transform=tr,
+            )
+            self.assertAlmostEqual(result, result_same)
+
 
 def test_deprecate_compute_measures():
     # TODO: remove once deprecated