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

Add zero-shot classification #121

Merged
merged 14 commits into from
Jan 3, 2023
Merged

Add zero-shot classification #121

merged 14 commits into from
Jan 3, 2023

Conversation

seanmor5
Copy link
Contributor

I will add tests tomorrow when I get the multi-prompt case down, but right now it seems to be working fine:

Screen Shot 2022-12-15 at 6 45 05 PM

Btw, is there a reason we hid documentation for TokenClassification ?

@jonatanklosko
Copy link
Member

Awesome! I think ideally we should follow the same format as image/text classification, so %{predictions: [%{label: ..., score: ...}, ...]}. For now I wouldn't include prompt and label in the output, since the user has the input, and for multiple they can just zip.

Btw, is there a reason we hid documentation for TokenClassification?

We use defdelegate in the Bumblebee.Text module and there are all the docs :)

{labels, hypothesis} = Enum.unzip(labels_and_hypothesis)

all_inputs =
Bumblebee.apply_tokenizer(tokenizer, Enum.zip(prompts, hypothesis),
Copy link
Member

Choose a reason for hiding this comment

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

One thing to note is that here a single input becomes multiple inputs in the batch (each {prompt, hypothesis} pair). We could group them by adding an additional leading axis, however the number of hypothesis may be different for every input in the batch, so we can't really do that. Probably just documenting it is the way to go?

For Stable Diffusion if someone sets num_images_per_prompt: 2, the number of sub-inputs is fixed and we treat it as a single member of the batch (by adding a leading axis). I wonder if we should instead treat num_images_per_prompt: 2 as two inputs, so for batch size of 1 we would generate each image separately. This way if someone sets 4 images and batch size of 1 it would take more time, but don't blow up the memory, and they can set batch size to 4 to generate at once. This decoupling gives more control to the user.

@seanmor5 @josevalim thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

FTR we decided to stick to the current approach, that is :batch_size always refers to the serving input. It may be inflated by options such as num_images_pre_prompt, or the number of labels in this case.

@jonatanklosko
Copy link
Member

@seanmor5 I fixed the post processing to apply softmax per batch on the entailment label. I also adjusted the assertions based on this:

from transformers import pipeline

p = pipeline("zero-shot-classification", model="facebook/bart-large-mnli", candidate_labels=["cooking", "traveling", "dancing"])

p("one day I will see the world")

Copy link
Member

@jonatanklosko jonatanklosko left a comment

Choose a reason for hiding this comment

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

:shipit:

@seanmor5 seanmor5 merged commit cfbd909 into main Jan 3, 2023
@jonatanklosko jonatanklosko deleted the sm-zero-shot-classification branch January 3, 2023 11:01
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.

None yet

2 participants