text
stringlengths 0
15.3k
|
---|
text = re.sub('\\[.*?\\]', '', text) |
text = text.replace(' ', ' ') |
return text |
def process_docs(dataset: datasets.Dataset) -> datasets.Dataset: |
def _process_doc(doc): |
choices = [preprocess(doc['Incorrect Answer 1']), preprocess(doc['Incorrect Answer 2']), preprocess(doc['Incorrect Answer 3']), preprocess(doc['Correct Answer'])] |
random.shuffle(choices) |
correct_answer_index = choices.index(preprocess(doc['Correct Answer'])) |
out_doc = {'choice1': choices[0], 'choice2': choices[1], 'choice3': choices[2], 'choice4': choices[3], 'answer': f'({chr(65 + correct_answer_index)})'} |
return out_doc |
return dataset.map(_process_doc) |
# File: lm-evaluation-harness-main/lm_eval/tasks/leaderboard/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) |
if relation is None: |
self._comparison_relation = random.choice(_COMPARISON_RELATION) |
elif relation not in _COMPARISON_RELATION: |
raise ValueError(f'The supported relation for comparison must be in {_COMPARISON_RELATION}, but {relation} is given.') |
else: |
self._comparison_relation = relation |
self._description_pattern = 'Your response should contain {relation} {num_sentences} sentences.' |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.