Spaces:
Runtime error
Runtime error
pminervini
commited on
Commit
•
1a7b8b2
1
Parent(s):
a64574f
update
Browse files
src/backend/tasks/ifeval/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# IFEval
|
2 |
+
|
3 |
+
### Paper
|
4 |
+
|
5 |
+
Title: Instruction-Following Evaluation for Large Language Models
|
6 |
+
Abstract: https://arxiv.org/abs/2311.07911
|
7 |
+
|
8 |
+
One core capability of Large Language Models (LLMs) is to follow natural language instructions. However, the evaluation of such abilities is not standardized: Human evaluations are expensive, slow, and not objectively reproducible, while LLM-based auto-evaluation is potentially biased or limited by the ability of the evaluator LLM. To overcome these issues, we introduce Instruction-Following Eval (IFEval) for large language models. IFEval is a straightforward and easy-to-reproduce evaluation benchmark. It focuses on a set of "verifiable instructions" such as "write in more than 400 words" and "mention the keyword of AI at least 3 times". We identified 25 types of those verifiable instructions and constructed around 500 prompts, with each prompt containing one or more verifiable instructions. We show evaluation results of two widely available LLMs on the market. Our code and data can be found at https://github.com/google-research/google-research/tree/master/instruction_following_eval
|
9 |
+
|
10 |
+
Homepage: https://github.com/google-research/google-research/tree/master/instruction_following_eval
|
11 |
+
|
12 |
+
|
13 |
+
### Citation
|
14 |
+
|
15 |
+
```
|
16 |
+
@article{zhou2023instructionfollowing,
|
17 |
+
title={Instruction-Following Evaluation for Large Language Models},
|
18 |
+
author={Jeffrey Zhou and Tianjian Lu and Swaroop Mishra and Siddhartha Brahma and Sujoy Basu and Yi Luan and Denny Zhou and Le Hou},
|
19 |
+
journal={arXiv preprint arXiv:2311.07911},
|
20 |
+
year={2023},
|
21 |
+
}
|
22 |
+
```
|
23 |
+
|
24 |
+
### Groups and Tasks
|
25 |
+
|
26 |
+
#### Groups
|
27 |
+
|
28 |
+
* Not part of a group yet
|
29 |
+
|
30 |
+
#### Tasks
|
31 |
+
|
32 |
+
* `ifeval`
|
33 |
+
|
34 |
+
### Checklist
|
35 |
+
|
36 |
+
For adding novel benchmarks/datasets to the library:
|
37 |
+
* [x] Is the task an existing benchmark in the literature?
|
38 |
+
* [x] Have you referenced the original paper that introduced the task?
|
39 |
+
* [x] If yes, does the original paper provide a reference implementation? If so, have you checked against the reference implementation and documented how to run such a test?
|
40 |
+
|
41 |
+
|
42 |
+
If other tasks on this dataset are already supported:
|
43 |
+
* [ ] Is the "Main" variant of this task clearly denoted?
|
44 |
+
* [ ] Have you provided a short sentence in a README on what each new variant adds / evaluates?
|
45 |
+
* [ ] Have you noted which, if any, published evaluation setups are matched by this variant?
|
src/backend/tasks/ifeval/ifeval.yaml
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
task: ifeval
|
2 |
+
dataset_path: wis-k/instruction-following-eval
|
3 |
+
dataset_name: null
|
4 |
+
output_type: generate_until
|
5 |
+
test_split: train
|
6 |
+
num_fewshot: 0
|
7 |
+
doc_to_text: prompt
|
8 |
+
doc_to_target: 0
|
9 |
+
generation_kwargs:
|
10 |
+
until: []
|
11 |
+
do_sample: false
|
12 |
+
temperature: 0.0
|
13 |
+
max_gen_toks: 1024
|
14 |
+
process_results: !function utils.process_results
|
15 |
+
metric_list:
|
16 |
+
- metric: prompt_level_strict_acc
|
17 |
+
aggregation: mean
|
18 |
+
higher_is_better: true
|
19 |
+
- metric: inst_level_strict_acc
|
20 |
+
aggregation: !function utils.agg_inst_level_acc
|
21 |
+
higher_is_better: true
|
22 |
+
- metric: prompt_level_loose_acc
|
23 |
+
aggregation: mean
|
24 |
+
higher_is_better: true
|
25 |
+
- metric: inst_level_loose_acc
|
26 |
+
aggregation: !function utils.agg_inst_level_acc
|
27 |
+
higher_is_better: true
|
28 |
+
metadata:
|
29 |
+
- version: 1.0
|
src/backend/tasks/ifeval/instructions.py
ADDED
@@ -0,0 +1,1611 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2023 The Google Research Authors.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
|
16 |
+
"""Library of instructions."""
|
17 |
+
import collections
|
18 |
+
import json
|
19 |
+
import logging
|
20 |
+
import random
|
21 |
+
import re
|
22 |
+
import string
|
23 |
+
from typing import Dict, Optional, Sequence, Union
|
24 |
+
|
25 |
+
import langdetect
|
26 |
+
|
27 |
+
from lm_eval.tasks.ifeval import instructions_util
|
28 |
+
|
29 |
+
logger = logging.getLogger(__name__)
|
30 |
+
|
31 |
+
_InstructionArgsDtype = Optional[Dict[str, Union[int, str, Sequence[str]]]]
|
32 |
+
|
33 |
+
_LANGUAGES = instructions_util.LANGUAGE_CODES
|
34 |
+
|
35 |
+
# The relational operation for comparison.
|
36 |
+
_COMPARISON_RELATION = ("less than", "at least")
|
37 |
+
|
38 |
+
# The maximum number of sentences.
|
39 |
+
_MAX_NUM_SENTENCES = 20
|
40 |
+
|
41 |
+
# The number of placeholders.
|
42 |
+
_NUM_PLACEHOLDERS = 4
|
43 |
+
|
44 |
+
# The number of bullet lists.
|
45 |
+
_NUM_BULLETS = 5
|
46 |
+
|
47 |
+
# The options of constrained response.
|
48 |
+
_CONSTRAINED_RESPONSE_OPTIONS = (
|
49 |
+
"My answer is yes.",
|
50 |
+
"My answer is no.",
|
51 |
+
"My answer is maybe.",
|
52 |
+
)
|
53 |
+
|
54 |
+
# The options of starter keywords.
|
55 |
+
_STARTER_OPTIONS = (
|
56 |
+
"I would say",
|
57 |
+
"My answer is",
|
58 |
+
"I believe",
|
59 |
+
"In my opinion",
|
60 |
+
"I think",
|
61 |
+
"I reckon",
|
62 |
+
"I feel",
|
63 |
+
"From my perspective",
|
64 |
+
"As I see it",
|
65 |
+
"According to me",
|
66 |
+
"As far as I'm concerned",
|
67 |
+
"To my understanding",
|
68 |
+
"In my view",
|
69 |
+
"My take on it is",
|
70 |
+
"As per my perception",
|
71 |
+
)
|
72 |
+
|
73 |
+
# The options of ending keywords.
|
74 |
+
# TODO(jeffreyzhou) add more ending options
|
75 |
+
_ENDING_OPTIONS = ("Any other questions?", "Is there anything else I can help with?")
|
76 |
+
|
77 |
+
# The number of highlighted sections.
|
78 |
+
_NUM_HIGHLIGHTED_SECTIONS = 4
|
79 |
+
|
80 |
+
# The section spliter.
|
81 |
+
_SECTION_SPLITER = ("Section", "SECTION")
|
82 |
+
|
83 |
+
# The number of sections.
|
84 |
+
_NUM_SECTIONS = 5
|
85 |
+
|
86 |
+
# The number of paragraphs.
|
87 |
+
_NUM_PARAGRAPHS = 5
|
88 |
+
|
89 |
+
# The postscript marker.
|
90 |
+
_POSTSCRIPT_MARKER = ("P.S.", "P.P.S")
|
91 |
+
|
92 |
+
# The number of keywords.
|
93 |
+
_NUM_KEYWORDS = 2
|
94 |
+
|
95 |
+
# The occurrences of a single keyword.
|
96 |
+
_KEYWORD_FREQUENCY = 3
|
97 |
+
|
98 |
+
# The occurrences of a single letter.
|
99 |
+
_LETTER_FREQUENCY = 10
|
100 |
+
|
101 |
+
# The occurrences of words with all capital letters.
|
102 |
+
_ALL_CAPITAL_WORD_FREQUENCY = 20
|
103 |
+
|
104 |
+
# The number of words in the response.
|
105 |
+
_NUM_WORDS_LOWER_LIMIT = 100
|
106 |
+
_NUM_WORDS_UPPER_LIMIT = 500
|
107 |
+
|
108 |
+
|
109 |
+
class Instruction:
|
110 |
+
"""An instruction template."""
|
111 |
+
|
112 |
+
def __init__(self, instruction_id):
|
113 |
+
self.id = instruction_id
|
114 |
+
|
115 |
+
def build_description(self, **kwargs):
|
116 |
+
raise NotImplementedError("`build_description` not implemented.")
|
117 |
+
|
118 |
+
def get_instruction_args(self):
|
119 |
+
raise NotImplementedError("`get_instruction_args` not implemented.")
|
120 |
+
|
121 |
+
def get_instruction_args_keys(self):
|
122 |
+
raise NotImplementedError("`get_instruction_args_keys` not implemented.")
|
123 |
+
|
124 |
+
def check_following(self, value):
|
125 |
+
raise NotImplementedError("`check_following` not implemented.")
|
126 |
+
|
127 |
+
|
128 |
+
class ResponseLanguageChecker(Instruction):
|
129 |
+
"""Check the language of the entire response."""
|
130 |
+
|
131 |
+
def build_description(self, *, language=None):
|
132 |
+
"""Build the instruction description.
|
133 |
+
|
134 |
+
Args:
|
135 |
+
language: A string representing the expected language of the response. The
|
136 |
+
language has to comply to the 97 types defined in
|
137 |
+
`langid.py` (https://pypi.org/project/langid/1.1.5/), which follows
|
138 |
+
ISO 639-1 codes (https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes);
|
139 |
+
for example, `en` for English, `zh` for Chinese, `fr` for French.
|
140 |
+
|
141 |
+
Returns:
|
142 |
+
A string representing the instruction description.
|
143 |
+
"""
|
144 |
+
self._language = language
|
145 |
+
if self._language is None:
|
146 |
+
self._language = random.choice(list(_LANGUAGES.keys()))
|
147 |
+
# TODO(tianjianlu): opens the description generation to more choices.
|
148 |
+
self._description_pattern = (
|
149 |
+
"Your ENTIRE response should be in {language} language, no other "
|
150 |
+
+ "language is allowed."
|
151 |
+
)
|
152 |
+
return self._description_pattern.format(language=_LANGUAGES[self._language])
|
153 |
+
|
154 |
+
def get_instruction_args(self):
|
155 |
+
"""Returns the keyward args of `build_description`."""
|
156 |
+
return {"language": self._language}
|
157 |
+
|
158 |
+
def get_instruction_args_keys(self):
|
159 |
+
"""Returns the args keys of `build_description`."""
|
160 |
+
return ["language"]
|
161 |
+
|
162 |
+
def check_following(self, value):
|
163 |
+
"""Check if the language of the entire response follows the instruction.
|
164 |
+
|
165 |
+
Args:
|
166 |
+
value: A string representing the response.
|
167 |
+
|
168 |
+
Returns:
|
169 |
+
True if the language of `value` follows instruction; otherwise False.
|
170 |
+
"""
|
171 |
+
assert isinstance(value, str)
|
172 |
+
|
173 |
+
try:
|
174 |
+
return langdetect.detect(value) == self._language
|
175 |
+
except langdetect.LangDetectException as e:
|
176 |
+
# Count as instruction is followed.
|
177 |
+
logging.error(
|
178 |
+
"Unable to detect language for text %s due to %s", value, e
|
179 |
+
) # refex: disable=pytotw.037
|
180 |
+
return True
|
181 |
+
|
182 |
+
|
183 |
+
class NumberOfSentences(Instruction):
|
184 |
+
"""Check the number of sentences."""
|
185 |
+
|
186 |
+
def build_description(self, *, num_sentences=None, relation=None):
|
187 |
+
"""Build the instruction description.
|
188 |
+
|
189 |
+
Args:
|
190 |
+
num_sentences: An integer specifying the number of sentences as a
|
191 |
+
threshold.
|
192 |
+
relation: A string in (`less than`, `at least`), defining the relational
|
193 |
+
operator for comparison.
|
194 |
+
Two relational comparisons are supported for now:
|
195 |
+
if 'less than', the actual number of sentences < the threshold;
|
196 |
+
if 'at least', the actual number of sentences >= the threshold.
|
197 |
+
|
198 |
+
Returns:
|
199 |
+
A string representing the instruction description.
|
200 |
+
"""
|
201 |
+
# The number of sentences as a threshold for comparison.
|
202 |
+
self._num_sentences_threshold = num_sentences
|
203 |
+
if self._num_sentences_threshold is None or self._num_sentences_threshold < 0:
|
204 |
+
self._num_sentences_threshold = random.randint(1, _MAX_NUM_SENTENCES)
|
205 |
+
|
206 |
+
if relation is None:
|
207 |
+
self._comparison_relation = random.choice(_COMPARISON_RELATION)
|
208 |
+
elif relation not in _COMPARISON_RELATION:
|
209 |
+
raise ValueError(
|
210 |
+
"The supported relation for comparison must be in "
|
211 |
+
f"{_COMPARISON_RELATION}, but {relation} is given."
|
212 |
+
)
|
213 |
+
else:
|
214 |
+
self._comparison_relation = relation
|
215 |
+
|
216 |
+
self._description_pattern = (
|
217 |
+
"Your response should contain {relation} {num_sentences} sentences."
|
218 |
+
)
|
219 |
+
return self._description_pattern.format(
|
220 |
+
relation=self._comparison_relation,
|
221 |
+
num_sentences=self._num_sentences_threshold,
|
222 |
+
)
|
223 |
+
|
224 |
+
def get_instruction_args(self):
|
225 |
+
"""Returns the keyward args of `build_description`."""
|
226 |
+
return {
|
227 |
+
"num_sentences": self._num_sentences_threshold,
|
228 |
+
"relation": self._comparison_relation,
|
229 |
+
}
|
230 |
+
|
231 |
+
def get_instruction_args_keys(self):
|
232 |
+
"""Returns the args keys of `build_description`."""
|
233 |
+
return ["num_sentences", "relation"]
|
234 |
+
|
235 |
+
def check_following(self, value):
|
236 |
+
"""Check if the number of sentences follows the instruction.
|
237 |
+
|
238 |
+
Args:
|
239 |
+
value: A string representing the response.
|
240 |
+
|
241 |
+
Returns:
|
242 |
+
True if the response follows the instruction.
|
243 |
+
|
244 |
+
Raise:
|
245 |
+
ValueError if the string in `instruction_args` is not in
|
246 |
+
[`less_than`, `at_least`].
|
247 |
+
"""
|
248 |
+
num_sentences = instructions_util.count_sentences(value)
|
249 |
+
if self._comparison_relation == _COMPARISON_RELATION[0]:
|
250 |
+
return num_sentences < self._num_sentences_threshold
|
251 |
+
elif self._comparison_relation == _COMPARISON_RELATION[1]:
|
252 |
+
return num_sentences >= self._num_sentences_threshold
|
253 |
+
|
254 |
+
|
255 |
+
class PlaceholderChecker(Instruction):
|
256 |
+
"""Check the placeholders in template writing."""
|
257 |
+
|
258 |
+
def build_description(self, *, num_placeholders=None):
|
259 |
+
"""Build the instruction description.
|
260 |
+
|
261 |
+
Args:
|
262 |
+
num_placeholders: An integer denoting the minimum number of
|
263 |
+
placeholders required in the response.
|
264 |
+
|
265 |
+
Returns:
|
266 |
+
A string representing the instruction description.
|
267 |
+
"""
|
268 |
+
self._num_placeholders = num_placeholders
|
269 |
+
if self._num_placeholders is None or self._num_placeholders < 0:
|
270 |
+
self._num_placeholders = random.randint(1, _NUM_PLACEHOLDERS)
|
271 |
+
self._description_pattern = (
|
272 |
+
"The response must contain at least {num_placeholders} placeholders "
|
273 |
+
+ "represented by square brackets, such as [address]."
|
274 |
+
)
|
275 |
+
return self._description_pattern.format(num_placeholders=self._num_placeholders)
|
276 |
+
|
277 |
+
def get_instruction_args(self):
|
278 |
+
"""Returns the keyward args of `build_description`."""
|
279 |
+
return {"num_placeholders": self._num_placeholders}
|
280 |
+
|
281 |
+
def get_instruction_args_keys(self):
|
282 |
+
"""Returns the args keys of `build_description`."""
|
283 |
+
return ["num_placeholders"]
|
284 |
+
|
285 |
+
def check_following(self, value):
|
286 |
+
"""Check if the number of placeholders follows the instruction.
|
287 |
+
|
288 |
+
Args:
|
289 |
+
value: A string representing the response.
|
290 |
+
|
291 |
+
Returns:
|
292 |
+
True if the actual number of placeholders in the response is greater than
|
293 |
+
or equal to `num_placeholders`; otherwise, False.
|
294 |
+
"""
|
295 |
+
placeholders = re.findall(r"\[.*?\]", value)
|
296 |
+
num_placeholders = len(placeholders)
|
297 |
+
return num_placeholders >= self._num_placeholders
|
298 |
+
|
299 |
+
|
300 |
+
class BulletListChecker(Instruction):
|
301 |
+
"""Checks the bullet list in the prompt."""
|
302 |
+
|
303 |
+
def build_description(self, *, num_bullets=None):
|
304 |
+
"""Build the instruction description.
|
305 |
+
|
306 |
+
Args:
|
307 |
+
num_bullets: An integer specifying the exact number of bullet lists
|
308 |
+
that is required to appear in the response.
|
309 |
+
|
310 |
+
Returns:
|
311 |
+
A string representing the instruction description.
|
312 |
+
"""
|
313 |
+
self._num_bullets = num_bullets
|
314 |
+
if self._num_bullets is None or self._num_bullets < 0:
|
315 |
+
self._num_bullets = random.randint(1, _NUM_BULLETS)
|
316 |
+
self._description_pattern = (
|
317 |
+
"Your answer must contain exactly {num_bullets} bullet points. "
|
318 |
+
+ "Use the markdown bullet points such as:\n"
|
319 |
+
+ "* This is point 1. \n"
|
320 |
+
+ "* This is point 2"
|
321 |
+
)
|
322 |
+
return self._description_pattern.format(num_bullets=self._num_bullets)
|
323 |
+
|
324 |
+
def get_instruction_args(self):
|
325 |
+
"""Returns the keyward args of `build_description`."""
|
326 |
+
return {"num_bullets": self._num_bullets}
|
327 |
+
|
328 |
+
def get_instruction_args_keys(self):
|
329 |
+
"""Returns the args keys of `build_description`."""
|
330 |
+
return ["num_bullets"]
|
331 |
+
|
332 |
+
def check_following(self, value):
|
333 |
+
r"""Check if the number of bullet lists meets the requirement.
|
334 |
+
|
335 |
+
Args:
|
336 |
+
value: A string representing the response. The response is expected to
|
337 |
+
contain some bullet lists that start with `\*`.
|
338 |
+
|
339 |
+
Returns:
|
340 |
+
True if the actual number of bullet lists in the response meets the
|
341 |
+
requirement.
|
342 |
+
"""
|
343 |
+
bullet_lists = re.findall(r"^\s*\*[^\*].*$", value, flags=re.MULTILINE)
|
344 |
+
bullet_lists_2 = re.findall(r"^\s*-.*$", value, flags=re.MULTILINE)
|
345 |
+
num_bullet_lists = len(bullet_lists) + len(bullet_lists_2)
|
346 |
+
return num_bullet_lists == self._num_bullets
|
347 |
+
|
348 |
+
|
349 |
+
class ConstrainedResponseChecker(Instruction):
|
350 |
+
"""Checks the constrained response."""
|
351 |
+
|
352 |
+
def build_description(self):
|
353 |
+
"""Build the instruction description."""
|
354 |
+
# A sequence of string(s) representing the options of the expected response.
|
355 |
+
self._constrained_responses = _CONSTRAINED_RESPONSE_OPTIONS
|
356 |
+
self._description_pattern = (
|
357 |
+
"Answer with one of the following options: {response_options}"
|
358 |
+
)
|
359 |
+
return self._description_pattern.format(
|
360 |
+
response_options=self._constrained_responses
|
361 |
+
)
|
362 |
+
|
363 |
+
def get_instruction_args(self):
|
364 |
+
"""Returns the keyward args of `build_description`."""
|
365 |
+
return None
|
366 |
+
|
367 |
+
def get_instruction_args_keys(self):
|
368 |
+
"""Returns the args keys of `build_description`."""
|
369 |
+
return []
|
370 |
+
|
371 |
+
def check_following(self, value):
|
372 |
+
"""Checks if the response matches the constrained options.
|
373 |
+
|
374 |
+
Args:
|
375 |
+
value: A string representing the response.
|
376 |
+
|
377 |
+
Returns:
|
378 |
+
True if the actual response contains one of the options in the constrained
|
379 |
+
responses; otherwise False.
|
380 |
+
"""
|
381 |
+
value = value.strip()
|
382 |
+
for constrained_response in self._constrained_responses:
|
383 |
+
if constrained_response in value:
|
384 |
+
return True
|
385 |
+
return False
|
386 |
+
|
387 |
+
|
388 |
+
class ConstrainedStartChecker(Instruction):
|
389 |
+
"""Checks the response start."""
|
390 |
+
|
391 |
+
def build_description(self, *, starter=None):
|
392 |
+
"""Build the instruction description.
|
393 |
+
|
394 |
+
Args:
|
395 |
+
starter: A string representing the keyward that the response should start
|
396 |
+
with.
|
397 |
+
|
398 |
+
Returns:
|
399 |
+
A string representing the instruction description.
|
400 |
+
"""
|
401 |
+
self._starter = starter.strip() if isinstance(starter, str) else starter
|
402 |
+
if self._starter is None:
|
403 |
+
self._starter = random.choice(_STARTER_OPTIONS)
|
404 |
+
self._description_pattern = (
|
405 |
+
"During the conversation, when it is your turn, "
|
406 |
+
+ "please always start with {starter}"
|
407 |
+
)
|
408 |
+
return self._description_pattern.format(starter=self._starter)
|
409 |
+
|
410 |
+
def get_instruction_args(self):
|
411 |
+
"""Returns the keyward args of `build_description`."""
|
412 |
+
return {"starter": self._starter}
|
413 |
+
|
414 |
+
def get_instruction_args_keys(self):
|
415 |
+
"""Returns the args keys of `build_description`."""
|
416 |
+
return ["starter"]
|
417 |
+
|
418 |
+
def check_following(self, value):
|
419 |
+
"""Checks if the response starts with the constrained keyword or phrase.
|
420 |
+
|
421 |
+
Args:
|
422 |
+
value: A string representing the response.
|
423 |
+
|
424 |
+
Returns:
|
425 |
+
True if the response starts with the given phrase or keyword that is
|
426 |
+
contained in `instruction_args`; otherwise, False.
|
427 |
+
"""
|
428 |
+
response_pattern = r"^\s*" + self._starter + r".*$"
|
429 |
+
response_with_constrained_start = re.search(
|
430 |
+
response_pattern, value, flags=re.MULTILINE
|
431 |
+
)
|
432 |
+
return True if response_with_constrained_start else False
|
433 |
+
|
434 |
+
|
435 |
+
class HighlightSectionChecker(Instruction):
|
436 |
+
"""Checks the highlighted section."""
|
437 |
+
|
438 |
+
def build_description(self, *, num_highlights=None):
|
439 |
+
"""Build the instruction description.
|
440 |
+
|
441 |
+
Args:
|
442 |
+
num_highlights: An integer specifying the minimum number of highlighted
|
443 |
+
sections.
|
444 |
+
|
445 |
+
Returns:
|
446 |
+
A string representing the instruction description.
|
447 |
+
"""
|
448 |
+
self._num_highlights = num_highlights
|
449 |
+
if self._num_highlights is None or self._num_highlights < 0:
|
450 |
+
self._num_highlights = random.randint(1, _NUM_HIGHLIGHTED_SECTIONS)
|
451 |
+
|
452 |
+
self._description_pattern = (
|
453 |
+
"Highlight at least {num_highlights} sections in your answer with "
|
454 |
+
+ "markdown, i.e. *highlighted section*."
|
455 |
+
)
|
456 |
+
|
457 |
+
return self._description_pattern.format(num_highlights=self._num_highlights)
|
458 |
+
|
459 |
+
def get_instruction_args(self):
|
460 |
+
"""Returns the keyward args of `build_description`."""
|
461 |
+
return {"num_highlights": self._num_highlights}
|
462 |
+
|
463 |
+
def get_instruction_args_keys(self):
|
464 |
+
"""Returns the args keys of `build_description`."""
|
465 |
+
return ["num_highlights"]
|
466 |
+
|
467 |
+
def check_following(self, value):
|
468 |
+
"""Checks if the number of highlighted sections meets the requirement.
|
469 |
+
|
470 |
+
Args:
|
471 |
+
value: a string repesenting the response. The response is expected to
|
472 |
+
contain highlighted sections in the format of *highlighted*.
|
473 |
+
|
474 |
+
Returns:
|
475 |
+
True if the actual number of highlighted sections in the format of
|
476 |
+
*highlighed sections* meets the minimum requirement; otherwise False.
|
477 |
+
"""
|
478 |
+
num_highlights = 0
|
479 |
+
highlights = re.findall(r"\*[^\n\*]*\*", value)
|
480 |
+
double_highlights = re.findall(r"\*\*[^\n\*]*\*\*", value)
|
481 |
+
for highlight in highlights:
|
482 |
+
if highlight.strip("*").strip():
|
483 |
+
num_highlights += 1
|
484 |
+
for highlight in double_highlights:
|
485 |
+
if highlight.removeprefix("**").removesuffix("**").strip():
|
486 |
+
num_highlights += 1
|
487 |
+
|
488 |
+
return num_highlights >= self._num_highlights
|
489 |
+
|
490 |
+
|
491 |
+
class SectionChecker(Instruction):
|
492 |
+
"""Checks the sections."""
|
493 |
+
|
494 |
+
def build_description(self, *, section_spliter=None, num_sections=None):
|
495 |
+
"""Build the instruction description.
|
496 |
+
|
497 |
+
Args:
|
498 |
+
section_spliter: A string represents the section spliter keyword that
|
499 |
+
marks a new section, i.e., `Section` or `SECTION`.
|
500 |
+
num_sections: An integer specifying the number of sections.
|
501 |
+
|
502 |
+
Returns:
|
503 |
+
A string representing the instruction description.
|
504 |
+
"""
|
505 |
+
self._section_spliter = (
|
506 |
+
section_spliter.strip()
|
507 |
+
if isinstance(section_spliter, str)
|
508 |
+
else section_spliter
|
509 |
+
)
|
510 |
+
if self._section_spliter is None:
|
511 |
+
self._section_spliter = random.choice(_SECTION_SPLITER)
|
512 |
+
|
513 |
+
self._num_sections = num_sections
|
514 |
+
if self._num_sections is None or self._num_sections < 0:
|
515 |
+
self._num_sections = random.randint(1, _NUM_SECTIONS)
|
516 |
+
|
517 |
+
self._description_pattern = (
|
518 |
+
"Your response must have {num_sections} sections. Mark the beginning "
|
519 |
+
+ "of each section with {section_spliter} X, such as:\n"
|
520 |
+
+ "{section_spliter} 1\n"
|
521 |
+
+ "[content of section 1]\n"
|
522 |
+
+ "{section_spliter} 2\n"
|
523 |
+
+ "[content of section 2]"
|
524 |
+
)
|
525 |
+
|
526 |
+
return self._description_pattern.format(
|
527 |
+
num_sections=self._num_sections, section_spliter=self._section_spliter
|
528 |
+
)
|
529 |
+
|
530 |
+
def get_instruction_args(self):
|
531 |
+
"""Returns the keyward args of `build_description`."""
|
532 |
+
return {
|
533 |
+
"section_spliter": self._section_spliter,
|
534 |
+
"num_sections": self._num_sections,
|
535 |
+
}
|
536 |
+
|
537 |
+
def get_instruction_args_keys(self):
|
538 |
+
"""Returns the args keys of `build_description`."""
|
539 |
+
return ["section_spliter", "num_sections"]
|
540 |
+
|
541 |
+
def check_following(self, value):
|
542 |
+
"""Checks the response contains multiple sections.
|
543 |
+
|
544 |
+
Args:
|
545 |
+
value: A string representing the response. The response is expected
|
546 |
+
to contain multiple sections (number of sections is greater than 1).
|
547 |
+
A new section starts with `Section 1`, where the number denotes the
|
548 |
+
section index.
|
549 |
+
|
550 |
+
Returns:
|
551 |
+
True if the number of sections in the response is greater than or equal to
|
552 |
+
the minimum number of sections; otherwise, False.
|
553 |
+
"""
|
554 |
+
section_splitter_patten = r"\s?" + self._section_spliter + r"\s?\d+\s?"
|
555 |
+
sections = re.split(section_splitter_patten, value)
|
556 |
+
num_sections = len(sections) - 1
|
557 |
+
return num_sections >= self._num_sections
|
558 |
+
|
559 |
+
|
560 |
+
class ParagraphChecker(Instruction):
|
561 |
+
"""Checks the paragraphs."""
|
562 |
+
|
563 |
+
def build_description(self, *, num_paragraphs=None):
|
564 |
+
"""Build the instruction description.
|
565 |
+
|
566 |
+
Args:
|
567 |
+
num_paragraphs: An integer specifying the number of paragraphs.
|
568 |
+
|
569 |
+
Returns:
|
570 |
+
A string representing the instruction description.
|
571 |
+
"""
|
572 |
+
self._num_paragraphs = num_paragraphs
|
573 |
+
if self._num_paragraphs is None or self._num_paragraphs < 0:
|
574 |
+
self._num_paragraphs = random.randint(1, _NUM_PARAGRAPHS)
|
575 |
+
|
576 |
+
self._description_pattern = (
|
577 |
+
"There should be {num_paragraphs} paragraphs. "
|
578 |
+
+ "Paragraphs are separated with the markdown divider: ***"
|
579 |
+
)
|
580 |
+
|
581 |
+
return self._description_pattern.format(num_paragraphs=self._num_paragraphs)
|
582 |
+
|
583 |
+
def get_instruction_args(self):
|
584 |
+
"""Returns the keyward args of `build_description`."""
|
585 |
+
return {"num_paragraphs": self._num_paragraphs}
|
586 |
+
|
587 |
+
def get_instruction_args_keys(self):
|
588 |
+
"""Returns the args keys of `build_description`."""
|
589 |
+
return ["num_paragraphs"]
|
590 |
+
|
591 |
+
def check_following(self, value):
|
592 |
+
"""Checks the response contains required number of paragraphs.
|
593 |
+
|
594 |
+
Args:
|
595 |
+
value: A string representing the response. The response may contain
|
596 |
+
paragraphs that are separated by the markdown divider: `***`.
|
597 |
+
|
598 |
+
Returns:
|
599 |
+
True if the actual number of paragraphs is the same as required;
|
600 |
+
otherwise, False.
|
601 |
+
"""
|
602 |
+
paragraphs = re.split(r"\s?\*\*\*\s?", value)
|
603 |
+
num_paragraphs = len(paragraphs)
|
604 |
+
|
605 |
+
for index, paragraph in enumerate(paragraphs):
|
606 |
+
if not paragraph.strip():
|
607 |
+
if index == 0 or index == len(paragraphs) - 1:
|
608 |
+
num_paragraphs -= 1
|
609 |
+
else:
|
610 |
+
return False
|
611 |
+
|
612 |
+
return num_paragraphs == self._num_paragraphs
|
613 |
+
|
614 |
+
|
615 |
+
class PostscriptChecker(Instruction):
|
616 |
+
"""Checks the postscript."""
|
617 |
+
|
618 |
+
def build_description(self, *, postscript_marker=None):
|
619 |
+
"""Build the instruction description.
|
620 |
+
|
621 |
+
Args:
|
622 |
+
postscript_marker: A string containing the keyword that marks the start
|
623 |
+
of the postscript section.
|
624 |
+
|
625 |
+
Returns:
|
626 |
+
A string representing the instruction description.
|
627 |
+
"""
|
628 |
+
self._postscript_marker = (
|
629 |
+
postscript_marker.strip()
|
630 |
+
if isinstance(postscript_marker, str)
|
631 |
+
else postscript_marker
|
632 |
+
)
|
633 |
+
if self._postscript_marker is None:
|
634 |
+
self._postscript_marker = random.choice(_POSTSCRIPT_MARKER)
|
635 |
+
|
636 |
+
self._description_pattern = (
|
637 |
+
"At the end of your response, please explicitly add a postscript "
|
638 |
+
+ "starting with {postscript}"
|
639 |
+
)
|
640 |
+
|
641 |
+
return self._description_pattern.format(postscript=self._postscript_marker)
|
642 |
+
|
643 |
+
def get_instruction_args(self):
|
644 |
+
"""Returns the keyward args of `build_description`."""
|
645 |
+
return {"postscript_marker": self._postscript_marker}
|
646 |
+
|
647 |
+
def get_instruction_args_keys(self):
|
648 |
+
"""Returns the args keys of `build_description`."""
|
649 |
+
return ["postscript_marker"]
|
650 |
+
|
651 |
+
def check_following(self, value):
|
652 |
+
"""Checks if the response follows the postscript format.
|
653 |
+
|
654 |
+
Args:
|
655 |
+
value: a string representing the response. The response is expected to
|
656 |
+
contain a postscript section.
|
657 |
+
|
658 |
+
Returns:
|
659 |
+
True if the response contains a postscript section starting with
|
660 |
+
the keyword containing in the `instruction_args`; otherwise False.
|
661 |
+
"""
|
662 |
+
value = value.lower()
|
663 |
+
if self._postscript_marker == "P.P.S":
|
664 |
+
postscript_pattern = r"\s*p\.\s?p\.\s?s.*$"
|
665 |
+
elif self._postscript_marker == "P.S.":
|
666 |
+
postscript_pattern = r"\s*p\.\s?s\..*$"
|
667 |
+
else:
|
668 |
+
postscript_pattern = r"\s*" + self._postscript_marker.lower() + r".*$"
|
669 |
+
postscript = re.findall(postscript_pattern, value, flags=re.MULTILINE)
|
670 |
+
return True if postscript else False
|
671 |
+
|
672 |
+
|
673 |
+
class RephraseChecker(Instruction):
|
674 |
+
"""Checks the repharse."""
|
675 |
+
|
676 |
+
def build_description(self, *, original_message):
|
677 |
+
"""Build the instruction description.
|
678 |
+
|
679 |
+
Args:
|
680 |
+
original_message: A string representing the original message. The
|
681 |
+
rephrased response should only change its words/sentences in between
|
682 |
+
its two asterisks, for example, *change me*. Both original and rephrased
|
683 |
+
messages should contain the changes in the form of *change me*.
|
684 |
+
|
685 |
+
Returns:
|
686 |
+
A string representing the instruction description.
|
687 |
+
"""
|
688 |
+
if not self.is_change(original_message):
|
689 |
+
raise ValueError(
|
690 |
+
f"Message {original_message} does not contain changes "
|
691 |
+
"in the form of *change me*."
|
692 |
+
)
|
693 |
+
|
694 |
+
self._reference_without_change = original_message
|
695 |
+
self._description = (
|
696 |
+
"Rephrasing: Your rephrased response should only"
|
697 |
+
+ "change the words/sentences in between two asterisks"
|
698 |
+
+ "such as *change me*."
|
699 |
+
)
|
700 |
+
return self._description
|
701 |
+
|
702 |
+
def get_instruction_args(self):
|
703 |
+
"""Returns the keyward args of `build_description`."""
|
704 |
+
return {"original_message": self._reference_without_change}
|
705 |
+
|
706 |
+
def get_instruction_args_keys(self):
|
707 |
+
"""Returns the args keys of `build_description`."""
|
708 |
+
return ["original_message"]
|
709 |
+
|
710 |
+
def check_following(self, value):
|
711 |
+
r"""Checks if the rephrasing follows the instruction.
|
712 |
+
|
713 |
+
Args:
|
714 |
+
value: A string representing the response, which is expected to rephras
|
715 |
+
the string of `instruction_args`.
|
716 |
+
|
717 |
+
Returns:
|
718 |
+
True if `value` and `instruction_args` only differ by the words/sentences
|
719 |
+
in between two asterisks such as *change me*; otherwise, False.
|
720 |
+
"""
|
721 |
+
|
722 |
+
if not self.is_change(value):
|
723 |
+
raise ValueError(
|
724 |
+
f"value {value} does not contain " "changes in the form of *change me*."
|
725 |
+
)
|
726 |
+
|
727 |
+
response_without_changes = self.strip_changes(value)
|
728 |
+
reference_without_changes = self.strip_changes(self._reference_without_change)
|
729 |
+
|
730 |
+
return response_without_changes == reference_without_changes
|
731 |
+
|
732 |
+
def is_change(self, response):
|
733 |
+
"""Check if there is change in the response in the form of *change me*."""
|
734 |
+
return re.search(r"\*.*\*", response)
|
735 |
+
|
736 |
+
def strip_changes(self, response):
|
737 |
+
"""Strips off the changes."""
|
738 |
+
return re.sub(r"\*.*\*", "", response)
|
739 |
+
|
740 |
+
|
741 |
+
class KeywordChecker(Instruction):
|
742 |
+
"""Check the exisitence of certain keywords."""
|
743 |
+
|
744 |
+
def build_description(self, *, keywords=None):
|
745 |
+
"""Build the instruction description.
|
746 |
+
|
747 |
+
Args:
|
748 |
+
keywords: A sequence of strings representing the keywords that are
|
749 |
+
expected in the response.
|
750 |
+
|
751 |
+
Returns:
|
752 |
+
A string representing the instruction description.
|
753 |
+
"""
|
754 |
+
|
755 |
+
if not keywords:
|
756 |
+
self._keywords = instructions_util.generate_keywords(
|
757 |
+
num_keywords=_NUM_KEYWORDS
|
758 |
+
)
|
759 |
+
else:
|
760 |
+
self._keywords = keywords
|
761 |
+
self._keywords = sorted(self._keywords)
|
762 |
+
|
763 |
+
self._description_pattern = "Include keywords {keywords} in the response."
|
764 |
+
|
765 |
+
return self._description_pattern.format(keywords=self._keywords)
|
766 |
+
|
767 |
+
def get_instruction_args(self):
|
768 |
+
"""Returns the keyward args of `build_description`."""
|
769 |
+
return {"keywords": self._keywords}
|
770 |
+
|
771 |
+
def get_instruction_args_keys(self):
|
772 |
+
"""Returns the args keys of `build_description`."""
|
773 |
+
return ["keywords"]
|
774 |
+
|
775 |
+
def check_following(self, value):
|
776 |
+
"""Check if the response contain the expected keywords."""
|
777 |
+
for keyword in self._keywords:
|
778 |
+
if not re.search(keyword, value, flags=re.IGNORECASE):
|
779 |
+
return False
|
780 |
+
return True
|
781 |
+
|
782 |
+
|
783 |
+
class KeywordFrequencyChecker(Instruction):
|
784 |
+
"""Check the keyword frequency."""
|
785 |
+
|
786 |
+
def build_description(self, *, keyword=None, frequency=None, relation=None):
|
787 |
+
"""Build the instruction description.
|
788 |
+
|
789 |
+
Args:
|
790 |
+
keyword: A string representing a keyword that is expected in the response.
|
791 |
+
frequency: An integer specifying the number of times `keyword` is expected
|
792 |
+
to appear in the response.
|
793 |
+
relation: A string in (`less than`, `at least`), defining the relational
|
794 |
+
operator for comparison.
|
795 |
+
Two relational comparisons are supported for now:
|
796 |
+
if 'less than', the actual number of occurrences < frequency;
|
797 |
+
if 'at least', the actual number of occurrences >= frequency.
|
798 |
+
|
799 |
+
Returns:
|
800 |
+
A string representing the instruction description.
|
801 |
+
"""
|
802 |
+
if not keyword:
|
803 |
+
self._keyword = instructions_util.generate_keywords(num_keywords=1)[0]
|
804 |
+
else:
|
805 |
+
self._keyword = keyword.strip()
|
806 |
+
|
807 |
+
self._frequency = frequency
|
808 |
+
if self._frequency is None or self._frequency < 0:
|
809 |
+
self._frequency = random.randint(1, _KEYWORD_FREQUENCY)
|
810 |
+
|
811 |
+
if relation is None:
|
812 |
+
self._comparison_relation = random.choice(_COMPARISON_RELATION)
|
813 |
+
elif relation not in _COMPARISON_RELATION:
|
814 |
+
raise ValueError(
|
815 |
+
"The supported relation for comparison must be in "
|
816 |
+
f"{_COMPARISON_RELATION}, but {relation} is given."
|
817 |
+
)
|
818 |
+
else:
|
819 |
+
self._comparison_relation = relation
|
820 |
+
|
821 |
+
self._description_pattern = (
|
822 |
+
"In your response, the word {keyword} should appear {relation} "
|
823 |
+
+ "{frequency} times."
|
824 |
+
)
|
825 |
+
|
826 |
+
return self._description_pattern.format(
|
827 |
+
keyword=self._keyword,
|
828 |
+
relation=self._comparison_relation,
|
829 |
+
frequency=self._frequency,
|
830 |
+
)
|
831 |
+
|
832 |
+
def get_instruction_args(self):
|
833 |
+
"""Returns the keyward args of `build_description`."""
|
834 |
+
return {
|
835 |
+
"keyword": self._keyword,
|
836 |
+
"frequency": self._frequency,
|
837 |
+
"relation": self._comparison_relation,
|
838 |
+
}
|
839 |
+
|
840 |
+
def get_instruction_args_keys(self):
|
841 |
+
"""Returns the args keys of `build_description`."""
|
842 |
+
return ["keyword", "frequency", "relation"]
|
843 |
+
|
844 |
+
def check_following(self, value):
|
845 |
+
"""Checks if the response contain the keyword with required frequency."""
|
846 |
+
actual_occurrences = len(re.findall(self._keyword, value, flags=re.IGNORECASE))
|
847 |
+
|
848 |
+
if self._comparison_relation == _COMPARISON_RELATION[0]:
|
849 |
+
return actual_occurrences < self._frequency
|
850 |
+
elif self._comparison_relation == _COMPARISON_RELATION[1]:
|
851 |
+
return actual_occurrences >= self._frequency
|
852 |
+
|
853 |
+
|
854 |
+
class NumberOfWords(Instruction):
|
855 |
+
"""Checks the number of words."""
|
856 |
+
|
857 |
+
def build_description(self, *, num_words=None, relation=None):
|
858 |
+
"""Build the instruction description.
|
859 |
+
|
860 |
+
Args:
|
861 |
+
num_words: An integer specifying the number of words contained in the
|
862 |
+
response.
|
863 |
+
relation: A string in (`less than`, `at least`), defining the relational
|
864 |
+
operator for comparison.
|
865 |
+
Two relational comparisons are supported for now:
|
866 |
+
if 'less than', the actual number of words < num_words;
|
867 |
+
if 'at least', the actual number of words >= num_words.
|
868 |
+
|
869 |
+
Returns:
|
870 |
+
A string representing the instruction description.
|
871 |
+
"""
|
872 |
+
|
873 |
+
self._num_words = num_words
|
874 |
+
if self._num_words is None or self._num_words < 0:
|
875 |
+
self._num_words = random.randint(
|
876 |
+
_NUM_WORDS_LOWER_LIMIT, _NUM_WORDS_UPPER_LIMIT
|
877 |
+
)
|
878 |
+
|
879 |
+
if relation is None:
|
880 |
+
self._comparison_relation = random.choice(_COMPARISON_RELATION)
|
881 |
+
elif relation not in _COMPARISON_RELATION:
|
882 |
+
raise ValueError(
|
883 |
+
"The supported relation for comparison must be in "
|
884 |
+
f"{_COMPARISON_RELATION}, but {relation} is given."
|
885 |
+
)
|
886 |
+
else:
|
887 |
+
self._comparison_relation = relation
|
888 |
+
|
889 |
+
self._description_pattern = "Answer with {relation} {num_words} words."
|
890 |
+
|
891 |
+
return self._description_pattern.format(
|
892 |
+
relation=self._comparison_relation, num_words=self._num_words
|
893 |
+
)
|
894 |
+
|
895 |
+
def get_instruction_args(self):
|
896 |
+
"""Returns the keyward args of `build_description`."""
|
897 |
+
return {"num_words": self._num_words, "relation": self._comparison_relation}
|
898 |
+
|
899 |
+
def get_instruction_args_keys(self):
|
900 |
+
"""Returns the args keys of `build_description`."""
|
901 |
+
return ["num_words", "relation"]
|
902 |
+
|
903 |
+
def check_following(self, value):
|
904 |
+
"""Checks if the response contains the expected number of words."""
|
905 |
+
num_words = instructions_util.count_words(value)
|
906 |
+
|
907 |
+
if self._comparison_relation == _COMPARISON_RELATION[0]:
|
908 |
+
return num_words < self._num_words
|
909 |
+
elif self._comparison_relation == _COMPARISON_RELATION[1]:
|
910 |
+
return num_words >= self._num_words
|
911 |
+
|
912 |
+
|
913 |
+
class JsonFormat(Instruction):
|
914 |
+
"""Check the Json format."""
|
915 |
+
|
916 |
+
def build_description(self):
|
917 |
+
self._description_pattern = (
|
918 |
+
"Entire output should be wrapped in JSON format. You can use markdown"
|
919 |
+
" ticks such as ```."
|
920 |
+
)
|
921 |
+
return self._description_pattern
|
922 |
+
|
923 |
+
def get_instruction_args(self):
|
924 |
+
"""Returns the keyward args of `build_description`."""
|
925 |
+
return None
|
926 |
+
|
927 |
+
def get_instruction_args_keys(self):
|
928 |
+
"""Returns the args keys of `build_description`."""
|
929 |
+
return []
|
930 |
+
|
931 |
+
def check_following(self, value):
|
932 |
+
value = (
|
933 |
+
value.strip()
|
934 |
+
.removeprefix("```json")
|
935 |
+
.removeprefix("```Json")
|
936 |
+
.removeprefix("```JSON")
|
937 |
+
.removeprefix("```")
|
938 |
+
.removesuffix("```")
|
939 |
+
.strip()
|
940 |
+
)
|
941 |
+
try:
|
942 |
+
json.loads(value)
|
943 |
+
except ValueError as _:
|
944 |
+
return False
|
945 |
+
return True
|
946 |
+
|
947 |
+
|
948 |
+
class ParagraphFirstWordCheck(Instruction):
|
949 |
+
"""Check the paragraph and the first word of the nth paragraph."""
|
950 |
+
|
951 |
+
def build_description(
|
952 |
+
self, num_paragraphs=None, nth_paragraph=None, first_word=None
|
953 |
+
):
|
954 |
+
r"""Build the instruction description.
|
955 |
+
|
956 |
+
Args:
|
957 |
+
num_paragraphs: An integer indicating the number of paragraphs expected
|
958 |
+
in the response. A paragraph is a subset of the string that is
|
959 |
+
expected to be separated by '\n\n'.
|
960 |
+
nth_paragraph: An integer indicating the paragraph number that we look at.
|
961 |
+
Note that n starts from 1.
|
962 |
+
first_word: A string that represent the first word of the bth paragraph.
|
963 |
+
|
964 |
+
Returns:
|
965 |
+
A string representing the instruction description.
|
966 |
+
"""
|
967 |
+
self._num_paragraphs = num_paragraphs
|
968 |
+
if self._num_paragraphs is None or self._num_paragraphs < 0:
|
969 |
+
self._num_paragraphs = random.randint(1, _NUM_PARAGRAPHS)
|
970 |
+
|
971 |
+
self._nth_paragraph = nth_paragraph
|
972 |
+
if (
|
973 |
+
self._nth_paragraph is None
|
974 |
+
or self._nth_paragraph <= 0
|
975 |
+
or self._nth_paragraph > self._num_paragraphs
|
976 |
+
):
|
977 |
+
self._nth_paragraph = random.randint(1, self._num_paragraphs + 1)
|
978 |
+
|
979 |
+
self._first_word = first_word
|
980 |
+
if self._first_word is None:
|
981 |
+
self._first_word = instructions_util.generate_keywords(num_keywords=1)[0]
|
982 |
+
self._first_word = self._first_word.lower()
|
983 |
+
|
984 |
+
self._description_pattern = (
|
985 |
+
"There should be {num_paragraphs} paragraphs. "
|
986 |
+
+ "Paragraphs and only paragraphs are separated with each other by two "
|
987 |
+
+ "new lines as if it was '\\n\\n' in python. "
|
988 |
+
+ "Paragraph {nth_paragraph} must start with word {first_word}."
|
989 |
+
)
|
990 |
+
|
991 |
+
return self._description_pattern.format(
|
992 |
+
num_paragraphs=self._num_paragraphs,
|
993 |
+
nth_paragraph=self._nth_paragraph,
|
994 |
+
first_word=self._first_word,
|
995 |
+
)
|
996 |
+
|
997 |
+
def get_instruction_args(self):
|
998 |
+
"""Returns the keyward args of `build_description`."""
|
999 |
+
return {
|
1000 |
+
"num_paragraphs": self._num_paragraphs,
|
1001 |
+
"nth_paragraph": self._nth_paragraph,
|
1002 |
+
"first_word": self._first_word,
|
1003 |
+
}
|
1004 |
+
|
1005 |
+
def get_instruction_args_keys(self):
|
1006 |
+
"""Returns the args keys of `build_description`."""
|
1007 |
+
return ["num_paragraphs", "nth_paragraph", "first_word"]
|
1008 |
+
|
1009 |
+
def check_following(self, value):
|
1010 |
+
"""Checks for required number of paragraphs and correct first word.
|
1011 |
+
|
1012 |
+
Args:
|
1013 |
+
value: a string representing the response. The response may contain
|
1014 |
+
paragraphs that are separated by two new lines and the first word of
|
1015 |
+
the nth paragraph will have to match a specified word.
|
1016 |
+
|
1017 |
+
Returns:
|
1018 |
+
True if the number of paragraphs is the same as required and the first
|
1019 |
+
word of the specified paragraph is the same as required. Otherwise, false.
|
1020 |
+
"""
|
1021 |
+
|
1022 |
+
paragraphs = re.split(r"\n\n", value)
|
1023 |
+
num_paragraphs = len(paragraphs)
|
1024 |
+
|
1025 |
+
for paragraph in paragraphs:
|
1026 |
+
if not paragraph.strip():
|
1027 |
+
num_paragraphs -= 1
|
1028 |
+
|
1029 |
+
# check that index doesn't go out of bounds
|
1030 |
+
if self._nth_paragraph <= num_paragraphs:
|
1031 |
+
paragraph = paragraphs[self._nth_paragraph - 1].strip()
|
1032 |
+
if not paragraph:
|
1033 |
+
return False
|
1034 |
+
else:
|
1035 |
+
return False
|
1036 |
+
|
1037 |
+
first_word = ""
|
1038 |
+
punctuation = {".", ",", "?", "!", "'", '"'}
|
1039 |
+
|
1040 |
+
# get first word and remove punctuation
|
1041 |
+
word = paragraph.split()[0].strip()
|
1042 |
+
# TODO(jeffrey): make more complex?
|
1043 |
+
word = word.lstrip("'")
|
1044 |
+
word = word.lstrip('"')
|
1045 |
+
|
1046 |
+
for letter in word:
|
1047 |
+
if letter in punctuation:
|
1048 |
+
break
|
1049 |
+
first_word += letter.lower()
|
1050 |
+
|
1051 |
+
return num_paragraphs == self._num_paragraphs and first_word == self._first_word
|
1052 |
+
|
1053 |
+
|
1054 |
+
# TODO(jeffrey) add relation - at least/at most?
|
1055 |
+
class KeySentenceChecker(Instruction):
|
1056 |
+
"""Check the existence of certain key sentences."""
|
1057 |
+
|
1058 |
+
def build_description(self, key_sentences=None, num_sentences=None):
|
1059 |
+
"""Build the instruction description.
|
1060 |
+
|
1061 |
+
Args:
|
1062 |
+
key_sentences: A sequences of strings representing the key sentences that
|
1063 |
+
are expected in the response.
|
1064 |
+
num_sentences: The number of key sentences that are expected to be seen in
|
1065 |
+
the response.
|
1066 |
+
|
1067 |
+
Returns:
|
1068 |
+
A string representing the instruction description.
|
1069 |
+
"""
|
1070 |
+
|
1071 |
+
if not key_sentences:
|
1072 |
+
# TODO(jeffrey) make a generate sentences function? wonderwords package
|
1073 |
+
self._key_sentences = set(["For now, this is fine."])
|
1074 |
+
else:
|
1075 |
+
self._key_sentences = key_sentences
|
1076 |
+
|
1077 |
+
if not num_sentences:
|
1078 |
+
self._num_sentences = random.randint(1, len(self._key_sentences))
|
1079 |
+
else:
|
1080 |
+
self._num_sentences = num_sentences
|
1081 |
+
|
1082 |
+
self._description_pattern = (
|
1083 |
+
"Include {num_sentences} of the following sentences {key_sentences}"
|
1084 |
+
)
|
1085 |
+
|
1086 |
+
return self._description_pattern.format(
|
1087 |
+
num_sentences=self._num_sentences, key_sentences=self._key_sentences
|
1088 |
+
)
|
1089 |
+
|
1090 |
+
def get_instruction_args(self):
|
1091 |
+
"""Returns the keyward args of `build_description`."""
|
1092 |
+
return {
|
1093 |
+
"num_sentences": self._num_sentences,
|
1094 |
+
"key_sentences": list(self._key_sentences),
|
1095 |
+
}
|
1096 |
+
|
1097 |
+
def get_instruction_args_keys(self):
|
1098 |
+
"""Returns the args keys of `build_description`."""
|
1099 |
+
return ["num_sentences", "key_sentences"]
|
1100 |
+
|
1101 |
+
def check_following(self, value):
|
1102 |
+
"""Checks if the response contains the expected key sentences."""
|
1103 |
+
count = 0
|
1104 |
+
sentences = instructions_util.split_into_sentences(value)
|
1105 |
+
for sentence in self._key_sentences:
|
1106 |
+
if sentence in sentences:
|
1107 |
+
count += 1
|
1108 |
+
|
1109 |
+
return count == self._num_sentences
|
1110 |
+
|
1111 |
+
|
1112 |
+
class ForbiddenWords(Instruction):
|
1113 |
+
"""Checks that specified words are not used in response."""
|
1114 |
+
|
1115 |
+
def build_description(self, forbidden_words=None):
|
1116 |
+
"""Build the instruction description.
|
1117 |
+
|
1118 |
+
Args:
|
1119 |
+
forbidden_words: A sequences of strings respresenting words that are not
|
1120 |
+
allowed in the response.
|
1121 |
+
|
1122 |
+
Returns:
|
1123 |
+
A string representing the instruction description.
|
1124 |
+
"""
|
1125 |
+
|
1126 |
+
if not forbidden_words:
|
1127 |
+
self._forbidden_words = instructions_util.generate_keywords(
|
1128 |
+
num_keywords=_NUM_KEYWORDS
|
1129 |
+
)
|
1130 |
+
else:
|
1131 |
+
self._forbidden_words = list(set(forbidden_words))
|
1132 |
+
self._forbidden_words = sorted(self._forbidden_words)
|
1133 |
+
self._description_pattern = (
|
1134 |
+
"Do not include keywords {forbidden_words} in the response."
|
1135 |
+
)
|
1136 |
+
|
1137 |
+
return self._description_pattern.format(forbidden_words=self._forbidden_words)
|
1138 |
+
|
1139 |
+
def get_instruction_args(self):
|
1140 |
+
"""Returns the keyward args of `build_description`."""
|
1141 |
+
return {"forbidden_words": self._forbidden_words}
|
1142 |
+
|
1143 |
+
def get_instruction_args_keys(self):
|
1144 |
+
"""Returns the args keys of `build_description`."""
|
1145 |
+
return ["forbidden_words"]
|
1146 |
+
|
1147 |
+
def check_following(self, value):
|
1148 |
+
"""Check if the response does not contain the expected keywords."""
|
1149 |
+
for word in self._forbidden_words:
|
1150 |
+
if re.search(r"\b" + word + r"\b", value, flags=re.IGNORECASE):
|
1151 |
+
return False
|
1152 |
+
return True
|
1153 |
+
|
1154 |
+
|
1155 |
+
class RephraseParagraph(Instruction):
|
1156 |
+
"""Checks that the paragraph is rephrased."""
|
1157 |
+
|
1158 |
+
def build_description(self, *, original_paragraph, low, high):
|
1159 |
+
"""Builds the instruction description.
|
1160 |
+
|
1161 |
+
Args:
|
1162 |
+
original_paragraph: A string presenting the original paragraph. The
|
1163 |
+
rephrases response should have betweeb low-high words in common.
|
1164 |
+
low: An integer presenting the lower bound of similar words.
|
1165 |
+
high: An integer representing the upper bound of similar words.
|
1166 |
+
|
1167 |
+
Returns:
|
1168 |
+
A string representing the instruction description.
|
1169 |
+
"""
|
1170 |
+
# TODO(jeffrey) make more encompassing
|
1171 |
+
self._original_paragraph = original_paragraph
|
1172 |
+
self._low = low
|
1173 |
+
self._high = high
|
1174 |
+
|
1175 |
+
self._description = (
|
1176 |
+
"Rephrase the following paragraph: "
|
1177 |
+
+ "{original_paragraph}\nYour response should have "
|
1178 |
+
+ "between {low} and {high} of the same words. "
|
1179 |
+
+ "Words are the same if and only if all of the "
|
1180 |
+
+ "letters, ignoring cases, are the same. For "
|
1181 |
+
+ "example, 'run' is the same as 'Run' but different "
|
1182 |
+
+ "to 'ran'."
|
1183 |
+
)
|
1184 |
+
|
1185 |
+
return self._description.format(
|
1186 |
+
original_paragraph=original_paragraph, low=self._low, high=self._high
|
1187 |
+
)
|
1188 |
+
|
1189 |
+
def get_instruction_args(self):
|
1190 |
+
"""Returns the keyward args of `build_description`."""
|
1191 |
+
return {
|
1192 |
+
"original_paragraph": self._original_paragraph,
|
1193 |
+
"low": self._low,
|
1194 |
+
"high": self._high,
|
1195 |
+
}
|
1196 |
+
|
1197 |
+
def get_instruction_args_keys(self):
|
1198 |
+
"""Returns the args keys of `build_description`."""
|
1199 |
+
return ["original_paragraph", "low", "high"]
|
1200 |
+
|
1201 |
+
def check_following(self, value):
|
1202 |
+
val_words = re.findall(r"\w+", value.lower())
|
1203 |
+
original_words = re.findall(r"\w+", self._original_paragraph.lower())
|
1204 |
+
similar_words = 0
|
1205 |
+
|
1206 |
+
dict_val = collections.Counter(val_words)
|
1207 |
+
dict_original = collections.Counter(original_words)
|
1208 |
+
|
1209 |
+
for word in dict_original:
|
1210 |
+
similar_words += min(dict_original[word], dict_val[word])
|
1211 |
+
|
1212 |
+
return similar_words >= self._low and similar_words <= self._high
|
1213 |
+
|
1214 |
+
|
1215 |
+
class TwoResponsesChecker(Instruction):
|
1216 |
+
"""Check that two responses were given."""
|
1217 |
+
|
1218 |
+
def build_description(self):
|
1219 |
+
"""Build the instruction description."""
|
1220 |
+
self._description_pattern = (
|
1221 |
+
"Give two different responses. Responses and only responses should"
|
1222 |
+
" be separated by 6 asterisk symbols: ******."
|
1223 |
+
)
|
1224 |
+
return self._description_pattern
|
1225 |
+
|
1226 |
+
def get_instruction_args(self):
|
1227 |
+
"""Returns the keyward args of `build_description`."""
|
1228 |
+
return None
|
1229 |
+
|
1230 |
+
def get_instruction_args_keys(self):
|
1231 |
+
"""Returns the args keys of `build_description`."""
|
1232 |
+
return []
|
1233 |
+
|
1234 |
+
def check_following(self, value):
|
1235 |
+
"""Checks if the response has two different answers.
|
1236 |
+
|
1237 |
+
Args:
|
1238 |
+
value: A string representing the response.
|
1239 |
+
|
1240 |
+
Returns:
|
1241 |
+
True if two responses are detected and false otherwise.
|
1242 |
+
"""
|
1243 |
+
valid_responses = list()
|
1244 |
+
responses = value.split("******")
|
1245 |
+
for index, response in enumerate(responses):
|
1246 |
+
if not response.strip():
|
1247 |
+
if index != 0 and index != len(responses) - 1:
|
1248 |
+
return False
|
1249 |
+
else:
|
1250 |
+
valid_responses.append(response)
|
1251 |
+
return (
|
1252 |
+
len(valid_responses) == 2
|
1253 |
+
and valid_responses[0].strip() != valid_responses[1].strip()
|
1254 |
+
)
|
1255 |
+
|
1256 |
+
|
1257 |
+
class RepeatPromptThenAnswer(Instruction):
|
1258 |
+
"""Checks that Prompt is first repeated then answered."""
|
1259 |
+
|
1260 |
+
def build_description(self, *, prompt_to_repeat=None):
|
1261 |
+
"""Build the instruction description.
|
1262 |
+
|
1263 |
+
Args:
|
1264 |
+
prompt_to_repeat: The prompt that is meant to be repeated.
|
1265 |
+
|
1266 |
+
Returns:
|
1267 |
+
A string representing the instruction description.
|
1268 |
+
"""
|
1269 |
+
if not prompt_to_repeat:
|
1270 |
+
raise ValueError("prompt_to_repeat must be set.")
|
1271 |
+
else:
|
1272 |
+
self._prompt_to_repeat = prompt_to_repeat
|
1273 |
+
self._description_pattern = (
|
1274 |
+
"First repeat the request word for word without change,"
|
1275 |
+
" then give your answer (1. do not say any words or characters"
|
1276 |
+
" before repeating the request; 2. the request you need to repeat"
|
1277 |
+
" does not include this sentence)"
|
1278 |
+
)
|
1279 |
+
return self._description_pattern
|
1280 |
+
|
1281 |
+
def get_instruction_args(self):
|
1282 |
+
return {"prompt_to_repeat": self._prompt_to_repeat}
|
1283 |
+
|
1284 |
+
def get_instruction_args_keys(self):
|
1285 |
+
"""Returns the args keys of `build_description`."""
|
1286 |
+
return ["prompt_to_repeat"]
|
1287 |
+
|
1288 |
+
def check_following(self, value):
|
1289 |
+
if value.strip().lower().startswith(self._prompt_to_repeat.strip().lower()):
|
1290 |
+
return True
|
1291 |
+
return False
|
1292 |
+
|
1293 |
+
|
1294 |
+
class EndChecker(Instruction):
|
1295 |
+
"""Checks that the prompt ends with a given phrase."""
|
1296 |
+
|
1297 |
+
def build_description(self, *, end_phrase=None):
|
1298 |
+
"""Build the instruction description.
|
1299 |
+
|
1300 |
+
Args:
|
1301 |
+
end_phrase: A string representing the phrase the response should end with.
|
1302 |
+
|
1303 |
+
Returns:
|
1304 |
+
A string representing the instruction description.
|
1305 |
+
"""
|
1306 |
+
self._end_phrase = (
|
1307 |
+
end_phrase.strip() if isinstance(end_phrase, str) else end_phrase
|
1308 |
+
)
|
1309 |
+
if self._end_phrase is None:
|
1310 |
+
self._end_phrase = random.choice(_ENDING_OPTIONS)
|
1311 |
+
self._description_pattern = (
|
1312 |
+
"Finish your response with this exact phrase {ender}. "
|
1313 |
+
"No other words should follow this phrase."
|
1314 |
+
)
|
1315 |
+
return self._description_pattern.format(ender=self._end_phrase)
|
1316 |
+
|
1317 |
+
def get_instruction_args(self):
|
1318 |
+
return {"end_phrase": self._end_phrase}
|
1319 |
+
|
1320 |
+
def get_instruction_args_keys(self):
|
1321 |
+
"""Returns the args keys of `build_description`."""
|
1322 |
+
return ["end_phrase"]
|
1323 |
+
|
1324 |
+
def check_following(self, value):
|
1325 |
+
"""Checks if the response ends with the expected phrase."""
|
1326 |
+
value = value.strip().strip('"').lower()
|
1327 |
+
self._end_phrase = self._end_phrase.strip().lower()
|
1328 |
+
return value.endswith(self._end_phrase)
|
1329 |
+
|
1330 |
+
|
1331 |
+
class TitleChecker(Instruction):
|
1332 |
+
"""Checks the response for a title."""
|
1333 |
+
|
1334 |
+
def build_description(self):
|
1335 |
+
"""Build the instruction description."""
|
1336 |
+
self._description_pattern = (
|
1337 |
+
"Your answer must contain a title, wrapped in double angular brackets,"
|
1338 |
+
" such as <<poem of joy>>."
|
1339 |
+
)
|
1340 |
+
return self._description_pattern
|
1341 |
+
|
1342 |
+
def get_instruction_args(self):
|
1343 |
+
return None
|
1344 |
+
|
1345 |
+
def get_instruction_args_keys(self):
|
1346 |
+
"""Returns the args keys of `build_description`."""
|
1347 |
+
return []
|
1348 |
+
|
1349 |
+
def check_following(self, value):
|
1350 |
+
"""Checks if the response contains a title."""
|
1351 |
+
pattern = r"<<[^\n]+>>"
|
1352 |
+
re_pattern = re.compile(pattern)
|
1353 |
+
titles = re.findall(re_pattern, value)
|
1354 |
+
|
1355 |
+
for title in titles:
|
1356 |
+
if title.lstrip("<").rstrip(">").strip():
|
1357 |
+
return True
|
1358 |
+
return False
|
1359 |
+
|
1360 |
+
|
1361 |
+
class LetterFrequencyChecker(Instruction):
|
1362 |
+
"""Checks letter frequency."""
|
1363 |
+
|
1364 |
+
def build_description(self, *, letter=None, let_frequency=None, let_relation=None):
|
1365 |
+
"""Build the instruction description.
|
1366 |
+
|
1367 |
+
Args:
|
1368 |
+
letter: A string representing a letter that is expected in the response.
|
1369 |
+
let_frequency: An integer specifying the number of times `keyword` is
|
1370 |
+
expected to appear in the response.
|
1371 |
+
let_relation: A string in (`less than`, `at least`), defining the
|
1372 |
+
relational operator for comparison. Two relational comparisons are
|
1373 |
+
supported for now; if 'less than', the actual number of
|
1374 |
+
occurrences < frequency; if 'at least', the actual number of
|
1375 |
+
occurrences >= frequency.
|
1376 |
+
|
1377 |
+
Returns:
|
1378 |
+
A string representing the instruction description.
|
1379 |
+
"""
|
1380 |
+
if (
|
1381 |
+
not letter
|
1382 |
+
or len(letter) > 1
|
1383 |
+
or ord(letter.lower()) < 97
|
1384 |
+
or ord(letter.lower()) > 122
|
1385 |
+
):
|
1386 |
+
self._letter = random.choice(list(string.ascii_letters))
|
1387 |
+
else:
|
1388 |
+
self._letter = letter.strip()
|
1389 |
+
self._letter = self._letter.lower()
|
1390 |
+
|
1391 |
+
self._frequency = let_frequency
|
1392 |
+
if self._frequency is None or self._frequency < 0:
|
1393 |
+
self._frequency = random.randint(1, _LETTER_FREQUENCY)
|
1394 |
+
|
1395 |
+
if let_relation is None:
|
1396 |
+
self._comparison_relation = random.choice(_COMPARISON_RELATION)
|
1397 |
+
elif let_relation not in _COMPARISON_RELATION:
|
1398 |
+
raise ValueError(
|
1399 |
+
"The supported relation for comparison must be in "
|
1400 |
+
f"{_COMPARISON_RELATION}, but {let_relation} is given."
|
1401 |
+
)
|
1402 |
+
else:
|
1403 |
+
self._comparison_relation = let_relation
|
1404 |
+
|
1405 |
+
self._description_pattern = (
|
1406 |
+
"In your response, the letter {letter} should appear {let_relation}"
|
1407 |
+
" {let_frequency} times."
|
1408 |
+
)
|
1409 |
+
|
1410 |
+
return self._description_pattern.format(
|
1411 |
+
letter=self._letter,
|
1412 |
+
let_frequency=self._frequency,
|
1413 |
+
let_relation=self._comparison_relation,
|
1414 |
+
)
|
1415 |
+
|
1416 |
+
def get_instruction_args(self):
|
1417 |
+
"""Returns the keyword args of build description."""
|
1418 |
+
return {
|
1419 |
+
"letter": self._letter,
|
1420 |
+
"let_frequency": self._frequency,
|
1421 |
+
"let_relation": self._comparison_relation,
|
1422 |
+
}
|
1423 |
+
|
1424 |
+
def get_instruction_args_keys(self):
|
1425 |
+
"""Returns the args keys of `build_description`."""
|
1426 |
+
return ["letter", "let_frequency", "let_relation"]
|
1427 |
+
|
1428 |
+
def check_following(self, value):
|
1429 |
+
"""Checks that the response contains the letter at the right frequency."""
|
1430 |
+
value = value.lower()
|
1431 |
+
letters = collections.Counter(value)
|
1432 |
+
|
1433 |
+
if self._comparison_relation == _COMPARISON_RELATION[0]:
|
1434 |
+
return letters[self._letter] < self._frequency
|
1435 |
+
else:
|
1436 |
+
return letters[self._letter] >= self._frequency
|
1437 |
+
|
1438 |
+
|
1439 |
+
class CapitalLettersEnglishChecker(Instruction):
|
1440 |
+
"""Checks that the response is in english and is in all capital letters."""
|
1441 |
+
|
1442 |
+
def build_description(self):
|
1443 |
+
"""Build the instruction description."""
|
1444 |
+
self._description_pattern = (
|
1445 |
+
"Your entire response should be in English, and in all capital letters."
|
1446 |
+
)
|
1447 |
+
return self._description_pattern
|
1448 |
+
|
1449 |
+
def get_instruction_args(self):
|
1450 |
+
return None
|
1451 |
+
|
1452 |
+
def get_instruction_args_keys(self):
|
1453 |
+
"""Returns the args keys of `build_description`."""
|
1454 |
+
return []
|
1455 |
+
|
1456 |
+
def check_following(self, value):
|
1457 |
+
"""Checks that the response is in English and in all capital letters."""
|
1458 |
+
assert isinstance(value, str)
|
1459 |
+
|
1460 |
+
try:
|
1461 |
+
return value.isupper() and langdetect.detect(value) == "en"
|
1462 |
+
except langdetect.LangDetectException as e:
|
1463 |
+
# Count as instruction is followed.
|
1464 |
+
logging.error(
|
1465 |
+
"Unable to detect language for text %s due to %s", value, e
|
1466 |
+
) # refex: disable=pytotw.037
|
1467 |
+
return True
|
1468 |
+
|
1469 |
+
|
1470 |
+
class LowercaseLettersEnglishChecker(Instruction):
|
1471 |
+
"""Checks that the response is in english and is in all lowercase letters."""
|
1472 |
+
|
1473 |
+
def build_description(self):
|
1474 |
+
"""Build the instruction description."""
|
1475 |
+
self._description_pattern = (
|
1476 |
+
"Your entire response should be in English, and in all lowercase"
|
1477 |
+
" letters. No capital letters are allowed."
|
1478 |
+
)
|
1479 |
+
return self._description_pattern
|
1480 |
+
|
1481 |
+
def get_instruction_args(self):
|
1482 |
+
return None
|
1483 |
+
|
1484 |
+
def get_instruction_args_keys(self):
|
1485 |
+
"""Returns the args keys of `build_description`."""
|
1486 |
+
return []
|
1487 |
+
|
1488 |
+
def check_following(self, value):
|
1489 |
+
"""Checks that the response is in English and in all lowercase letters."""
|
1490 |
+
assert isinstance(value, str)
|
1491 |
+
|
1492 |
+
try:
|
1493 |
+
return value.islower() and langdetect.detect(value) == "en"
|
1494 |
+
except langdetect.LangDetectException as e:
|
1495 |
+
# Count as instruction is followed.
|
1496 |
+
logging.error(
|
1497 |
+
"Unable to detect language for text %s due to %s", value, e
|
1498 |
+
) # refex: disable=pytotw.037
|
1499 |
+
return True
|
1500 |
+
|
1501 |
+
|
1502 |
+
class CommaChecker(Instruction):
|
1503 |
+
"""Checks the response for no commas."""
|
1504 |
+
|
1505 |
+
def build_description(self):
|
1506 |
+
"""Build the instruction description."""
|
1507 |
+
self._description_pattern = (
|
1508 |
+
"In your entire response, refrain from the use of any commas."
|
1509 |
+
)
|
1510 |
+
return self._description_pattern
|
1511 |
+
|
1512 |
+
def get_instruction_args(self):
|
1513 |
+
return None
|
1514 |
+
|
1515 |
+
def get_instruction_args_keys(self):
|
1516 |
+
"""Returns the args keys of `build_description`."""
|
1517 |
+
return []
|
1518 |
+
|
1519 |
+
def check_following(self, value):
|
1520 |
+
"""Checks that the response does not contain commas."""
|
1521 |
+
return not re.search(r"\,", value)
|
1522 |
+
|
1523 |
+
|
1524 |
+
class CapitalWordFrequencyChecker(Instruction):
|
1525 |
+
"""Checks frequency of words with all capital letters."""
|
1526 |
+
|
1527 |
+
def build_description(
|
1528 |
+
self,
|
1529 |
+
capital_frequency=None,
|
1530 |
+
capital_relation=None,
|
1531 |
+
):
|
1532 |
+
"""Build the instruction description.
|
1533 |
+
|
1534 |
+
Args:
|
1535 |
+
capital_frequency: An integer that represents the number of words that
|
1536 |
+
should be in all capital letters.
|
1537 |
+
capital_relation: A string that is 'at least' or 'at most' that refers to
|
1538 |
+
the frequency.
|
1539 |
+
|
1540 |
+
Returns:
|
1541 |
+
A string representing the instruction description.
|
1542 |
+
"""
|
1543 |
+
self._frequency = capital_frequency
|
1544 |
+
if self._frequency is None:
|
1545 |
+
self._frequency = random.randint(1, _ALL_CAPITAL_WORD_FREQUENCY)
|
1546 |
+
|
1547 |
+
self._comparison_relation = capital_relation
|
1548 |
+
if capital_relation is None:
|
1549 |
+
self._comparison_relation = random.choice(_COMPARISON_RELATION)
|
1550 |
+
elif capital_relation not in _COMPARISON_RELATION:
|
1551 |
+
raise ValueError(
|
1552 |
+
"The supported relation for comparison must be in "
|
1553 |
+
f"{_COMPARISON_RELATION}, but {capital_relation} is given."
|
1554 |
+
)
|
1555 |
+
|
1556 |
+
self._description_pattern = (
|
1557 |
+
"In your response, words with all capital letters should appear"
|
1558 |
+
" {relation} {frequency} times."
|
1559 |
+
)
|
1560 |
+
|
1561 |
+
return self._description_pattern.format(
|
1562 |
+
frequency=self._frequency, relation=self._comparison_relation
|
1563 |
+
)
|
1564 |
+
|
1565 |
+
def get_instruction_args(self):
|
1566 |
+
"""Returns the keyword args of build description."""
|
1567 |
+
return {
|
1568 |
+
"capital_frequency": self._frequency,
|
1569 |
+
"capital_relation": self._comparison_relation,
|
1570 |
+
}
|
1571 |
+
|
1572 |
+
def get_instruction_args_keys(self):
|
1573 |
+
"""Returns the args keys of `build_description`."""
|
1574 |
+
return ["capital_frequency", "capital_relation"]
|
1575 |
+
|
1576 |
+
def check_following(self, value):
|
1577 |
+
"""Checks the frequency of words with all capital letters."""
|
1578 |
+
# Hyphenated words will count as one word
|
1579 |
+
words = instructions_util.nltk.word_tokenize(value)
|
1580 |
+
capital_words = [word for word in words if word.isupper()]
|
1581 |
+
|
1582 |
+
capital_words = len(capital_words)
|
1583 |
+
|
1584 |
+
if self._comparison_relation == _COMPARISON_RELATION[0]:
|
1585 |
+
return capital_words < self._frequency
|
1586 |
+
else:
|
1587 |
+
return capital_words >= self._frequency
|
1588 |
+
|
1589 |
+
|
1590 |
+
class QuotationChecker(Instruction):
|
1591 |
+
"""Checks response is wrapped with double quotation marks."""
|
1592 |
+
|
1593 |
+
def build_description(self):
|
1594 |
+
"""Build the instruction description."""
|
1595 |
+
self._description_pattern = (
|
1596 |
+
"Wrap your entire response with double quotation marks."
|
1597 |
+
)
|
1598 |
+
return self._description_pattern
|
1599 |
+
|
1600 |
+
def get_instruction_args(self):
|
1601 |
+
"""Returns the keyword args of build description."""
|
1602 |
+
return None
|
1603 |
+
|
1604 |
+
def get_instruction_args_keys(self):
|
1605 |
+
"""Returns the args keys of `build_description`."""
|
1606 |
+
return []
|
1607 |
+
|
1608 |
+
def check_following(self, value):
|
1609 |
+
"""Checks if the response is wrapped with double quotation marks."""
|
1610 |
+
value = value.strip()
|
1611 |
+
return len(value) > 1 and value[0] == '"' and value[-1] == '"'
|
src/backend/tasks/ifeval/instructions_registry.py
ADDED
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2023 The Google Research Authors.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
|
16 |
+
"""Registry of all instructions."""
|
17 |
+
from lm_eval.tasks.ifeval import instructions
|
18 |
+
|
19 |
+
_KEYWORD = "keywords:"
|
20 |
+
|
21 |
+
_LANGUAGE = "language:"
|
22 |
+
|
23 |
+
_LENGTH = "length_constraints:"
|
24 |
+
|
25 |
+
_CONTENT = "detectable_content:"
|
26 |
+
|
27 |
+
_FORMAT = "detectable_format:"
|
28 |
+
|
29 |
+
_MULTITURN = "multi-turn:"
|
30 |
+
|
31 |
+
_COMBINATION = "combination:"
|
32 |
+
|
33 |
+
_STARTEND = "startend:"
|
34 |
+
|
35 |
+
_CHANGE_CASES = "change_case:"
|
36 |
+
|
37 |
+
_PUNCTUATION = "punctuation:"
|
38 |
+
|
39 |
+
INSTRUCTION_DICT = {
|
40 |
+
_KEYWORD + "existence": instructions.KeywordChecker,
|
41 |
+
_KEYWORD + "frequency": instructions.KeywordFrequencyChecker,
|
42 |
+
# TODO(jeffreyzhou): make a proper set of sentences to choose from
|
43 |
+
# _KEYWORD + "key_sentences": instructions.KeySentenceChecker,
|
44 |
+
_KEYWORD + "forbidden_words": instructions.ForbiddenWords,
|
45 |
+
_KEYWORD + "letter_frequency": instructions.LetterFrequencyChecker,
|
46 |
+
_LANGUAGE + "response_language": instructions.ResponseLanguageChecker,
|
47 |
+
_LENGTH + "number_sentences": instructions.NumberOfSentences,
|
48 |
+
_LENGTH + "number_paragraphs": instructions.ParagraphChecker,
|
49 |
+
_LENGTH + "number_words": instructions.NumberOfWords,
|
50 |
+
_LENGTH + "nth_paragraph_first_word": instructions.ParagraphFirstWordCheck,
|
51 |
+
_CONTENT + "number_placeholders": instructions.PlaceholderChecker,
|
52 |
+
_CONTENT + "postscript": instructions.PostscriptChecker,
|
53 |
+
_FORMAT + "number_bullet_lists": instructions.BulletListChecker,
|
54 |
+
# TODO(jeffreyzhou): Pre-create paragraph or use prompt to replace
|
55 |
+
# _CONTENT + "rephrase_paragraph": instructions.RephraseParagraph,
|
56 |
+
_FORMAT + "constrained_response": instructions.ConstrainedResponseChecker,
|
57 |
+
_FORMAT + "number_highlighted_sections": (instructions.HighlightSectionChecker),
|
58 |
+
_FORMAT + "multiple_sections": instructions.SectionChecker,
|
59 |
+
# TODO(tianjianlu): Re-enable rephrasing with preprocessing the message.
|
60 |
+
# _FORMAT + "rephrase": instructions.RephraseChecker,
|
61 |
+
_FORMAT + "json_format": instructions.JsonFormat,
|
62 |
+
_FORMAT + "title": instructions.TitleChecker,
|
63 |
+
# TODO(tianjianlu): Re-enable with specific prompts.
|
64 |
+
# _MULTITURN + "constrained_start": instructions.ConstrainedStartChecker,
|
65 |
+
_COMBINATION + "two_responses": instructions.TwoResponsesChecker,
|
66 |
+
_COMBINATION + "repeat_prompt": instructions.RepeatPromptThenAnswer,
|
67 |
+
_STARTEND + "end_checker": instructions.EndChecker,
|
68 |
+
_CHANGE_CASES + "capital_word_frequency": instructions.CapitalWordFrequencyChecker,
|
69 |
+
_CHANGE_CASES + "english_capital": instructions.CapitalLettersEnglishChecker,
|
70 |
+
_CHANGE_CASES + "english_lowercase": instructions.LowercaseLettersEnglishChecker,
|
71 |
+
_PUNCTUATION + "no_comma": instructions.CommaChecker,
|
72 |
+
_STARTEND + "quotation": instructions.QuotationChecker,
|
73 |
+
}
|
74 |
+
|
75 |
+
INSTRUCTION_CONFLICTS = {
|
76 |
+
_KEYWORD + "existence": {_KEYWORD + "existence"},
|
77 |
+
_KEYWORD + "frequency": {_KEYWORD + "frequency"},
|
78 |
+
# TODO(jeffreyzhou): make a proper set of sentences to choose from
|
79 |
+
# _KEYWORD + "key_sentences": instructions.KeySentenceChecker,
|
80 |
+
_KEYWORD + "forbidden_words": {_KEYWORD + "forbidden_words"},
|
81 |
+
_KEYWORD + "letter_frequency": {_KEYWORD + "letter_frequency"},
|
82 |
+
_LANGUAGE
|
83 |
+
+ "response_language": {
|
84 |
+
_LANGUAGE + "response_language",
|
85 |
+
_FORMAT + "multiple_sections",
|
86 |
+
_KEYWORD + "existence",
|
87 |
+
_KEYWORD + "frequency",
|
88 |
+
_KEYWORD + "forbidden_words",
|
89 |
+
_STARTEND + "end_checker",
|
90 |
+
_CHANGE_CASES + "english_capital",
|
91 |
+
_CHANGE_CASES + "english_lowercase",
|
92 |
+
},
|
93 |
+
_LENGTH + "number_sentences": {_LENGTH + "number_sentences"},
|
94 |
+
_LENGTH
|
95 |
+
+ "number_paragraphs": {
|
96 |
+
_LENGTH + "number_paragraphs",
|
97 |
+
_LENGTH + "nth_paragraph_first_word",
|
98 |
+
_LENGTH + "number_sentences",
|
99 |
+
_LENGTH + "nth_paragraph_first_word",
|
100 |
+
},
|
101 |
+
_LENGTH + "number_words": {_LENGTH + "number_words"},
|
102 |
+
_LENGTH
|
103 |
+
+ "nth_paragraph_first_word": {
|
104 |
+
_LENGTH + "nth_paragraph_first_word",
|
105 |
+
_LENGTH + "number_paragraphs",
|
106 |
+
},
|
107 |
+
_CONTENT + "number_placeholders": {_CONTENT + "number_placeholders"},
|
108 |
+
_CONTENT + "postscript": {_CONTENT + "postscript"},
|
109 |
+
_FORMAT + "number_bullet_lists": {_FORMAT + "number_bullet_lists"},
|
110 |
+
# TODO(jeffreyzhou): Pre-create paragraph or use prompt to replace
|
111 |
+
# _CONTENT + "rephrase_paragraph": instructions.RephraseParagraph,
|
112 |
+
_FORMAT + "constrained_response": set(INSTRUCTION_DICT.keys()),
|
113 |
+
_FORMAT + "number_highlighted_sections": {_FORMAT + "number_highlighted_sections"},
|
114 |
+
_FORMAT
|
115 |
+
+ "multiple_sections": {
|
116 |
+
_FORMAT + "multiple_sections",
|
117 |
+
_LANGUAGE + "response_language",
|
118 |
+
_FORMAT + "number_highlighted_sections",
|
119 |
+
},
|
120 |
+
# TODO(tianjianlu): Re-enable rephrasing with preprocessing the message.
|
121 |
+
# _FORMAT + "rephrase": instructions.RephraseChecker,
|
122 |
+
_FORMAT
|
123 |
+
+ "json_format": set(INSTRUCTION_DICT.keys()).difference(
|
124 |
+
{_KEYWORD + "forbidden_words", _KEYWORD + "existence"}
|
125 |
+
),
|
126 |
+
_FORMAT + "title": {_FORMAT + "title"},
|
127 |
+
# TODO(tianjianlu): Re-enable with specific prompts.
|
128 |
+
# _MULTITURN + "constrained_start": instructions.ConstrainedStartChecker,
|
129 |
+
_COMBINATION
|
130 |
+
+ "two_responses": set(INSTRUCTION_DICT.keys()).difference(
|
131 |
+
{
|
132 |
+
_KEYWORD + "forbidden_words",
|
133 |
+
_KEYWORD + "existence",
|
134 |
+
_LANGUAGE + "response_language",
|
135 |
+
_FORMAT + "title",
|
136 |
+
_PUNCTUATION + "no_comma",
|
137 |
+
}
|
138 |
+
),
|
139 |
+
_COMBINATION
|
140 |
+
+ "repeat_prompt": set(INSTRUCTION_DICT.keys()).difference(
|
141 |
+
{_KEYWORD + "existence", _FORMAT + "title", _PUNCTUATION + "no_comma"}
|
142 |
+
),
|
143 |
+
_STARTEND + "end_checker": {_STARTEND + "end_checker"},
|
144 |
+
_CHANGE_CASES
|
145 |
+
+ "capital_word_frequency": {
|
146 |
+
_CHANGE_CASES + "capital_word_frequency",
|
147 |
+
_CHANGE_CASES + "english_lowercase",
|
148 |
+
_CHANGE_CASES + "english_capital",
|
149 |
+
},
|
150 |
+
_CHANGE_CASES + "english_capital": {_CHANGE_CASES + "english_capital"},
|
151 |
+
_CHANGE_CASES
|
152 |
+
+ "english_lowercase": {
|
153 |
+
_CHANGE_CASES + "english_lowercase",
|
154 |
+
_CHANGE_CASES + "english_capital",
|
155 |
+
},
|
156 |
+
_PUNCTUATION + "no_comma": {_PUNCTUATION + "no_comma"},
|
157 |
+
_STARTEND + "quotation": {_STARTEND + "quotation", _FORMAT + "title"},
|
158 |
+
}
|
159 |
+
|
160 |
+
|
161 |
+
def conflict_make(conflicts):
|
162 |
+
"""Makes sure if A conflicts with B, B will conflict with A.
|
163 |
+
|
164 |
+
Args:
|
165 |
+
conflicts: Dictionary of potential conflicts where key is instruction id
|
166 |
+
and value is set of instruction ids that it conflicts with.
|
167 |
+
|
168 |
+
Returns:
|
169 |
+
Revised version of the dictionary. All instructions conflict with
|
170 |
+
themselves. If A conflicts with B, B will conflict with A.
|
171 |
+
"""
|
172 |
+
for key in conflicts:
|
173 |
+
for k in conflicts[key]:
|
174 |
+
conflicts[k].add(key)
|
175 |
+
conflicts[key].add(key)
|
176 |
+
return conflicts
|
src/backend/tasks/ifeval/instructions_util.py
ADDED
@@ -0,0 +1,1684 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2023 The Google Research Authors.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
|
16 |
+
"""Utility library of instructions."""
|
17 |
+
|
18 |
+
import functools
|
19 |
+
import random
|
20 |
+
import re
|
21 |
+
from typing import List
|
22 |
+
|
23 |
+
import immutabledict
|
24 |
+
import nltk
|
25 |
+
|
26 |
+
|
27 |
+
def download_nltk_resources():
|
28 |
+
"""Download 'punkt' if not already installed"""
|
29 |
+
try:
|
30 |
+
nltk.data.find("tokenizers/punkt")
|
31 |
+
except LookupError:
|
32 |
+
nltk.download("punkt")
|
33 |
+
|
34 |
+
|
35 |
+
download_nltk_resources()
|
36 |
+
|
37 |
+
WORD_LIST = [
|
38 |
+
"western",
|
39 |
+
"sentence",
|
40 |
+
"signal",
|
41 |
+
"dump",
|
42 |
+
"spot",
|
43 |
+
"opposite",
|
44 |
+
"bottom",
|
45 |
+
"potato",
|
46 |
+
"administration",
|
47 |
+
"working",
|
48 |
+
"welcome",
|
49 |
+
"morning",
|
50 |
+
"good",
|
51 |
+
"agency",
|
52 |
+
"primary",
|
53 |
+
"wish",
|
54 |
+
"responsibility",
|
55 |
+
"press",
|
56 |
+
"problem",
|
57 |
+
"president",
|
58 |
+
"steal",
|
59 |
+
"brush",
|
60 |
+
"read",
|
61 |
+
"type",
|
62 |
+
"beat",
|
63 |
+
"trainer",
|
64 |
+
"growth",
|
65 |
+
"lock",
|
66 |
+
"bone",
|
67 |
+
"case",
|
68 |
+
"equal",
|
69 |
+
"comfortable",
|
70 |
+
"region",
|
71 |
+
"replacement",
|
72 |
+
"performance",
|
73 |
+
"mate",
|
74 |
+
"walk",
|
75 |
+
"medicine",
|
76 |
+
"film",
|
77 |
+
"thing",
|
78 |
+
"rock",
|
79 |
+
"tap",
|
80 |
+
"total",
|
81 |
+
"competition",
|
82 |
+
"ease",
|
83 |
+
"south",
|
84 |
+
"establishment",
|
85 |
+
"gather",
|
86 |
+
"parking",
|
87 |
+
"world",
|
88 |
+
"plenty",
|
89 |
+
"breath",
|
90 |
+
"claim",
|
91 |
+
"alcohol",
|
92 |
+
"trade",
|
93 |
+
"dear",
|
94 |
+
"highlight",
|
95 |
+
"street",
|
96 |
+
"matter",
|
97 |
+
"decision",
|
98 |
+
"mess",
|
99 |
+
"agreement",
|
100 |
+
"studio",
|
101 |
+
"coach",
|
102 |
+
"assist",
|
103 |
+
"brain",
|
104 |
+
"wing",
|
105 |
+
"style",
|
106 |
+
"private",
|
107 |
+
"top",
|
108 |
+
"brown",
|
109 |
+
"leg",
|
110 |
+
"buy",
|
111 |
+
"procedure",
|
112 |
+
"method",
|
113 |
+
"speed",
|
114 |
+
"high",
|
115 |
+
"company",
|
116 |
+
"valuable",
|
117 |
+
"pie",
|
118 |
+
"analyst",
|
119 |
+
"session",
|
120 |
+
"pattern",
|
121 |
+
"district",
|
122 |
+
"pleasure",
|
123 |
+
"dinner",
|
124 |
+
"swimming",
|
125 |
+
"joke",
|
126 |
+
"order",
|
127 |
+
"plate",
|
128 |
+
"department",
|
129 |
+
"motor",
|
130 |
+
"cell",
|
131 |
+
"spend",
|
132 |
+
"cabinet",
|
133 |
+
"difference",
|
134 |
+
"power",
|
135 |
+
"examination",
|
136 |
+
"engine",
|
137 |
+
"horse",
|
138 |
+
"dimension",
|
139 |
+
"pay",
|
140 |
+
"toe",
|
141 |
+
"curve",
|
142 |
+
"literature",
|
143 |
+
"bother",
|
144 |
+
"fire",
|
145 |
+
"possibility",
|
146 |
+
"debate",
|
147 |
+
"activity",
|
148 |
+
"passage",
|
149 |
+
"hello",
|
150 |
+
"cycle",
|
151 |
+
"background",
|
152 |
+
"quiet",
|
153 |
+
"author",
|
154 |
+
"effect",
|
155 |
+
"actor",
|
156 |
+
"page",
|
157 |
+
"bicycle",
|
158 |
+
"error",
|
159 |
+
"throat",
|
160 |
+
"attack",
|
161 |
+
"character",
|
162 |
+
"phone",
|
163 |
+
"tea",
|
164 |
+
"increase",
|
165 |
+
"outcome",
|
166 |
+
"file",
|
167 |
+
"specific",
|
168 |
+
"inspector",
|
169 |
+
"internal",
|
170 |
+
"potential",
|
171 |
+
"staff",
|
172 |
+
"building",
|
173 |
+
"employer",
|
174 |
+
"shoe",
|
175 |
+
"hand",
|
176 |
+
"direction",
|
177 |
+
"garden",
|
178 |
+
"purchase",
|
179 |
+
"interview",
|
180 |
+
"study",
|
181 |
+
"recognition",
|
182 |
+
"member",
|
183 |
+
"spiritual",
|
184 |
+
"oven",
|
185 |
+
"sandwich",
|
186 |
+
"weird",
|
187 |
+
"passenger",
|
188 |
+
"particular",
|
189 |
+
"response",
|
190 |
+
"reaction",
|
191 |
+
"size",
|
192 |
+
"variation",
|
193 |
+
"a",
|
194 |
+
"cancel",
|
195 |
+
"candy",
|
196 |
+
"exit",
|
197 |
+
"guest",
|
198 |
+
"condition",
|
199 |
+
"fly",
|
200 |
+
"price",
|
201 |
+
"weakness",
|
202 |
+
"convert",
|
203 |
+
"hotel",
|
204 |
+
"great",
|
205 |
+
"mouth",
|
206 |
+
"mind",
|
207 |
+
"song",
|
208 |
+
"sugar",
|
209 |
+
"suspect",
|
210 |
+
"telephone",
|
211 |
+
"ear",
|
212 |
+
"roof",
|
213 |
+
"paint",
|
214 |
+
"refrigerator",
|
215 |
+
"organization",
|
216 |
+
"jury",
|
217 |
+
"reward",
|
218 |
+
"engineering",
|
219 |
+
"day",
|
220 |
+
"possession",
|
221 |
+
"crew",
|
222 |
+
"bar",
|
223 |
+
"road",
|
224 |
+
"description",
|
225 |
+
"celebration",
|
226 |
+
"score",
|
227 |
+
"mark",
|
228 |
+
"letter",
|
229 |
+
"shower",
|
230 |
+
"suggestion",
|
231 |
+
"sir",
|
232 |
+
"luck",
|
233 |
+
"national",
|
234 |
+
"progress",
|
235 |
+
"hall",
|
236 |
+
"stroke",
|
237 |
+
"theory",
|
238 |
+
"offer",
|
239 |
+
"story",
|
240 |
+
"tax",
|
241 |
+
"definition",
|
242 |
+
"history",
|
243 |
+
"ride",
|
244 |
+
"medium",
|
245 |
+
"opening",
|
246 |
+
"glass",
|
247 |
+
"elevator",
|
248 |
+
"stomach",
|
249 |
+
"question",
|
250 |
+
"ability",
|
251 |
+
"leading",
|
252 |
+
"village",
|
253 |
+
"computer",
|
254 |
+
"city",
|
255 |
+
"grand",
|
256 |
+
"confidence",
|
257 |
+
"candle",
|
258 |
+
"priest",
|
259 |
+
"recommendation",
|
260 |
+
"point",
|
261 |
+
"necessary",
|
262 |
+
"body",
|
263 |
+
"desk",
|
264 |
+
"secret",
|
265 |
+
"horror",
|
266 |
+
"noise",
|
267 |
+
"culture",
|
268 |
+
"warning",
|
269 |
+
"water",
|
270 |
+
"round",
|
271 |
+
"diet",
|
272 |
+
"flower",
|
273 |
+
"bus",
|
274 |
+
"tough",
|
275 |
+
"permission",
|
276 |
+
"week",
|
277 |
+
"prompt",
|
278 |
+
"connection",
|
279 |
+
"abuse",
|
280 |
+
"height",
|
281 |
+
"save",
|
282 |
+
"corner",
|
283 |
+
"border",
|
284 |
+
"stress",
|
285 |
+
"drive",
|
286 |
+
"stop",
|
287 |
+
"rip",
|
288 |
+
"meal",
|
289 |
+
"listen",
|
290 |
+
"confusion",
|
291 |
+
"girlfriend",
|
292 |
+
"living",
|
293 |
+
"relation",
|
294 |
+
"significance",
|
295 |
+
"plan",
|
296 |
+
"creative",
|
297 |
+
"atmosphere",
|
298 |
+
"blame",
|
299 |
+
"invite",
|
300 |
+
"housing",
|
301 |
+
"paper",
|
302 |
+
"drink",
|
303 |
+
"roll",
|
304 |
+
"silver",
|
305 |
+
"drunk",
|
306 |
+
"age",
|
307 |
+
"damage",
|
308 |
+
"smoke",
|
309 |
+
"environment",
|
310 |
+
"pack",
|
311 |
+
"savings",
|
312 |
+
"influence",
|
313 |
+
"tourist",
|
314 |
+
"rain",
|
315 |
+
"post",
|
316 |
+
"sign",
|
317 |
+
"grandmother",
|
318 |
+
"run",
|
319 |
+
"profit",
|
320 |
+
"push",
|
321 |
+
"clerk",
|
322 |
+
"final",
|
323 |
+
"wine",
|
324 |
+
"swim",
|
325 |
+
"pause",
|
326 |
+
"stuff",
|
327 |
+
"singer",
|
328 |
+
"funeral",
|
329 |
+
"average",
|
330 |
+
"source",
|
331 |
+
"scene",
|
332 |
+
"tradition",
|
333 |
+
"personal",
|
334 |
+
"snow",
|
335 |
+
"nobody",
|
336 |
+
"distance",
|
337 |
+
"sort",
|
338 |
+
"sensitive",
|
339 |
+
"animal",
|
340 |
+
"major",
|
341 |
+
"negotiation",
|
342 |
+
"click",
|
343 |
+
"mood",
|
344 |
+
"period",
|
345 |
+
"arrival",
|
346 |
+
"expression",
|
347 |
+
"holiday",
|
348 |
+
"repeat",
|
349 |
+
"dust",
|
350 |
+
"closet",
|
351 |
+
"gold",
|
352 |
+
"bad",
|
353 |
+
"sail",
|
354 |
+
"combination",
|
355 |
+
"clothes",
|
356 |
+
"emphasis",
|
357 |
+
"duty",
|
358 |
+
"black",
|
359 |
+
"step",
|
360 |
+
"school",
|
361 |
+
"jump",
|
362 |
+
"document",
|
363 |
+
"professional",
|
364 |
+
"lip",
|
365 |
+
"chemical",
|
366 |
+
"front",
|
367 |
+
"wake",
|
368 |
+
"while",
|
369 |
+
"inside",
|
370 |
+
"watch",
|
371 |
+
"row",
|
372 |
+
"subject",
|
373 |
+
"penalty",
|
374 |
+
"balance",
|
375 |
+
"possible",
|
376 |
+
"adult",
|
377 |
+
"aside",
|
378 |
+
"sample",
|
379 |
+
"appeal",
|
380 |
+
"wedding",
|
381 |
+
"depth",
|
382 |
+
"king",
|
383 |
+
"award",
|
384 |
+
"wife",
|
385 |
+
"blow",
|
386 |
+
"site",
|
387 |
+
"camp",
|
388 |
+
"music",
|
389 |
+
"safe",
|
390 |
+
"gift",
|
391 |
+
"fault",
|
392 |
+
"guess",
|
393 |
+
"act",
|
394 |
+
"shame",
|
395 |
+
"drama",
|
396 |
+
"capital",
|
397 |
+
"exam",
|
398 |
+
"stupid",
|
399 |
+
"record",
|
400 |
+
"sound",
|
401 |
+
"swing",
|
402 |
+
"novel",
|
403 |
+
"minimum",
|
404 |
+
"ratio",
|
405 |
+
"machine",
|
406 |
+
"shape",
|
407 |
+
"lead",
|
408 |
+
"operation",
|
409 |
+
"salary",
|
410 |
+
"cloud",
|
411 |
+
"affair",
|
412 |
+
"hit",
|
413 |
+
"chapter",
|
414 |
+
"stage",
|
415 |
+
"quantity",
|
416 |
+
"access",
|
417 |
+
"army",
|
418 |
+
"chain",
|
419 |
+
"traffic",
|
420 |
+
"kick",
|
421 |
+
"analysis",
|
422 |
+
"airport",
|
423 |
+
"time",
|
424 |
+
"vacation",
|
425 |
+
"philosophy",
|
426 |
+
"ball",
|
427 |
+
"chest",
|
428 |
+
"thanks",
|
429 |
+
"place",
|
430 |
+
"mountain",
|
431 |
+
"advertising",
|
432 |
+
"red",
|
433 |
+
"past",
|
434 |
+
"rent",
|
435 |
+
"return",
|
436 |
+
"tour",
|
437 |
+
"house",
|
438 |
+
"construction",
|
439 |
+
"net",
|
440 |
+
"native",
|
441 |
+
"war",
|
442 |
+
"figure",
|
443 |
+
"fee",
|
444 |
+
"spray",
|
445 |
+
"user",
|
446 |
+
"dirt",
|
447 |
+
"shot",
|
448 |
+
"task",
|
449 |
+
"stick",
|
450 |
+
"friend",
|
451 |
+
"software",
|
452 |
+
"promotion",
|
453 |
+
"interaction",
|
454 |
+
"surround",
|
455 |
+
"block",
|
456 |
+
"purpose",
|
457 |
+
"practice",
|
458 |
+
"conflict",
|
459 |
+
"routine",
|
460 |
+
"requirement",
|
461 |
+
"bonus",
|
462 |
+
"hole",
|
463 |
+
"state",
|
464 |
+
"junior",
|
465 |
+
"sweet",
|
466 |
+
"catch",
|
467 |
+
"tear",
|
468 |
+
"fold",
|
469 |
+
"wall",
|
470 |
+
"editor",
|
471 |
+
"life",
|
472 |
+
"position",
|
473 |
+
"pound",
|
474 |
+
"respect",
|
475 |
+
"bathroom",
|
476 |
+
"coat",
|
477 |
+
"script",
|
478 |
+
"job",
|
479 |
+
"teach",
|
480 |
+
"birth",
|
481 |
+
"view",
|
482 |
+
"resolve",
|
483 |
+
"theme",
|
484 |
+
"employee",
|
485 |
+
"doubt",
|
486 |
+
"market",
|
487 |
+
"education",
|
488 |
+
"serve",
|
489 |
+
"recover",
|
490 |
+
"tone",
|
491 |
+
"harm",
|
492 |
+
"miss",
|
493 |
+
"union",
|
494 |
+
"understanding",
|
495 |
+
"cow",
|
496 |
+
"river",
|
497 |
+
"association",
|
498 |
+
"concept",
|
499 |
+
"training",
|
500 |
+
"recipe",
|
501 |
+
"relationship",
|
502 |
+
"reserve",
|
503 |
+
"depression",
|
504 |
+
"proof",
|
505 |
+
"hair",
|
506 |
+
"revenue",
|
507 |
+
"independent",
|
508 |
+
"lift",
|
509 |
+
"assignment",
|
510 |
+
"temporary",
|
511 |
+
"amount",
|
512 |
+
"loss",
|
513 |
+
"edge",
|
514 |
+
"track",
|
515 |
+
"check",
|
516 |
+
"rope",
|
517 |
+
"estimate",
|
518 |
+
"pollution",
|
519 |
+
"stable",
|
520 |
+
"message",
|
521 |
+
"delivery",
|
522 |
+
"perspective",
|
523 |
+
"mirror",
|
524 |
+
"assistant",
|
525 |
+
"representative",
|
526 |
+
"witness",
|
527 |
+
"nature",
|
528 |
+
"judge",
|
529 |
+
"fruit",
|
530 |
+
"tip",
|
531 |
+
"devil",
|
532 |
+
"town",
|
533 |
+
"emergency",
|
534 |
+
"upper",
|
535 |
+
"drop",
|
536 |
+
"stay",
|
537 |
+
"human",
|
538 |
+
"neck",
|
539 |
+
"speaker",
|
540 |
+
"network",
|
541 |
+
"sing",
|
542 |
+
"resist",
|
543 |
+
"league",
|
544 |
+
"trip",
|
545 |
+
"signature",
|
546 |
+
"lawyer",
|
547 |
+
"importance",
|
548 |
+
"gas",
|
549 |
+
"choice",
|
550 |
+
"engineer",
|
551 |
+
"success",
|
552 |
+
"part",
|
553 |
+
"external",
|
554 |
+
"worker",
|
555 |
+
"simple",
|
556 |
+
"quarter",
|
557 |
+
"student",
|
558 |
+
"heart",
|
559 |
+
"pass",
|
560 |
+
"spite",
|
561 |
+
"shift",
|
562 |
+
"rough",
|
563 |
+
"lady",
|
564 |
+
"grass",
|
565 |
+
"community",
|
566 |
+
"garage",
|
567 |
+
"youth",
|
568 |
+
"standard",
|
569 |
+
"skirt",
|
570 |
+
"promise",
|
571 |
+
"blind",
|
572 |
+
"television",
|
573 |
+
"disease",
|
574 |
+
"commission",
|
575 |
+
"positive",
|
576 |
+
"energy",
|
577 |
+
"calm",
|
578 |
+
"presence",
|
579 |
+
"tune",
|
580 |
+
"basis",
|
581 |
+
"preference",
|
582 |
+
"head",
|
583 |
+
"common",
|
584 |
+
"cut",
|
585 |
+
"somewhere",
|
586 |
+
"presentation",
|
587 |
+
"current",
|
588 |
+
"thought",
|
589 |
+
"revolution",
|
590 |
+
"effort",
|
591 |
+
"master",
|
592 |
+
"implement",
|
593 |
+
"republic",
|
594 |
+
"floor",
|
595 |
+
"principle",
|
596 |
+
"stranger",
|
597 |
+
"shoulder",
|
598 |
+
"grade",
|
599 |
+
"button",
|
600 |
+
"tennis",
|
601 |
+
"police",
|
602 |
+
"collection",
|
603 |
+
"account",
|
604 |
+
"register",
|
605 |
+
"glove",
|
606 |
+
"divide",
|
607 |
+
"professor",
|
608 |
+
"chair",
|
609 |
+
"priority",
|
610 |
+
"combine",
|
611 |
+
"peace",
|
612 |
+
"extension",
|
613 |
+
"maybe",
|
614 |
+
"evening",
|
615 |
+
"frame",
|
616 |
+
"sister",
|
617 |
+
"wave",
|
618 |
+
"code",
|
619 |
+
"application",
|
620 |
+
"mouse",
|
621 |
+
"match",
|
622 |
+
"counter",
|
623 |
+
"bottle",
|
624 |
+
"half",
|
625 |
+
"cheek",
|
626 |
+
"resolution",
|
627 |
+
"back",
|
628 |
+
"knowledge",
|
629 |
+
"make",
|
630 |
+
"discussion",
|
631 |
+
"screw",
|
632 |
+
"length",
|
633 |
+
"accident",
|
634 |
+
"battle",
|
635 |
+
"dress",
|
636 |
+
"knee",
|
637 |
+
"log",
|
638 |
+
"package",
|
639 |
+
"it",
|
640 |
+
"turn",
|
641 |
+
"hearing",
|
642 |
+
"newspaper",
|
643 |
+
"layer",
|
644 |
+
"wealth",
|
645 |
+
"profile",
|
646 |
+
"imagination",
|
647 |
+
"answer",
|
648 |
+
"weekend",
|
649 |
+
"teacher",
|
650 |
+
"appearance",
|
651 |
+
"meet",
|
652 |
+
"bike",
|
653 |
+
"rise",
|
654 |
+
"belt",
|
655 |
+
"crash",
|
656 |
+
"bowl",
|
657 |
+
"equivalent",
|
658 |
+
"support",
|
659 |
+
"image",
|
660 |
+
"poem",
|
661 |
+
"risk",
|
662 |
+
"excitement",
|
663 |
+
"remote",
|
664 |
+
"secretary",
|
665 |
+
"public",
|
666 |
+
"produce",
|
667 |
+
"plane",
|
668 |
+
"display",
|
669 |
+
"money",
|
670 |
+
"sand",
|
671 |
+
"situation",
|
672 |
+
"punch",
|
673 |
+
"customer",
|
674 |
+
"title",
|
675 |
+
"shake",
|
676 |
+
"mortgage",
|
677 |
+
"option",
|
678 |
+
"number",
|
679 |
+
"pop",
|
680 |
+
"window",
|
681 |
+
"extent",
|
682 |
+
"nothing",
|
683 |
+
"experience",
|
684 |
+
"opinion",
|
685 |
+
"departure",
|
686 |
+
"dance",
|
687 |
+
"indication",
|
688 |
+
"boy",
|
689 |
+
"material",
|
690 |
+
"band",
|
691 |
+
"leader",
|
692 |
+
"sun",
|
693 |
+
"beautiful",
|
694 |
+
"muscle",
|
695 |
+
"farmer",
|
696 |
+
"variety",
|
697 |
+
"fat",
|
698 |
+
"handle",
|
699 |
+
"director",
|
700 |
+
"opportunity",
|
701 |
+
"calendar",
|
702 |
+
"outside",
|
703 |
+
"pace",
|
704 |
+
"bath",
|
705 |
+
"fish",
|
706 |
+
"consequence",
|
707 |
+
"put",
|
708 |
+
"owner",
|
709 |
+
"go",
|
710 |
+
"doctor",
|
711 |
+
"information",
|
712 |
+
"share",
|
713 |
+
"hurt",
|
714 |
+
"protection",
|
715 |
+
"career",
|
716 |
+
"finance",
|
717 |
+
"force",
|
718 |
+
"golf",
|
719 |
+
"garbage",
|
720 |
+
"aspect",
|
721 |
+
"kid",
|
722 |
+
"food",
|
723 |
+
"boot",
|
724 |
+
"milk",
|
725 |
+
"respond",
|
726 |
+
"objective",
|
727 |
+
"reality",
|
728 |
+
"raw",
|
729 |
+
"ring",
|
730 |
+
"mall",
|
731 |
+
"one",
|
732 |
+
"impact",
|
733 |
+
"area",
|
734 |
+
"news",
|
735 |
+
"international",
|
736 |
+
"series",
|
737 |
+
"impress",
|
738 |
+
"mother",
|
739 |
+
"shelter",
|
740 |
+
"strike",
|
741 |
+
"loan",
|
742 |
+
"month",
|
743 |
+
"seat",
|
744 |
+
"anything",
|
745 |
+
"entertainment",
|
746 |
+
"familiar",
|
747 |
+
"clue",
|
748 |
+
"year",
|
749 |
+
"glad",
|
750 |
+
"supermarket",
|
751 |
+
"natural",
|
752 |
+
"god",
|
753 |
+
"cost",
|
754 |
+
"conversation",
|
755 |
+
"tie",
|
756 |
+
"ruin",
|
757 |
+
"comfort",
|
758 |
+
"earth",
|
759 |
+
"storm",
|
760 |
+
"percentage",
|
761 |
+
"assistance",
|
762 |
+
"budget",
|
763 |
+
"strength",
|
764 |
+
"beginning",
|
765 |
+
"sleep",
|
766 |
+
"other",
|
767 |
+
"young",
|
768 |
+
"unit",
|
769 |
+
"fill",
|
770 |
+
"store",
|
771 |
+
"desire",
|
772 |
+
"hide",
|
773 |
+
"value",
|
774 |
+
"cup",
|
775 |
+
"maintenance",
|
776 |
+
"nurse",
|
777 |
+
"function",
|
778 |
+
"tower",
|
779 |
+
"role",
|
780 |
+
"class",
|
781 |
+
"camera",
|
782 |
+
"database",
|
783 |
+
"panic",
|
784 |
+
"nation",
|
785 |
+
"basket",
|
786 |
+
"ice",
|
787 |
+
"art",
|
788 |
+
"spirit",
|
789 |
+
"chart",
|
790 |
+
"exchange",
|
791 |
+
"feedback",
|
792 |
+
"statement",
|
793 |
+
"reputation",
|
794 |
+
"search",
|
795 |
+
"hunt",
|
796 |
+
"exercise",
|
797 |
+
"nasty",
|
798 |
+
"notice",
|
799 |
+
"male",
|
800 |
+
"yard",
|
801 |
+
"annual",
|
802 |
+
"collar",
|
803 |
+
"date",
|
804 |
+
"platform",
|
805 |
+
"plant",
|
806 |
+
"fortune",
|
807 |
+
"passion",
|
808 |
+
"friendship",
|
809 |
+
"spread",
|
810 |
+
"cancer",
|
811 |
+
"ticket",
|
812 |
+
"attitude",
|
813 |
+
"island",
|
814 |
+
"active",
|
815 |
+
"object",
|
816 |
+
"service",
|
817 |
+
"buyer",
|
818 |
+
"bite",
|
819 |
+
"card",
|
820 |
+
"face",
|
821 |
+
"steak",
|
822 |
+
"proposal",
|
823 |
+
"patient",
|
824 |
+
"heat",
|
825 |
+
"rule",
|
826 |
+
"resident",
|
827 |
+
"broad",
|
828 |
+
"politics",
|
829 |
+
"west",
|
830 |
+
"knife",
|
831 |
+
"expert",
|
832 |
+
"girl",
|
833 |
+
"design",
|
834 |
+
"salt",
|
835 |
+
"baseball",
|
836 |
+
"grab",
|
837 |
+
"inspection",
|
838 |
+
"cousin",
|
839 |
+
"couple",
|
840 |
+
"magazine",
|
841 |
+
"cook",
|
842 |
+
"dependent",
|
843 |
+
"security",
|
844 |
+
"chicken",
|
845 |
+
"version",
|
846 |
+
"currency",
|
847 |
+
"ladder",
|
848 |
+
"scheme",
|
849 |
+
"kitchen",
|
850 |
+
"employment",
|
851 |
+
"local",
|
852 |
+
"attention",
|
853 |
+
"manager",
|
854 |
+
"fact",
|
855 |
+
"cover",
|
856 |
+
"sad",
|
857 |
+
"guard",
|
858 |
+
"relative",
|
859 |
+
"county",
|
860 |
+
"rate",
|
861 |
+
"lunch",
|
862 |
+
"program",
|
863 |
+
"initiative",
|
864 |
+
"gear",
|
865 |
+
"bridge",
|
866 |
+
"breast",
|
867 |
+
"talk",
|
868 |
+
"dish",
|
869 |
+
"guarantee",
|
870 |
+
"beer",
|
871 |
+
"vehicle",
|
872 |
+
"reception",
|
873 |
+
"woman",
|
874 |
+
"substance",
|
875 |
+
"copy",
|
876 |
+
"lecture",
|
877 |
+
"advantage",
|
878 |
+
"park",
|
879 |
+
"cold",
|
880 |
+
"death",
|
881 |
+
"mix",
|
882 |
+
"hold",
|
883 |
+
"scale",
|
884 |
+
"tomorrow",
|
885 |
+
"blood",
|
886 |
+
"request",
|
887 |
+
"green",
|
888 |
+
"cookie",
|
889 |
+
"church",
|
890 |
+
"strip",
|
891 |
+
"forever",
|
892 |
+
"beyond",
|
893 |
+
"debt",
|
894 |
+
"tackle",
|
895 |
+
"wash",
|
896 |
+
"following",
|
897 |
+
"feel",
|
898 |
+
"maximum",
|
899 |
+
"sector",
|
900 |
+
"sea",
|
901 |
+
"property",
|
902 |
+
"economics",
|
903 |
+
"menu",
|
904 |
+
"bench",
|
905 |
+
"try",
|
906 |
+
"language",
|
907 |
+
"start",
|
908 |
+
"call",
|
909 |
+
"solid",
|
910 |
+
"address",
|
911 |
+
"income",
|
912 |
+
"foot",
|
913 |
+
"senior",
|
914 |
+
"honey",
|
915 |
+
"few",
|
916 |
+
"mixture",
|
917 |
+
"cash",
|
918 |
+
"grocery",
|
919 |
+
"link",
|
920 |
+
"map",
|
921 |
+
"form",
|
922 |
+
"factor",
|
923 |
+
"pot",
|
924 |
+
"model",
|
925 |
+
"writer",
|
926 |
+
"farm",
|
927 |
+
"winter",
|
928 |
+
"skill",
|
929 |
+
"anywhere",
|
930 |
+
"birthday",
|
931 |
+
"policy",
|
932 |
+
"release",
|
933 |
+
"husband",
|
934 |
+
"lab",
|
935 |
+
"hurry",
|
936 |
+
"mail",
|
937 |
+
"equipment",
|
938 |
+
"sink",
|
939 |
+
"pair",
|
940 |
+
"driver",
|
941 |
+
"consideration",
|
942 |
+
"leather",
|
943 |
+
"skin",
|
944 |
+
"blue",
|
945 |
+
"boat",
|
946 |
+
"sale",
|
947 |
+
"brick",
|
948 |
+
"two",
|
949 |
+
"feed",
|
950 |
+
"square",
|
951 |
+
"dot",
|
952 |
+
"rush",
|
953 |
+
"dream",
|
954 |
+
"location",
|
955 |
+
"afternoon",
|
956 |
+
"manufacturer",
|
957 |
+
"control",
|
958 |
+
"occasion",
|
959 |
+
"trouble",
|
960 |
+
"introduction",
|
961 |
+
"advice",
|
962 |
+
"bet",
|
963 |
+
"eat",
|
964 |
+
"kill",
|
965 |
+
"category",
|
966 |
+
"manner",
|
967 |
+
"office",
|
968 |
+
"estate",
|
969 |
+
"pride",
|
970 |
+
"awareness",
|
971 |
+
"slip",
|
972 |
+
"crack",
|
973 |
+
"client",
|
974 |
+
"nail",
|
975 |
+
"shoot",
|
976 |
+
"membership",
|
977 |
+
"soft",
|
978 |
+
"anybody",
|
979 |
+
"web",
|
980 |
+
"official",
|
981 |
+
"individual",
|
982 |
+
"pizza",
|
983 |
+
"interest",
|
984 |
+
"bag",
|
985 |
+
"spell",
|
986 |
+
"profession",
|
987 |
+
"queen",
|
988 |
+
"deal",
|
989 |
+
"resource",
|
990 |
+
"ship",
|
991 |
+
"guy",
|
992 |
+
"chocolate",
|
993 |
+
"joint",
|
994 |
+
"formal",
|
995 |
+
"upstairs",
|
996 |
+
"car",
|
997 |
+
"resort",
|
998 |
+
"abroad",
|
999 |
+
"dealer",
|
1000 |
+
"associate",
|
1001 |
+
"finger",
|
1002 |
+
"surgery",
|
1003 |
+
"comment",
|
1004 |
+
"team",
|
1005 |
+
"detail",
|
1006 |
+
"crazy",
|
1007 |
+
"path",
|
1008 |
+
"tale",
|
1009 |
+
"initial",
|
1010 |
+
"arm",
|
1011 |
+
"radio",
|
1012 |
+
"demand",
|
1013 |
+
"single",
|
1014 |
+
"draw",
|
1015 |
+
"yellow",
|
1016 |
+
"contest",
|
1017 |
+
"piece",
|
1018 |
+
"quote",
|
1019 |
+
"pull",
|
1020 |
+
"commercial",
|
1021 |
+
"shirt",
|
1022 |
+
"contribution",
|
1023 |
+
"cream",
|
1024 |
+
"channel",
|
1025 |
+
"suit",
|
1026 |
+
"discipline",
|
1027 |
+
"instruction",
|
1028 |
+
"concert",
|
1029 |
+
"speech",
|
1030 |
+
"low",
|
1031 |
+
"effective",
|
1032 |
+
"hang",
|
1033 |
+
"scratch",
|
1034 |
+
"industry",
|
1035 |
+
"breakfast",
|
1036 |
+
"lay",
|
1037 |
+
"join",
|
1038 |
+
"metal",
|
1039 |
+
"bedroom",
|
1040 |
+
"minute",
|
1041 |
+
"product",
|
1042 |
+
"rest",
|
1043 |
+
"temperature",
|
1044 |
+
"many",
|
1045 |
+
"give",
|
1046 |
+
"argument",
|
1047 |
+
"print",
|
1048 |
+
"purple",
|
1049 |
+
"laugh",
|
1050 |
+
"health",
|
1051 |
+
"credit",
|
1052 |
+
"investment",
|
1053 |
+
"sell",
|
1054 |
+
"setting",
|
1055 |
+
"lesson",
|
1056 |
+
"egg",
|
1057 |
+
"middle",
|
1058 |
+
"marriage",
|
1059 |
+
"level",
|
1060 |
+
"evidence",
|
1061 |
+
"phrase",
|
1062 |
+
"love",
|
1063 |
+
"self",
|
1064 |
+
"benefit",
|
1065 |
+
"guidance",
|
1066 |
+
"affect",
|
1067 |
+
"you",
|
1068 |
+
"dad",
|
1069 |
+
"anxiety",
|
1070 |
+
"special",
|
1071 |
+
"boyfriend",
|
1072 |
+
"test",
|
1073 |
+
"blank",
|
1074 |
+
"payment",
|
1075 |
+
"soup",
|
1076 |
+
"obligation",
|
1077 |
+
"reply",
|
1078 |
+
"smile",
|
1079 |
+
"deep",
|
1080 |
+
"complaint",
|
1081 |
+
"addition",
|
1082 |
+
"review",
|
1083 |
+
"box",
|
1084 |
+
"towel",
|
1085 |
+
"minor",
|
1086 |
+
"fun",
|
1087 |
+
"soil",
|
1088 |
+
"issue",
|
1089 |
+
"cigarette",
|
1090 |
+
"internet",
|
1091 |
+
"gain",
|
1092 |
+
"tell",
|
1093 |
+
"entry",
|
1094 |
+
"spare",
|
1095 |
+
"incident",
|
1096 |
+
"family",
|
1097 |
+
"refuse",
|
1098 |
+
"branch",
|
1099 |
+
"can",
|
1100 |
+
"pen",
|
1101 |
+
"grandfather",
|
1102 |
+
"constant",
|
1103 |
+
"tank",
|
1104 |
+
"uncle",
|
1105 |
+
"climate",
|
1106 |
+
"ground",
|
1107 |
+
"volume",
|
1108 |
+
"communication",
|
1109 |
+
"kind",
|
1110 |
+
"poet",
|
1111 |
+
"child",
|
1112 |
+
"screen",
|
1113 |
+
"mine",
|
1114 |
+
"quit",
|
1115 |
+
"gene",
|
1116 |
+
"lack",
|
1117 |
+
"charity",
|
1118 |
+
"memory",
|
1119 |
+
"tooth",
|
1120 |
+
"fear",
|
1121 |
+
"mention",
|
1122 |
+
"marketing",
|
1123 |
+
"reveal",
|
1124 |
+
"reason",
|
1125 |
+
"court",
|
1126 |
+
"season",
|
1127 |
+
"freedom",
|
1128 |
+
"land",
|
1129 |
+
"sport",
|
1130 |
+
"audience",
|
1131 |
+
"classroom",
|
1132 |
+
"law",
|
1133 |
+
"hook",
|
1134 |
+
"win",
|
1135 |
+
"carry",
|
1136 |
+
"eye",
|
1137 |
+
"smell",
|
1138 |
+
"distribution",
|
1139 |
+
"research",
|
1140 |
+
"country",
|
1141 |
+
"dare",
|
1142 |
+
"hope",
|
1143 |
+
"whereas",
|
1144 |
+
"stretch",
|
1145 |
+
"library",
|
1146 |
+
"if",
|
1147 |
+
"delay",
|
1148 |
+
"college",
|
1149 |
+
"plastic",
|
1150 |
+
"book",
|
1151 |
+
"present",
|
1152 |
+
"use",
|
1153 |
+
"worry",
|
1154 |
+
"champion",
|
1155 |
+
"goal",
|
1156 |
+
"economy",
|
1157 |
+
"march",
|
1158 |
+
"election",
|
1159 |
+
"reflection",
|
1160 |
+
"midnight",
|
1161 |
+
"slide",
|
1162 |
+
"inflation",
|
1163 |
+
"action",
|
1164 |
+
"challenge",
|
1165 |
+
"guitar",
|
1166 |
+
"coast",
|
1167 |
+
"apple",
|
1168 |
+
"campaign",
|
1169 |
+
"field",
|
1170 |
+
"jacket",
|
1171 |
+
"sense",
|
1172 |
+
"way",
|
1173 |
+
"visual",
|
1174 |
+
"remove",
|
1175 |
+
"weather",
|
1176 |
+
"trash",
|
1177 |
+
"cable",
|
1178 |
+
"regret",
|
1179 |
+
"buddy",
|
1180 |
+
"beach",
|
1181 |
+
"historian",
|
1182 |
+
"courage",
|
1183 |
+
"sympathy",
|
1184 |
+
"truck",
|
1185 |
+
"tension",
|
1186 |
+
"permit",
|
1187 |
+
"nose",
|
1188 |
+
"bed",
|
1189 |
+
"son",
|
1190 |
+
"person",
|
1191 |
+
"base",
|
1192 |
+
"meat",
|
1193 |
+
"usual",
|
1194 |
+
"air",
|
1195 |
+
"meeting",
|
1196 |
+
"worth",
|
1197 |
+
"game",
|
1198 |
+
"independence",
|
1199 |
+
"physical",
|
1200 |
+
"brief",
|
1201 |
+
"play",
|
1202 |
+
"raise",
|
1203 |
+
"board",
|
1204 |
+
"she",
|
1205 |
+
"key",
|
1206 |
+
"writing",
|
1207 |
+
"pick",
|
1208 |
+
"command",
|
1209 |
+
"party",
|
1210 |
+
"yesterday",
|
1211 |
+
"spring",
|
1212 |
+
"candidate",
|
1213 |
+
"physics",
|
1214 |
+
"university",
|
1215 |
+
"concern",
|
1216 |
+
"development",
|
1217 |
+
"change",
|
1218 |
+
"string",
|
1219 |
+
"target",
|
1220 |
+
"instance",
|
1221 |
+
"room",
|
1222 |
+
"bitter",
|
1223 |
+
"bird",
|
1224 |
+
"football",
|
1225 |
+
"normal",
|
1226 |
+
"split",
|
1227 |
+
"impression",
|
1228 |
+
"wood",
|
1229 |
+
"long",
|
1230 |
+
"meaning",
|
1231 |
+
"stock",
|
1232 |
+
"cap",
|
1233 |
+
"leadership",
|
1234 |
+
"media",
|
1235 |
+
"ambition",
|
1236 |
+
"fishing",
|
1237 |
+
"essay",
|
1238 |
+
"salad",
|
1239 |
+
"repair",
|
1240 |
+
"today",
|
1241 |
+
"designer",
|
1242 |
+
"night",
|
1243 |
+
"bank",
|
1244 |
+
"drawing",
|
1245 |
+
"inevitable",
|
1246 |
+
"phase",
|
1247 |
+
"vast",
|
1248 |
+
"chip",
|
1249 |
+
"anger",
|
1250 |
+
"switch",
|
1251 |
+
"cry",
|
1252 |
+
"twist",
|
1253 |
+
"personality",
|
1254 |
+
"attempt",
|
1255 |
+
"storage",
|
1256 |
+
"being",
|
1257 |
+
"preparation",
|
1258 |
+
"bat",
|
1259 |
+
"selection",
|
1260 |
+
"white",
|
1261 |
+
"technology",
|
1262 |
+
"contract",
|
1263 |
+
"side",
|
1264 |
+
"section",
|
1265 |
+
"station",
|
1266 |
+
"till",
|
1267 |
+
"structure",
|
1268 |
+
"tongue",
|
1269 |
+
"taste",
|
1270 |
+
"truth",
|
1271 |
+
"difficulty",
|
1272 |
+
"group",
|
1273 |
+
"limit",
|
1274 |
+
"main",
|
1275 |
+
"move",
|
1276 |
+
"feeling",
|
1277 |
+
"light",
|
1278 |
+
"example",
|
1279 |
+
"mission",
|
1280 |
+
"might",
|
1281 |
+
"wait",
|
1282 |
+
"wheel",
|
1283 |
+
"shop",
|
1284 |
+
"host",
|
1285 |
+
"classic",
|
1286 |
+
"alternative",
|
1287 |
+
"cause",
|
1288 |
+
"agent",
|
1289 |
+
"consist",
|
1290 |
+
"table",
|
1291 |
+
"airline",
|
1292 |
+
"text",
|
1293 |
+
"pool",
|
1294 |
+
"craft",
|
1295 |
+
"range",
|
1296 |
+
"fuel",
|
1297 |
+
"tool",
|
1298 |
+
"partner",
|
1299 |
+
"load",
|
1300 |
+
"entrance",
|
1301 |
+
"deposit",
|
1302 |
+
"hate",
|
1303 |
+
"article",
|
1304 |
+
"video",
|
1305 |
+
"summer",
|
1306 |
+
"feature",
|
1307 |
+
"extreme",
|
1308 |
+
"mobile",
|
1309 |
+
"hospital",
|
1310 |
+
"flight",
|
1311 |
+
"fall",
|
1312 |
+
"pension",
|
1313 |
+
"piano",
|
1314 |
+
"fail",
|
1315 |
+
"result",
|
1316 |
+
"rub",
|
1317 |
+
"gap",
|
1318 |
+
"system",
|
1319 |
+
"report",
|
1320 |
+
"suck",
|
1321 |
+
"ordinary",
|
1322 |
+
"wind",
|
1323 |
+
"nerve",
|
1324 |
+
"ask",
|
1325 |
+
"shine",
|
1326 |
+
"note",
|
1327 |
+
"line",
|
1328 |
+
"mom",
|
1329 |
+
"perception",
|
1330 |
+
"brother",
|
1331 |
+
"reference",
|
1332 |
+
"bend",
|
1333 |
+
"charge",
|
1334 |
+
"treat",
|
1335 |
+
"trick",
|
1336 |
+
"term",
|
1337 |
+
"homework",
|
1338 |
+
"bake",
|
1339 |
+
"bid",
|
1340 |
+
"status",
|
1341 |
+
"project",
|
1342 |
+
"strategy",
|
1343 |
+
"orange",
|
1344 |
+
"let",
|
1345 |
+
"enthusiasm",
|
1346 |
+
"parent",
|
1347 |
+
"concentrate",
|
1348 |
+
"device",
|
1349 |
+
"travel",
|
1350 |
+
"poetry",
|
1351 |
+
"business",
|
1352 |
+
"society",
|
1353 |
+
"kiss",
|
1354 |
+
"end",
|
1355 |
+
"vegetable",
|
1356 |
+
"employ",
|
1357 |
+
"schedule",
|
1358 |
+
"hour",
|
1359 |
+
"brave",
|
1360 |
+
"focus",
|
1361 |
+
"process",
|
1362 |
+
"movie",
|
1363 |
+
"illegal",
|
1364 |
+
"general",
|
1365 |
+
"coffee",
|
1366 |
+
"ad",
|
1367 |
+
"highway",
|
1368 |
+
"chemistry",
|
1369 |
+
"psychology",
|
1370 |
+
"hire",
|
1371 |
+
"bell",
|
1372 |
+
"conference",
|
1373 |
+
"relief",
|
1374 |
+
"show",
|
1375 |
+
"neat",
|
1376 |
+
"funny",
|
1377 |
+
"weight",
|
1378 |
+
"quality",
|
1379 |
+
"club",
|
1380 |
+
"daughter",
|
1381 |
+
"zone",
|
1382 |
+
"touch",
|
1383 |
+
"tonight",
|
1384 |
+
"shock",
|
1385 |
+
"burn",
|
1386 |
+
"excuse",
|
1387 |
+
"name",
|
1388 |
+
"survey",
|
1389 |
+
"landscape",
|
1390 |
+
"advance",
|
1391 |
+
"satisfaction",
|
1392 |
+
"bread",
|
1393 |
+
"disaster",
|
1394 |
+
"item",
|
1395 |
+
"hat",
|
1396 |
+
"prior",
|
1397 |
+
"shopping",
|
1398 |
+
"visit",
|
1399 |
+
"east",
|
1400 |
+
"photo",
|
1401 |
+
"home",
|
1402 |
+
"idea",
|
1403 |
+
"father",
|
1404 |
+
"comparison",
|
1405 |
+
"cat",
|
1406 |
+
"pipe",
|
1407 |
+
"winner",
|
1408 |
+
"count",
|
1409 |
+
"lake",
|
1410 |
+
"fight",
|
1411 |
+
"prize",
|
1412 |
+
"foundation",
|
1413 |
+
"dog",
|
1414 |
+
"keep",
|
1415 |
+
"ideal",
|
1416 |
+
"fan",
|
1417 |
+
"struggle",
|
1418 |
+
"peak",
|
1419 |
+
"safety",
|
1420 |
+
"solution",
|
1421 |
+
"hell",
|
1422 |
+
"conclusion",
|
1423 |
+
"population",
|
1424 |
+
"strain",
|
1425 |
+
"alarm",
|
1426 |
+
"measurement",
|
1427 |
+
"second",
|
1428 |
+
"train",
|
1429 |
+
"race",
|
1430 |
+
"due",
|
1431 |
+
"insurance",
|
1432 |
+
"boss",
|
1433 |
+
"tree",
|
1434 |
+
"monitor",
|
1435 |
+
"sick",
|
1436 |
+
"course",
|
1437 |
+
"drag",
|
1438 |
+
"appointment",
|
1439 |
+
"slice",
|
1440 |
+
"still",
|
1441 |
+
"care",
|
1442 |
+
"patience",
|
1443 |
+
"rich",
|
1444 |
+
"escape",
|
1445 |
+
"emotion",
|
1446 |
+
"royal",
|
1447 |
+
"female",
|
1448 |
+
"childhood",
|
1449 |
+
"government",
|
1450 |
+
"picture",
|
1451 |
+
"will",
|
1452 |
+
"sock",
|
1453 |
+
"big",
|
1454 |
+
"gate",
|
1455 |
+
"oil",
|
1456 |
+
"cross",
|
1457 |
+
"pin",
|
1458 |
+
"improvement",
|
1459 |
+
"championship",
|
1460 |
+
"silly",
|
1461 |
+
"help",
|
1462 |
+
"sky",
|
1463 |
+
"pitch",
|
1464 |
+
"man",
|
1465 |
+
"diamond",
|
1466 |
+
"most",
|
1467 |
+
"transition",
|
1468 |
+
"work",
|
1469 |
+
"science",
|
1470 |
+
"committee",
|
1471 |
+
"moment",
|
1472 |
+
"fix",
|
1473 |
+
"teaching",
|
1474 |
+
"dig",
|
1475 |
+
"specialist",
|
1476 |
+
"complex",
|
1477 |
+
"guide",
|
1478 |
+
"people",
|
1479 |
+
"dead",
|
1480 |
+
"voice",
|
1481 |
+
"original",
|
1482 |
+
"break",
|
1483 |
+
"topic",
|
1484 |
+
"data",
|
1485 |
+
"degree",
|
1486 |
+
"reading",
|
1487 |
+
"recording",
|
1488 |
+
"bunch",
|
1489 |
+
"reach",
|
1490 |
+
"judgment",
|
1491 |
+
"lie",
|
1492 |
+
"regular",
|
1493 |
+
"set",
|
1494 |
+
"painting",
|
1495 |
+
"mode",
|
1496 |
+
"list",
|
1497 |
+
"player",
|
1498 |
+
"bear",
|
1499 |
+
"north",
|
1500 |
+
"wonder",
|
1501 |
+
"carpet",
|
1502 |
+
"heavy",
|
1503 |
+
"officer",
|
1504 |
+
"negative",
|
1505 |
+
"clock",
|
1506 |
+
"unique",
|
1507 |
+
"baby",
|
1508 |
+
"pain",
|
1509 |
+
"assumption",
|
1510 |
+
"disk",
|
1511 |
+
"iron",
|
1512 |
+
"bill",
|
1513 |
+
"drawer",
|
1514 |
+
"look",
|
1515 |
+
"double",
|
1516 |
+
"mistake",
|
1517 |
+
"finish",
|
1518 |
+
"future",
|
1519 |
+
"brilliant",
|
1520 |
+
"contact",
|
1521 |
+
"math",
|
1522 |
+
"rice",
|
1523 |
+
"leave",
|
1524 |
+
"restaurant",
|
1525 |
+
"discount",
|
1526 |
+
"sex",
|
1527 |
+
"virus",
|
1528 |
+
"bit",
|
1529 |
+
"trust",
|
1530 |
+
"event",
|
1531 |
+
"wear",
|
1532 |
+
"juice",
|
1533 |
+
"failure",
|
1534 |
+
"bug",
|
1535 |
+
"context",
|
1536 |
+
"mud",
|
1537 |
+
"whole",
|
1538 |
+
"wrap",
|
1539 |
+
"intention",
|
1540 |
+
"draft",
|
1541 |
+
"pressure",
|
1542 |
+
"cake",
|
1543 |
+
"dark",
|
1544 |
+
"explanation",
|
1545 |
+
"space",
|
1546 |
+
"angle",
|
1547 |
+
"word",
|
1548 |
+
"efficiency",
|
1549 |
+
"management",
|
1550 |
+
"habit",
|
1551 |
+
"star",
|
1552 |
+
"chance",
|
1553 |
+
"finding",
|
1554 |
+
"transportation",
|
1555 |
+
"stand",
|
1556 |
+
"criticism",
|
1557 |
+
"flow",
|
1558 |
+
"door",
|
1559 |
+
"injury",
|
1560 |
+
"insect",
|
1561 |
+
"surprise",
|
1562 |
+
"apartment",
|
1563 |
+
] # pylint: disable=line-too-long
|
1564 |
+
|
1565 |
+
# ISO 639-1 codes to language names.
|
1566 |
+
LANGUAGE_CODES = immutabledict.immutabledict(
|
1567 |
+
{
|
1568 |
+
"en": "English",
|
1569 |
+
"es": "Spanish",
|
1570 |
+
"pt": "Portuguese",
|
1571 |
+
"ar": "Arabic",
|
1572 |
+
"hi": "Hindi",
|
1573 |
+
"fr": "French",
|
1574 |
+
"ru": "Russian",
|
1575 |
+
"de": "German",
|
1576 |
+
"ja": "Japanese",
|
1577 |
+
"it": "Italian",
|
1578 |
+
"bn": "Bengali",
|
1579 |
+
"uk": "Ukrainian",
|
1580 |
+
"th": "Thai",
|
1581 |
+
"ur": "Urdu",
|
1582 |
+
"ta": "Tamil",
|
1583 |
+
"te": "Telugu",
|
1584 |
+
"bg": "Bulgarian",
|
1585 |
+
"ko": "Korean",
|
1586 |
+
"pl": "Polish",
|
1587 |
+
"he": "Hebrew",
|
1588 |
+
"fa": "Persian",
|
1589 |
+
"vi": "Vietnamese",
|
1590 |
+
"ne": "Nepali",
|
1591 |
+
"sw": "Swahili",
|
1592 |
+
"kn": "Kannada",
|
1593 |
+
"mr": "Marathi",
|
1594 |
+
"gu": "Gujarati",
|
1595 |
+
"pa": "Punjabi",
|
1596 |
+
"ml": "Malayalam",
|
1597 |
+
"fi": "Finnish",
|
1598 |
+
}
|
1599 |
+
)
|
1600 |
+
|
1601 |
+
_ALPHABETS = "([A-Za-z])"
|
1602 |
+
_PREFIXES = "(Mr|St|Mrs|Ms|Dr)[.]"
|
1603 |
+
_SUFFIXES = "(Inc|Ltd|Jr|Sr|Co)"
|
1604 |
+
_STARTERS = r"(Mr|Mrs|Ms|Dr|Prof|Capt|Cpt|Lt|He\s|She\s|It\s|They\s|Their\s|Our\s|We\s|But\s|However\s|That\s|This\s|Wherever)"
|
1605 |
+
_ACRONYMS = "([A-Z][.][A-Z][.](?:[A-Z][.])?)"
|
1606 |
+
_WEBSITES = "[.](com|net|org|io|gov|edu|me)"
|
1607 |
+
_DIGITS = "([0-9])"
|
1608 |
+
_MULTIPLE_DOTS = r"\.{2,}"
|
1609 |
+
|
1610 |
+
|
1611 |
+
def split_into_sentences(text):
|
1612 |
+
"""Split the text into sentences.
|
1613 |
+
|
1614 |
+
Args:
|
1615 |
+
text: A string that consists of more than or equal to one sentences.
|
1616 |
+
|
1617 |
+
Returns:
|
1618 |
+
A list of strings where each string is a sentence.
|
1619 |
+
"""
|
1620 |
+
text = " " + text + " "
|
1621 |
+
text = text.replace("\n", " ")
|
1622 |
+
text = re.sub(_PREFIXES, "\\1<prd>", text)
|
1623 |
+
text = re.sub(_WEBSITES, "<prd>\\1", text)
|
1624 |
+
text = re.sub(_DIGITS + "[.]" + _DIGITS, "\\1<prd>\\2", text)
|
1625 |
+
text = re.sub(
|
1626 |
+
_MULTIPLE_DOTS,
|
1627 |
+
lambda match: "<prd>" * len(match.group(0)) + "<stop>",
|
1628 |
+
text,
|
1629 |
+
)
|
1630 |
+
if "Ph.D" in text:
|
1631 |
+
text = text.replace("Ph.D.", "Ph<prd>D<prd>")
|
1632 |
+
text = re.sub(r"\s" + _ALPHABETS + "[.] ", " \\1<prd> ", text)
|
1633 |
+
text = re.sub(_ACRONYMS + " " + _STARTERS, "\\1<stop> \\2", text)
|
1634 |
+
text = re.sub(
|
1635 |
+
_ALPHABETS + "[.]" + _ALPHABETS + "[.]" + _ALPHABETS + "[.]",
|
1636 |
+
"\\1<prd>\\2<prd>\\3<prd>",
|
1637 |
+
text,
|
1638 |
+
)
|
1639 |
+
text = re.sub(_ALPHABETS + "[.]" + _ALPHABETS + "[.]", "\\1<prd>\\2<prd>", text)
|
1640 |
+
text = re.sub(" " + _SUFFIXES + "[.] " + _STARTERS, " \\1<stop> \\2", text)
|
1641 |
+
text = re.sub(" " + _SUFFIXES + "[.]", " \\1<prd>", text)
|
1642 |
+
text = re.sub(" " + _ALPHABETS + "[.]", " \\1<prd>", text)
|
1643 |
+
if "”" in text:
|
1644 |
+
text = text.replace(".”", "”.")
|
1645 |
+
if '"' in text:
|
1646 |
+
text = text.replace('."', '".')
|
1647 |
+
if "!" in text:
|
1648 |
+
text = text.replace('!"', '"!')
|
1649 |
+
if "?" in text:
|
1650 |
+
text = text.replace('?"', '"?')
|
1651 |
+
text = text.replace(".", ".<stop>")
|
1652 |
+
text = text.replace("?", "?<stop>")
|
1653 |
+
text = text.replace("!", "!<stop>")
|
1654 |
+
text = text.replace("<prd>", ".")
|
1655 |
+
sentences = text.split("<stop>")
|
1656 |
+
sentences = [s.strip() for s in sentences]
|
1657 |
+
if sentences and not sentences[-1]:
|
1658 |
+
sentences = sentences[:-1]
|
1659 |
+
return sentences
|
1660 |
+
|
1661 |
+
|
1662 |
+
def count_words(text):
|
1663 |
+
"""Counts the number of words."""
|
1664 |
+
tokenizer = nltk.tokenize.RegexpTokenizer(r"\w+")
|
1665 |
+
tokens = tokenizer.tokenize(text)
|
1666 |
+
num_words = len(tokens)
|
1667 |
+
return num_words
|
1668 |
+
|
1669 |
+
|
1670 |
+
@functools.lru_cache(maxsize=None)
|
1671 |
+
def _get_sentence_tokenizer():
|
1672 |
+
return nltk.data.load("nltk:tokenizers/punkt/english.pickle")
|
1673 |
+
|
1674 |
+
|
1675 |
+
def count_sentences(text):
|
1676 |
+
"""Count the number of sentences."""
|
1677 |
+
tokenizer = _get_sentence_tokenizer()
|
1678 |
+
tokenized_sentences = tokenizer.tokenize(text)
|
1679 |
+
return len(tokenized_sentences)
|
1680 |
+
|
1681 |
+
|
1682 |
+
def generate_keywords(num_keywords):
|
1683 |
+
"""Randomly generates a few keywords."""
|
1684 |
+
return random.sample(WORD_LIST, k=num_keywords)
|
src/backend/tasks/ifeval/utils.py
ADDED
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import dataclasses
|
2 |
+
from typing import Dict, Optional, Union
|
3 |
+
|
4 |
+
from lm_eval.tasks.ifeval import instructions_registry
|
5 |
+
|
6 |
+
|
7 |
+
@dataclasses.dataclass
|
8 |
+
class InputExample:
|
9 |
+
key: int
|
10 |
+
instruction_id_list: list[str]
|
11 |
+
prompt: str
|
12 |
+
kwargs: list[Dict[str, Optional[Union[str, int]]]]
|
13 |
+
|
14 |
+
|
15 |
+
@dataclasses.dataclass
|
16 |
+
class OutputExample:
|
17 |
+
instruction_id_list: list[str]
|
18 |
+
prompt: str
|
19 |
+
response: str
|
20 |
+
follow_all_instructions: bool
|
21 |
+
follow_instruction_list: list[bool]
|
22 |
+
|
23 |
+
|
24 |
+
def test_instruction_following_strict(
|
25 |
+
inp,
|
26 |
+
response,
|
27 |
+
):
|
28 |
+
"""Tests response to see if instructions are followed."""
|
29 |
+
instruction_list = inp.instruction_id_list
|
30 |
+
is_following_list = []
|
31 |
+
|
32 |
+
for index, instruction_id in enumerate(instruction_list):
|
33 |
+
instruction_cls = instructions_registry.INSTRUCTION_DICT[instruction_id]
|
34 |
+
instruction = instruction_cls(instruction_id)
|
35 |
+
|
36 |
+
# Remove None values from kwargs to avoid unexpected keyword argument errors in build_description method.
|
37 |
+
kwargs = {k: v for k, v in inp.kwargs[index].items() if v}
|
38 |
+
instruction.build_description(**kwargs)
|
39 |
+
args = instruction.get_instruction_args()
|
40 |
+
if args and "prompt" in args:
|
41 |
+
instruction.build_description(prompt=inp.prompt)
|
42 |
+
|
43 |
+
if response.strip() and instruction.check_following(response):
|
44 |
+
is_following_list.append(True)
|
45 |
+
else:
|
46 |
+
is_following_list.append(False)
|
47 |
+
|
48 |
+
return OutputExample(
|
49 |
+
instruction_id_list=inp.instruction_id_list,
|
50 |
+
prompt=inp.prompt,
|
51 |
+
response=response,
|
52 |
+
follow_all_instructions=all(is_following_list),
|
53 |
+
follow_instruction_list=is_following_list,
|
54 |
+
)
|
55 |
+
|
56 |
+
|
57 |
+
def test_instruction_following_loose(
|
58 |
+
inp,
|
59 |
+
response,
|
60 |
+
):
|
61 |
+
"""Tests response for an upper bound for following instructions."""
|
62 |
+
r = response.split("\n")
|
63 |
+
response_remove_first = "\n".join(r[1:]).strip()
|
64 |
+
response_remove_last = "\n".join(r[:-1]).strip()
|
65 |
+
response_remove_both = "\n".join(r[1:-1]).strip()
|
66 |
+
revised_response = response.replace("*", "")
|
67 |
+
revised_response_remove_first = response_remove_first.replace("*", "")
|
68 |
+
revised_response_remove_last = response_remove_last.replace("*", "")
|
69 |
+
revised_response_remove_both = response_remove_both.replace("*", "")
|
70 |
+
all_responses = [
|
71 |
+
response,
|
72 |
+
revised_response,
|
73 |
+
response_remove_first,
|
74 |
+
response_remove_last,
|
75 |
+
response_remove_both,
|
76 |
+
revised_response_remove_first,
|
77 |
+
revised_response_remove_last,
|
78 |
+
revised_response_remove_both,
|
79 |
+
]
|
80 |
+
instruction_list = inp.instruction_id_list
|
81 |
+
is_following_list = []
|
82 |
+
|
83 |
+
for index, instruction_id in enumerate(instruction_list):
|
84 |
+
instruction_cls = instructions_registry.INSTRUCTION_DICT[instruction_id]
|
85 |
+
instruction = instruction_cls(instruction_id)
|
86 |
+
|
87 |
+
# Remove None values from kwargs to avoid unexpected keyword argument errors in build_description method.
|
88 |
+
kwargs = {k: v for k, v in inp.kwargs[index].items() if v}
|
89 |
+
instruction.build_description(**kwargs)
|
90 |
+
args = instruction.get_instruction_args()
|
91 |
+
if args and "prompt" in args:
|
92 |
+
instruction.build_description(prompt=inp.prompt)
|
93 |
+
|
94 |
+
is_following = False
|
95 |
+
for r in all_responses:
|
96 |
+
if r.strip() and instruction.check_following(r):
|
97 |
+
is_following = True
|
98 |
+
break
|
99 |
+
|
100 |
+
is_following_list.append(is_following)
|
101 |
+
|
102 |
+
return OutputExample(
|
103 |
+
instruction_id_list=inp.instruction_id_list,
|
104 |
+
prompt=inp.prompt,
|
105 |
+
response=response,
|
106 |
+
follow_all_instructions=all(is_following_list),
|
107 |
+
follow_instruction_list=is_following_list,
|
108 |
+
)
|
109 |
+
|
110 |
+
|
111 |
+
def process_results(doc, results):
|
112 |
+
inp = InputExample(
|
113 |
+
key=doc["key"],
|
114 |
+
instruction_id_list=doc["instruction_id_list"],
|
115 |
+
prompt=doc["prompt"],
|
116 |
+
kwargs=doc["kwargs"],
|
117 |
+
)
|
118 |
+
response = results[0]
|
119 |
+
|
120 |
+
out_strict = test_instruction_following_strict(inp, response)
|
121 |
+
out_loose = test_instruction_following_loose(inp, response)
|
122 |
+
|
123 |
+
return {
|
124 |
+
"prompt_level_strict_acc": out_strict.follow_all_instructions,
|
125 |
+
"inst_level_strict_acc": out_strict.follow_instruction_list,
|
126 |
+
"prompt_level_loose_acc": out_loose.follow_all_instructions,
|
127 |
+
"inst_level_loose_acc": out_loose.follow_instruction_list,
|
128 |
+
}
|
129 |
+
|
130 |
+
|
131 |
+
def agg_inst_level_acc(items):
|
132 |
+
flat_items = [item for sublist in items for item in sublist]
|
133 |
+
inst_level_acc = sum(flat_items) / len(flat_items)
|
134 |
+
return inst_level_acc
|