Skip to content

Support generation tasks and various improvements#3

Open
ZhaofengWu wants to merge 3 commits intomsclar:mainfrom
ZhaofengWu:main
Open

Support generation tasks and various improvements#3
ZhaofengWu wants to merge 3 commits intomsclar:mainfrom
ZhaofengWu:main

Conversation

@ZhaofengWu
Copy link
Copy Markdown

@ZhaofengWu ZhaofengWu commented Aug 3, 2024

I will add bertscore later. But also you don't have to merge this since this doesn't block me. Only if you think this is helpful.


# SuperNaturalInstructions Tasks without a defined format
if any(t in args.task_filename for t in SUPERNATURAL_INSTRUCTIONS_TASKS_WITH_NO_FORMAT):
if any(t in args.task_filename for t in SUPERNATURAL_INSTRUCTIONS_TASKS_WITH_NO_FORMAT + OPEN_GENERATION_SUPERNATURAL_INSTRUCTIONS_TASKS):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like _setup_non_formatted_dataset_with_one_field_only works well for generation tasks out of the box.

inputs = tokenizer(prompt_list, padding=True, return_tensors='pt', return_token_type_ids=False).to('cuda')
if tokenizer.chat_template is None:
inputs = tokenizer(prompt_list, padding=True, return_tensors='pt', return_token_type_ids=False).to('cuda')
else:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Support chat models


generated_answer_list = [s.lower() for s in tokenizer.batch_decode(outputs['sequences'], skip_special_tokens=True)]
sequences = outputs['sequences']
if tokenizer.chat_template is not None:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The truncation of chat models is a bit different from regular models and need to be done separately. Also got rid of lowercasing for generation tasks (done below for classification tasks).

full_prompt_string_list = []
for input_element, idx in zip(inputs, selected_dataset_ids):
full_prompt_string_list.append(input_element if n_shot == 0 else demonstration_string + "\n\n" + input_element)
full_prompt_string_list.append(demonstration_string + "\n\n" + input_element)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think even for 0-shot, the instruction (demonstration_definition) should still be there.


# 2. update the output values if needed, i.e. if the multiple choice classes now have different names
assert all(len(dataset[idx]['output']) == 1 for idx in selected_dataset_ids)
assert all(len(dataset[idx]['output']) >= 1 for idx in selected_dataset_ids)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be a bit lenient here. This doesn't hold for some generation tasks. When that happens, only take the first one.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to raise some kind of warning in the > 1 case? Otherwise the code will silently take the first output and you might never know it happened

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah makes sense. Added a warning below.

@ZhaofengWu
Copy link
Copy Markdown
Author

bertscore added

@msclar
Copy link
Copy Markdown
Owner

msclar commented Aug 12, 2024

Amazing, thank you for extending FormatSpread for generation tasks!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants