Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions softwares/auto_cot/auto_cot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from __future__ import annotations

from promptware.info import SoftwareInfo
from promptware.kernels.plm import PLMKernelConfig
from promptware.licenses import LicenseType
from promptware.promptware import PromptConfig, Promptware
from promptware.tasks import TaskType

import json
import os

folder = os.path.abspath(os.path.join(os.path.dirname(__file__), ".")) + '/demos/'


def create_demo_text(demo_path):
x, z, y = [], [], []

with open(demo_path, encoding="utf-8") as f:
json_data = json.load(f)
json_data = json_data["demo"]
for line in json_data:
x.append(line["question"])
z.append(line["rationale"])
y.append(line["pred_ans"])

index_list = list(range(len(x)))

demo_text = ""
for i in index_list:
demo_text += x[i] + " " + z[i] + " " + \
"The answer is" + " " + y[i] + ".\n\n"

return demo_text


class AutoCotPromptware(Promptware):
def _info(self) -> SoftwareInfo:
return SoftwareInfo(
Copy link
Contributor

Choose a reason for hiding this comment

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

Add more metadata info, for example :

description="This promptware is used to answer a question"
" that involves reasoning with chain-of-thought method.",
creator="Promptware Authors",
homepage="https://github.com/expressai/promptware",
reference="https://github.com/amazon-science/auto-cot",
codebase_url="https://github.com/expressai/promptware/tree/main/softwares",
license=LicenseType.apache_2_0,
task=TaskType.qa_open_domain,
)

def _kernel_configs(self):
return {
"openai": PLMKernelConfig(
platform="openai",
model_name="text-davinci-002",
temperature=0,
max_tokens=256,
top_p=1,
frequency_penalty=0.0,
presence_penalty=0.0,
)
}

def _software_configs(self):
return {
"multiarith": PromptConfig(
name="multiarith",
description="This promptware is used to answer an arithmatic question"
" that involves reasoning with Auto-CoT method.",
instruction="",
demonstration=[create_demo_text(folder+"multiarith_auto")],
prompt_template=lambda input: f"Q: {input['question']}\nA: Let's think step by step.",
task=TaskType.qa_open_domain,
)
}

def _example(self):
return {
"input": {
"question": "In a video game, each enemy defeated gives you 7 points. "
"If a level has 11 enemies total and you destroy all but 8 of them, "
"how many points would you earn?"
},
"output": 21.0,
}
27 changes: 27 additions & 0 deletions softwares/auto_cot/auto_cot_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
import sys
import unittest

current_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "."))
sys.path.append(current_path)

from auto_cot import AutoCotPromptware # noqa


