|
| 1 | +# MIT License |
| 2 | + |
| 3 | +# Copyright (c) 2024 The HuggingFace Team |
| 4 | + |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | + |
| 12 | +# The above copyright notice and this permission notice shall be included in all |
| 13 | +# copies or substantial portions of the Software. |
| 14 | + |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | +# SOFTWARE. |
| 22 | + |
| 23 | +import unittest |
| 24 | + |
| 25 | +from lighteval.utils.utils import remove_reasoning_tags |
| 26 | + |
| 27 | + |
| 28 | +class TestRemoveReasoningTags(unittest.TestCase): |
| 29 | + def test_remove_reasoning_tags(self): |
| 30 | + text = "<think> Reasoning section </think> Answer section" |
| 31 | + tag_pairs = [("<think>", "</think>")] |
| 32 | + result = remove_reasoning_tags(text, tag_pairs) |
| 33 | + self.assertEqual(result, " Answer section") |
| 34 | + |
| 35 | + def test_remove_multiple_tags(self): |
| 36 | + text = "<think> Reasoning </think> Interlude <think> More reasoning </think> Answer" |
| 37 | + tag_pairs = [("<think>", "</think>")] |
| 38 | + result = remove_reasoning_tags(text, tag_pairs) |
| 39 | + self.assertEqual(result, " Interlude Answer") |
| 40 | + |
| 41 | + def test_no_tags(self): |
| 42 | + text = "No reasoning tags here." |
| 43 | + tag_pairs = [("<think>", "</think>")] |
| 44 | + result = remove_reasoning_tags(text, tag_pairs) |
| 45 | + self.assertEqual(result, "No reasoning tags here.") |
| 46 | + |
| 47 | + def test_empty_text(self): |
| 48 | + text = "" |
| 49 | + tag_pairs = [("<think>", "</think>")] |
| 50 | + result = remove_reasoning_tags(text, tag_pairs) |
| 51 | + self.assertEqual(result, "") |
| 52 | + |
| 53 | + def test_no_opening_tag(self): |
| 54 | + text = "No opening tag <think> Reasoning section. </think> Answer section" |
| 55 | + tag_pairs = [("<think>", "</think>")] |
| 56 | + result = remove_reasoning_tags(text, tag_pairs) |
| 57 | + self.assertEqual(result, "No opening tag Answer section") |
| 58 | + |
| 59 | + def test_no_closing_tag(self): |
| 60 | + text = "<think> Reasoning section. Answer section" |
| 61 | + tag_pairs = [("<think>", "</think>")] |
| 62 | + result = remove_reasoning_tags(text, tag_pairs) |
| 63 | + self.assertEqual(result, "<think> Reasoning section. Answer section") |
0 commit comments