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

Custom Prefixes for data column and few shot column for prompt #45

Closed
HallerPatrick opened this issue Jul 21, 2023 · 2 comments
Closed

Comments

@HallerPatrick
Copy link
Collaborator

Currently generate_data_for_columnand fewshot_example_columns are used as the prefixs for the prompt.

E.g.:

from datasets import Dataset
from ai_dataset_generator.prompts import BasePrompt

fewshot_examples = Dataset.from_dict({
    "text": ["This movie is great!", "This movie is bad!"],
    "label": ["positive", "negative"]
})

prompt_template = BasePrompt(
    task_description="Annotate movie reviews as either: {label_options}",
    label_options=["positive", "negative"],
    generate_data_for_column="label",
    fewshot_example_columns="text",
)

Has Output:

Annotate movie reviews as either: positive, negative

text: This movie is great!
label: positive

text: This movie is bad!
label: negative

text: {text}
label: 

With text: and label: as the prefixes.

Proposal/Motivation

What if I use a custom fine-tuned model, that does not work well with textand label as prefixes in the prompt, but was trained with sentence and prediction.

For more flexibility, those prefixes should be optionally configurable. For example:

from datasets import Dataset
from ai_dataset_generator.prompts import BasePrompt

fewshot_examples = Dataset.from_dict({
    "text": ["This movie is great!", "This movie is bad!"],
    "label": ["positive", "negative"]
})

prompt_template = BasePrompt(
    task_description="Annotate movie reviews as either: {label_options}",
    label_options=["positive", "negative"],
    generate_data_for_column=("label", "sentence"),  # Second tuple item contains the new prefix string
    fewshot_example_columns=("text", "prediction"),  # Second tuple item contains the new prefix string
)

Has Output:

Annotate movie reviews as either: positive, negative

sentence: This movie is great!
prediction: positive

sentence: This movie is bad!
prediction: negative

sentence: {text}
prediction: 

The default behaviour could stay the same and the column name is used as the prefix. If it is a tuple (or other structure) then the second item is used.

@whoisjones
Copy link
Member

nice 🦝

@HallerPatrick
Copy link
Collaborator Author

@whoisjones Nevermind, just found out that this is covered by:

    prompt = ClassLabelPrompt(
        input_variables=[task_template.text_column],
        target_variable=task_template.label_column,
        examples_formatting_template="CustomText: {text}\nCustomLabel: {label}",
        target_formatting_template="CustomText: {text}\nCustomLabel:",
        label_options=dict(enumerate(task_template.label_schema["labels"].names)),
    )

I could write the docu for that case?

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

No branches or pull requests

2 participants