forked from BeastByteAI/scikit-llm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/iryna-kondr/scikit-llm
- Loading branch information
Showing
6 changed files
with
147 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from typing import Union | ||
|
||
from skllm.prompts.templates import ( | ||
SUMMARY_PROMPT_TEMPLATE, | ||
ZERO_SHOT_CLF_PROMPT_TEMPLATE, | ||
ZERO_SHOT_MLCLF_PROMPT_TEMPLATE, | ||
) | ||
|
||
# TODO add validators | ||
|
||
|
||
def build_zero_shot_prompt_slc( | ||
x: str, labels: str, template: str = ZERO_SHOT_CLF_PROMPT_TEMPLATE | ||
) -> str: | ||
"""Builds a prompt for zero-shot single-label classification. | ||
Parameters | ||
---------- | ||
x : str | ||
sample to classify | ||
labels : str | ||
candidate labels in a list-like representation | ||
template : str | ||
prompt template to use, must contain placeholders for all variables, by default ZERO_SHOT_CLF_PROMPT_TEMPLATE | ||
Returns | ||
------- | ||
str | ||
prepared prompt | ||
""" | ||
return template.format(x=x, labels=labels) | ||
|
||
|
||
def build_zero_shot_prompt_mlc( | ||
x: str, | ||
labels: str, | ||
max_cats: Union[int, str], | ||
template: str = ZERO_SHOT_MLCLF_PROMPT_TEMPLATE, | ||
) -> str: | ||
"""Builds a prompt for zero-shot multi-label classification. | ||
Parameters | ||
---------- | ||
x : str | ||
sample to classify | ||
labels : str | ||
candidate labels in a list-like representation | ||
max_cats : Union[int,str] | ||
maximum number of categories to assign | ||
template : str | ||
prompt template to use, must contain placeholders for all variables, by default ZERO_SHOT_MLCLF_PROMPT_TEMPLATE | ||
Returns | ||
------- | ||
str | ||
prepared prompt | ||
""" | ||
return template.format(x=x, labels=labels, max_cats=max_cats) | ||
|
||
|
||
def build_summary_prompt( | ||
x: str, max_words: Union[int, str], template: str = SUMMARY_PROMPT_TEMPLATE | ||
) -> str: | ||
"""Builds a prompt for text summarization. | ||
Parameters | ||
---------- | ||
x : str | ||
sample to summarize | ||
max_words : Union[int,str] | ||
maximum number of words to use in the summary | ||
template : str | ||
prompt template to use, must contain placeholders for all variables, by default SUMMARY_PROMPT_TEMPLATE | ||
Returns | ||
------- | ||
str | ||
prepared prompt | ||
""" | ||
return template.format(x=x, max_words=max_words) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
ZERO_SHOT_CLF_PROMPT_TEMPLATE = """ | ||
You will be provided with the following information: | ||
1. An arbitrary text sample. The sample is delimited with triple backticks. | ||
2. List of categories the text sample can be assigned to. The list is delimited with square brackets. The categories in the list are enclosed in the single quotes and comma separated. | ||
Perform the following tasks: | ||
1. Identify to which category the provided text belongs to with the highest probability. | ||
2. Assign the provided text to that category. | ||
3. Provide your response in a JSON format containing a single key `label` and a value corresponding to the assigned category. Do not provide any additional information except the JSON. | ||
List of categories: {labels} | ||
Text sample: ```{x}``` | ||
Your JSON response: | ||
""" | ||
|
||
ZERO_SHOT_MLCLF_PROMPT_TEMPLATE = """ | ||
You will be provided with the following information: | ||
1. An arbitrary text sample. The sample is delimited with triple backticks. | ||
2. List of categories the text sample can be assigned to. The list is delimited with square brackets. The categories in the list are enclosed in the single quotes and comma separated. The text sample belongs to at least one category but cannot exceed {max_cats}. | ||
Perform the following tasks: | ||
1. Identify to which categories the provided text belongs to with the highest probability. | ||
2. Assign the text sample to at least 1 but up to {max_cats} categories based on the probabilities. | ||
3. Provide your response in a JSON format containing a single key `label` and a value corresponding to the list of assigned categories. Do not provide any additional information except the JSON. | ||
List of categories: {labels} | ||
Text sample: ```{x}``` | ||
Your JSON response: | ||
""" | ||
|
||
SUMMARY_PROMPT_TEMPLATE = """ | ||
Your task is to generate a summary of the text sample. | ||
Summarize the text sample provided below, delimited by triple backticks, in at most {max_words} words. | ||
Text sample: ```{x}``` | ||
Summarized text: | ||
""" |