Validate whether the tag is properly formatted.
(text)
| 109 | |
| 110 | |
| 111 | def validate_think_pattern(text): |
| 112 | """Validate whether the <think> </think> tag is properly formatted.""" |
| 113 | start_tag = "<think>" |
| 114 | end_tag = "</think>" |
| 115 | |
| 116 | start_count = text.count(start_tag) |
| 117 | end_count = text.count(end_tag) |
| 118 | |
| 119 | if start_count == 1 and end_count == 1: |
| 120 | start_pos = text.find(start_tag) |
| 121 | end_pos = text.find(end_tag) |
| 122 | if start_pos < end_pos: |
| 123 | return True |
| 124 | return False |
| 125 | |
| 126 | |
| 127 | # Adapted from https://github.com/EleutherAI/lm-evaluation-harness/blob/main/lm_eval/tasks/hendrycks_math/utils.py |