text
stringlengths
0
15.3k
string = string.replace('\\$', '')
string = remove_right_units(string)
string = string.replace('\\%', '')
string = string.replace('\\%', '')
string = string.replace(' .', ' 0.')
string = string.replace('{.', '{0.')
if len(string) == 0:
return string
if string[0] == '.':
string = '0' + string
if len(string.split('=')) == 2:
if len(string.split('=')[0]) <= 2:
string = string.split('=')[1]
string = fix_sqrt(string)
string = string.replace(' ', '')
string = fix_fracs(string)
if string == '0.5':
string = '\\frac{1}{2}'
string = fix_a_slash_b(string)
return string
# File: lm-evaluation-harness-main/lm_eval/tasks/ifeval/instructions.py
""""""
import collections
import json
import logging
import random
import re
import string
from typing import Dict, Optional, Sequence, Union
import langdetect
from lm_eval.tasks.ifeval import instructions_util
logger = logging.getLogger(__name__)
_InstructionArgsDtype = Optional[Dict[str, Union[int, str, Sequence[str]]]]
_LANGUAGES = instructions_util.LANGUAGE_CODES
_COMPARISON_RELATION = ('less than', 'at least')
_MAX_NUM_SENTENCES = 20
_NUM_PLACEHOLDERS = 4
_NUM_BULLETS = 5
_CONSTRAINED_RESPONSE_OPTIONS = ('My answer is yes.', 'My answer is no.', 'My answer is maybe.')
_STARTER_OPTIONS = ('I would say', 'My answer is', 'I believe', 'In my opinion', 'I think', 'I reckon', 'I feel', 'From my perspective', 'As I see it', 'According to me', "As far as I'm concerned", 'To my understanding', 'In my view', 'My take on it is', 'As per my perception')
_ENDING_OPTIONS = ('Any other questions?', 'Is there anything else I can help with?')
_NUM_HIGHLIGHTED_SECTIONS = 4
_SECTION_SPLITER = ('Section', 'SECTION')
_NUM_SECTIONS = 5
_NUM_PARAGRAPHS = 5
_POSTSCRIPT_MARKER = ('P.S.', 'P.P.S')
_NUM_KEYWORDS = 2
_KEYWORD_FREQUENCY = 3
_LETTER_FREQUENCY = 10
_ALL_CAPITAL_WORD_FREQUENCY = 20
_NUM_WORDS_LOWER_LIMIT = 100
_NUM_WORDS_UPPER_LIMIT = 500
class Instruction:
def __init__(self, instruction_id):
self.id = instruction_id
def build_description(self, **kwargs):
raise NotImplementedError('`build_description` not implemented.')
def get_instruction_args(self):
raise NotImplementedError('`get_instruction_args` not implemented.')
def get_instruction_args_keys(self):
raise NotImplementedError('`get_instruction_args_keys` not implemented.')
def check_following(self, value):
raise NotImplementedError('`check_following` not implemented.')
class ResponseLanguageChecker(Instruction):
def build_description(self, *, language=None):
self._language = language
if self._language is None:
self._language = random.choice(list(_LANGUAGES.keys()))
self._description_pattern = 'Your ENTIRE response should be in {language} language, no other ' + 'language is allowed.'
return self._description_pattern.format(language=_LANGUAGES[self._language])
def get_instruction_args(self):
return {'language': self._language}
def get_instruction_args_keys(self):
return ['language']
def check_following(self, value):
assert isinstance(value, str)
try:
return langdetect.detect(value) == self._language
except langdetect.LangDetectException as e:
logging.error('Unable to detect language for text %s due to %s', value, e)
return True
class NumberOfSentences(Instruction):
def build_description(self, *, num_sentences=None, relation=None):
self._num_sentences_threshold = num_sentences
if self._num_sentences_threshold is None or self._num_sentences_threshold < 0:
self._num_sentences_threshold = random.randint(1, _MAX_NUM_SENTENCES)