Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generator progress bar #337

Merged
merged 15 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions prompt2model/dataset_generator/prompt_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,16 +449,18 @@ def generate_dataset_split(
handle_api_error(e)

# Extract the responses and add new examples to the dataset.
prev_length = len(generated_examples)
self.extract_and_append_responses(responses, all_generated_examples)
generated_examples = (
self.apply_multi_vote_filtering(all_generated_examples)
if self.filter_duplicated_examples
else all_generated_examples
)
if len(generated_examples) >= num_examples:
generated_examples = generated_examples[:num_examples]

pbar.update(len(generated_examples))
pbar.update(len(generated_examples) - prev_length)

if len(generated_examples) >= num_examples:
generated_examples = generated_examples[:num_examples]

return Dataset.from_dict(
{
Expand Down
15 changes: 8 additions & 7 deletions prompt2model/dataset_retriever/description_dataset_retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ def initialize_search_index(self) -> None:
"Search index must either be a valid file or not exist yet. "
"But {self.search_index_path} is provided."
)
logger.info("Creating dataset descriptions")
encode_text(
self.encoder_model_name,
text_to_encode=[x.description for x in self.dataset_infos],
encoding_file=self.search_index_path,
device=self.device,
)
if not os.path.exists(self.search_index_path):
logger.info("Creating dataset descriptions")
encode_text(
self.encoder_model_name,
text_to_encode=[x.description for x in self.dataset_infos],
encoding_file=self.search_index_path,
device=self.device,
)

# ---------------------------- Utility Functions ----------------------------
@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion tests/dataset_retriever_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def test_retrieve_dataset_dict_when_search_index_exists(encode_text):

mock_prompt = MockPromptSpec(task_type=TaskType.TEXT_GENERATION)
retrieved_dataset = retriever.retrieve_dataset_dict(mock_prompt)
assert encode_text.call_count == 2
assert encode_text.call_count == 1
for split_name in ["train", "val", "test"]:
assert split_name in retrieved_dataset
split = retrieved_dataset[split_name]
Expand Down