text
stringlengths 0
15.3k
|
---|
def get_instruction_args_keys(self): |
return ['num_words', 'relation'] |
def check_following(self, value): |
num_words = instructions_util.count_words(value) |
if self._comparison_relation == _COMPARISON_RELATION[0]: |
return num_words < self._num_words |
elif self._comparison_relation == _COMPARISON_RELATION[1]: |
return num_words >= self._num_words |
class JsonFormat(Instruction): |
def build_description(self): |
self._description_pattern = 'Entire output should be wrapped in JSON format. You can use markdown ticks such as ```.' |
return self._description_pattern |
def get_instruction_args(self): |
return None |
def get_instruction_args_keys(self): |
return [] |
def check_following(self, value): |
value = value.strip().removeprefix('```json').removeprefix('```Json').removeprefix('```JSON').removeprefix('```').removesuffix('```').strip() |
try: |
json.loads(value) |
except ValueError: |
return False |
return True |
class ParagraphFirstWordCheck(Instruction): |
def build_description(self, num_paragraphs=None, nth_paragraph=None, first_word=None): |
self._num_paragraphs = num_paragraphs |
if self._num_paragraphs is None or self._num_paragraphs < 0: |
self._num_paragraphs = random.randint(1, _NUM_PARAGRAPHS) |
self._nth_paragraph = nth_paragraph |
if self._nth_paragraph is None or self._nth_paragraph <= 0 or self._nth_paragraph > self._num_paragraphs: |
self._nth_paragraph = random.randint(1, self._num_paragraphs + 1) |
self._first_word = first_word |
if self._first_word is None: |
self._first_word = instructions_util.generate_keywords(num_keywords=1)[0] |
self._first_word = self._first_word.lower() |
self._description_pattern = 'There should be {num_paragraphs} paragraphs. ' + 'Paragraphs and only paragraphs are separated with each other by two ' + "new lines as if it was '\\n\\n' in python. " + 'Paragraph {nth_paragraph} must start with word {first_word}.' |
return self._description_pattern.format(num_paragraphs=self._num_paragraphs, nth_paragraph=self._nth_paragraph, first_word=self._first_word) |
def get_instruction_args(self): |
return {'num_paragraphs': self._num_paragraphs, 'nth_paragraph': self._nth_paragraph, 'first_word': self._first_word} |
def get_instruction_args_keys(self): |
return ['num_paragraphs', 'nth_paragraph', 'first_word'] |
def check_following(self, value): |
paragraphs = re.split('\\n\\n', value) |
num_paragraphs = len(paragraphs) |
for paragraph in paragraphs: |
if not paragraph.strip(): |
num_paragraphs -= 1 |
if self._nth_paragraph <= num_paragraphs: |
paragraph = paragraphs[self._nth_paragraph - 1].strip() |
if not paragraph: |
return False |
else: |
return False |
first_word = '' |
punctuation = {'.', ',', '?', '!', "'", '"'} |
word = paragraph.split()[0].strip() |
word = word.lstrip("'") |
word = word.lstrip('"') |
for letter in word: |
if letter in punctuation: |
break |
first_word += letter.lower() |
return num_paragraphs == self._num_paragraphs and first_word == self._first_word |
class KeySentenceChecker(Instruction): |
def build_description(self, key_sentences=None, num_sentences=None): |
if not key_sentences: |
self._key_sentences = set(['For now, this is fine.']) |
else: |
self._key_sentences = key_sentences |
if not num_sentences: |
self._num_sentences = random.randint(1, len(self._key_sentences)) |
else: |
self._num_sentences = num_sentences |
self._description_pattern = 'Include {num_sentences} of the following sentences {key_sentences}' |
return self._description_pattern.format(num_sentences=self._num_sentences, key_sentences=self._key_sentences) |
def get_instruction_args(self): |
return {'num_sentences': self._num_sentences, 'key_sentences': list(self._key_sentences)} |
def get_instruction_args_keys(self): |
return ['num_sentences', 'key_sentences'] |
def check_following(self, value): |
count = 0 |
sentences = instructions_util.split_into_sentences(value) |
for sentence in self._key_sentences: |
if sentence in 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.