Skip to content

Commit 398f81e

Browse files
change the prompting example code (#563)
* change the prompting example code * Apply suggestions from code review Co-authored-by: Stephen Bach <[email protected]>
1 parent a9684c4 commit 398f81e

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

Diff for: README.md

+15-5
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,29 @@ dataset = load_dataset("ag_news")
4747
example = dataset["train"][0]
4848

4949
# Prompt it
50-
from promptsource.templates import TemplateCollection
51-
# Get all the prompts
52-
collection = TemplateCollection()
50+
from promptsource.templates import DatasetTemplates
5351
# Get all the AG News prompts
54-
ag_news_prompts = collection.get_dataset("ag_news")
52+
ag_news_prompts = DatasetTemplates('ag_news')
5553
# Select a prompt by name
5654
prompt = ag_news_prompts["classify_question_first"]
57-
55+
# Apply the prompt on the example
5856
result = prompt.apply(example)
5957
print("INPUT: ", result[0])
6058
print("TARGET: ", result[1])
6159
```
6260

61+
You can collect all the available datasets and their associated prompts
62+
63+
```python
64+
from promptsource.templates import TemplateCollection
65+
66+
# Get all the prompts
67+
collection = TemplateCollection()
68+
69+
# Return a dict where the key is the pair (dataset name, subset name)
70+
# and the value is an instance of DatasetTemplates
71+
print(collection.datasets_templates)
72+
```
6373
## Contributing
6474
Contribution guidelines and step-by-step *HOW TO* are described [here](CONTRIBUTING.md).
6575

0 commit comments

Comments
 (0)