class TestAutoCotPromptware(unittest.TestCase):
def test_write_to_directory(self):
software = AutoCotPromptware()
file_path = software.info.write_to_directory(current_path)
self.assertTrue(os.path.exists(file_path))
'''
def test_execute_default(self):
software = AutoCotPromptware(config_name="default")
input = {
"question": "In a video game, each enemy defeated gives you 7 points. "
"If a level has 11 enemies total and you destroy all but 8 of them, "
"how many points would you earn?"
}
result = software.execute(input)
print(result)
self.assertGreater(len(result), 0)
'''
52 changes: 52 additions & 0 deletions softwares/auto_cot/demos/multiarith_auto
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"demo": [
{
"question": "Q: Wendy uploaded 45 pictures to Facebook. She put 27 pics into one album and put the rest into 9 different albums. How many pictures were in each album?\nA:",
"rationale": "Let's think step by step. First, we know that Wendy uploaded 45 pictures in total. Second, we know that Wendy put 27 pictures into one album. That means that Wendy put the remaining 18 pictures into 9 different albums. That means that each album would have 2 pictures.",
"pred_ans": "2",
"gold_ans": "2"
},
{
"question": "Q: For Halloween Katie and her sister combined the candy they received. Katie had 8 pieces of candy while her sister had 23. If they ate 8 pieces the first night, how many pieces do they have left?\nA:",
"rationale": "Let's think step by step. Katie and her sister have a total of 8 + 23 = 31 pieces of candy. If they eat 8 pieces the first night, they have 31 - 8 = 23 pieces left.",
"pred_ans": "23",
"gold_ans": "23"
},
{
"question": "Q: Bianca was organizing her book case making sure each of the shelves had exactly 8 books on it. If she had 5 shelves of mystery books and 4 shelves of picture books, how many books did she have total?\nA:",
"rationale": "Let's think step by step. There are 5 shelves of mystery books. Each shelf has 8 books. So that's 40 mystery books. There are 4 shelves of picture books. Each shelf has 8 books. So that's 32 picture books. 40 + 32 = 72 books.",
"pred_ans": "72",
"gold_ans": "72"
},
{
"question": "Q: A pet store had 78 puppies. In one day they sold 30 of them and put the rest into cages with 8 in each cage. How many cages did they use?\nA:",
"rationale": "Let's think step by step. There are 78 puppies. 30 are sold, so that means there are 48 left. 48 divided by 8 is 6, so that means there are 6 cages with 8 puppies in each.",
"pred_ans": "6",
"gold_ans": "6"
},
{
"question": "Q: A waiter had 14 customers to wait on. If 3 customers left and he got another 39 customers, how many customers would he have?\nA:",
"rationale": "Let's think step by step. The waiter had 14 customers to wait on. If 3 customers left, that means he would have 11 customers left. If he got another 39 customers, that means he would have 50 customers in total.",
"pred_ans": "50",
"gold_ans": "50"
},
{
"question": "Q: A trivia team had 7 members total, but during a game 2 members didn't show up. If each member that did show up scored 4 points, how many points were scored total?\nA:",
"rationale": "Let's think step by step. There were 7 members on the team, but 2 members didn't show up. That means that there were 5 members that did show up. Each member that showed up scored 4 points. So if 5 members each scored 4 points, then the total number of points scored would be 5*4=20.",
"pred_ans": "20",
"gold_ans": "20"
},
{
"question": "Q: Gwen had 18 math problems and 11 science problems for homework. If she finished 24 of the problems at school, how many problems did she have to do for homework?\nA:",
"rationale": "Let's think step by step. Gwen had 18 math problems and 11 science problems for homework. That means she had a total of 29 problems for homework. If she finished 24 of the problems at school, that means she had 5 problems left to do for homework.",
"pred_ans": "5",
"gold_ans": "5"
},
{
"question": "Q: Mike made 69 dollars mowing lawns over the summer. If he spent 24 dollars buying new mower blades, how many 5 dollar games could he buy with the money he had left?\nA:",
"rationale": "Let's think step by step. Mike made $69 from mowing lawns. He spent $24 on new mower blades. That means he has $45 left. Each game costs $5, so he could buy 9 games.",
"pred_ans": "9",
"gold_ans": "9"
}
]
}
47 changes: 47 additions & 0 deletions softwares/auto_cot/software_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"description": "This promptware is used to answer a question that involves reasoning with chain-of-thought method.",
"creator": "Promptware Authors",
"homepage": "https://github.com/expressai/promptware",
"reference": "https://github.com/amazon-science/auto-cot",
"codebase_url": "https://github.com/expressai/promptware/tree/main/softwares",
"license": "apache-2.0",
"task": "qa-open-domain",
"module_name": "auto_cot_promptware",
"config_name": "default",
"kernel_configs": {
"openai": {
"platform": "openai",
"model_name": "text-davinci-002",
"max_tokens": 256,
"temperature": 0,
"top_p": 1,
"suffix": "",
"frequency_penalty": 0.0,
"presence_penalty": 0.0,
"logprobs": 1,
"n": 1,
"echo": false,
"stop": null
}
},
"software_configs": {
"multiarith": {
"name": "multiarith",
"description": "This promptware is used to answer an arithmatic question that involves reasoning with Auto-CoT method.",
"instruction": "",
"demonstration": [
"Q: Wendy uploaded 45 pictures to Facebook. She put 27 pics into one album and put the rest into 9 different albums. How many pictures were in each album?\nA: Let's think step by step. First, we know that Wendy uploaded 45 pictures in total. Second, we know that Wendy put 27 pictures into one album. That means that Wendy put the remaining 18 pictures into 9 different albums. That means that each album would have 2 pictures. The answer is 2.\n\nQ: For Halloween Katie and her sister combined the candy they received. Katie had 8 pieces of candy while her sister had 23. If they ate 8 pieces the first night, how many pieces do they have left?\nA: Let's think step by step. Katie and her sister have a total of 8 + 23 = 31 pieces of candy. If they eat 8 pieces the first night, they have 31 - 8 = 23 pieces left. The answer is 23.\n\nQ: Bianca was organizing her book case making sure each of the shelves had exactly 8 books on it. If she had 5 shelves of mystery books and 4 shelves of picture books, how many books did she have total?\nA: Let's think step by step. There are 5 shelves of mystery books. Each shelf has 8 books. So that's 40 mystery books. There are 4 shelves of picture books. Each shelf has 8 books. So that's 32 picture books. 40 + 32 = 72 books. The answer is 72.\n\nQ: A pet store had 78 puppies. In one day they sold 30 of them and put the rest into cages with 8 in each cage. How many cages did they use?\nA: Let's think step by step. There are 78 puppies. 30 are sold, so that means there are 48 left. 48 divided by 8 is 6, so that means there are 6 cages with 8 puppies in each. The answer is 6.\n\nQ: A waiter had 14 customers to wait on. If 3 customers left and he got another 39 customers, how many customers would he have?\nA: Let's think step by step. The waiter had 14 customers to wait on. If 3 customers left, that means he would have 11 customers left. If he got another 39 customers, that means he would have 50 customers in total. The answer is 50.\n\nQ: A trivia team had 7 members total, but during a game 2 members didn't show up. If each member that did show up scored 4 points, how many points were scored total?\nA: Let's think step by step. There were 7 members on the team, but 2 members didn't show up. That means that there were 5 members that did show up. Each member that showed up scored 4 points. So if 5 members each scored 4 points, then the total number of points scored would be 5*4=20. The answer is 20.\n\nQ: Gwen had 18 math problems and 11 science problems for homework. If she finished 24 of the problems at school, how many problems did she have to do for homework?\nA: Let's think step by step. Gwen had 18 math problems and 11 science problems for homework. That means she had a total of 29 problems for homework. If she finished 24 of the problems at school, that means she had 5 problems left to do for homework. The answer is 5.\n\nQ: Mike made 69 dollars mowing lawns over the summer. If he spent 24 dollars buying new mower blades, how many 5 dollar games could he buy with the money he had left?\nA: Let's think step by step. Mike made $69 from mowing lawns. He spent $24 on new mower blades. That means he has $45 left. Each game costs $5, so he could buy 9 games. The answer is 9.\n\n"
],
"prompt_template": "lambda input: f\"Q: {input['question']}\\nA: Let's think step by step.\",",
"task": "qa-open-domain"
}
},
"dataset_configs": null,
"example": {
"input": {
"question": "In a video game, each enemy defeated gives you 7 points. If a level has 11 enemies total and you destroy all but 8 of them, how many points would you earn?"
},
"output": 21.0
},
"example_prompt": "Q: Wendy uploaded 45 pictures to Facebook. She put 27 pics into one album and put the rest into 9 different albums. How many pictures were in each album?\nA: Let's think step by step. First, we know that Wendy uploaded 45 pictures in total. Second, we know that Wendy put 27 pictures into one album. That means that Wendy put the remaining 18 pictures into 9 different albums. That means that each album would have 2 pictures. The answer is 2.\n\nQ: For Halloween Katie and her sister combined the candy they received. Katie had 8 pieces of candy while her sister had 23. If they ate 8 pieces the first night, how many pieces do they have left?\nA: Let's think step by step. Katie and her sister have a total of 8 + 23 = 31 pieces of candy. If they eat 8 pieces the first night, they have 31 - 8 = 23 pieces left. The answer is 23.\n\nQ: Bianca was organizing her book case making sure each of the shelves had exactly 8 books on it. If she had 5 shelves of mystery books and 4 shelves of picture books, how many books did she have total?\nA: Let's think step by step. There are 5 shelves of mystery books. Each shelf has 8 books. So that's 40 mystery books. There are 4 shelves of picture books. Each shelf has 8 books. So that's 32 picture books. 40 + 32 = 72 books. The answer is 72.\n\nQ: A pet store had 78 puppies. In one day they sold 30 of them and put the rest into cages with 8 in each cage. How many cages did they use?\nA: Let's think step by step. There are 78 puppies. 30 are sold, so that means there are 48 left. 48 divided by 8 is 6, so that means there are 6 cages with 8 puppies in each. The answer is 6.\n\nQ: A waiter had 14 customers to wait on. If 3 customers left and he got another 39 customers, how many customers would he have?\nA: Let's think step by step. The waiter had 14 customers to wait on. If 3 customers left, that means he would have 11 customers left. If he got another 39 customers, that means he would have 50 customers in total. The answer is 50.\n\nQ: A trivia team had 7 members total, but during a game 2 members didn't show up. If each member that did show up scored 4 points, how many points were scored total?\nA: Let's think step by step. There were 7 members on the team, but 2 members didn't show up. That means that there were 5 members that did show up. Each member that showed up scored 4 points. So if 5 members each scored 4 points, then the total number of points scored would be 5*4=20. The answer is 20.\n\nQ: Gwen had 18 math problems and 11 science problems for homework. If she finished 24 of the problems at school, how many problems did she have to do for homework?\nA: Let's think step by step. Gwen had 18 math problems and 11 science problems for homework. That means she had a total of 29 problems for homework. If she finished 24 of the problems at school, that means she had 5 problems left to do for homework. The answer is 5.\n\nQ: Mike made 69 dollars mowing lawns over the summer. If he spent 24 dollars buying new mower blades, how many 5 dollar games could he buy with the money he had left?\nA: Let's think step by step. Mike made $69 from mowing lawns. He spent $24 on new mower blades. That means he has $45 left. Each game costs $5, so he could buy 9 games. The answer is 9.\n\n\nQ: In a video game, each enemy defeated gives you 7 points. If a level has 11 enemies total and you destroy all but 8 of them, how many points would you earn?\nA: Let's think step by step.\n"
}
Empty file.
Empty file.

Large diffs are not rendered by default.

Loading