# ! pip install edsl
from edsl.questions import QuestionMultipleChoice
q_mc = QuestionMultipleChoice(
question_name = "q_mc",
question_text = "How often do you shop for clothes?",
question_options = [
"Rarely or never",
"Annually",
"Seasonally",
"Monthly",
"Daily"
]
)
from edsl.questions import QuestionCheckBox
q_cb = QuestionCheckBox(
question_name = "q_cb",
question_text = """Which of the following factors are important to you in making decisions about clothes shopping?
Select all that apply.""",
question_options = [
"Price",
"Quality",
"Brand Reputation",
"Style and Design",
"Fit and Comfort",
"Customer Reviews and Recommendations",
"Ethical and Sustainable Practices",
"Return Policy",
"Convenience",
"Other"
],
min_selections = 1, # This is optional
max_selections = 3 # This is optional
)
from edsl.questions import QuestionLinearScale
q_ls = QuestionLinearScale(
question_name = "q_ls",
question_text = """On a scale of 0-10, how much do you typically enjoy clothes shopping?
(0 = Not at all, 10 = Very much)""",
question_options = [0,1,2,3,4,5,6,7,8,9,10]
)
from edsl.questions import QuestionYesNo
q_yn = QuestionYesNo(
question_name = "q_yn",
question_text = "Have you ever felt excluded or frustrated by the standard sizes of the fashion industry?",
)
from edsl.questions import QuestionBudget
q_bg = QuestionBudget(
question_name = "q_bg",
question_text = """Estimate the percentage of your total time spent shopping for clothes in each of the
following modes.""",
question_options=[
"Online",
"Malls",
"Freestanding stores",
"Mail order catalogs",
"Other"
],
budget_sum = 100,
)
from edsl.questions import QuestionFreeText
q_ft = QuestionFreeText(
question_name = "q_ft",
question_text = "What improvements would you like to see in options for clothes shopping?",
allow_nonresponse = False,
)
from edsl.questions import QuestionList
q_li = QuestionList(
question_name = "q_li",
question_text = "What considerations are important to youin shopping for clothes?"
)
from edsl.questions import QuestionNumerical
q_nu = QuestionNumerical(
question_name = "q_nu",
question_text = "Estimate the amount of money that you spent on clothing in the past year (in $USD)."
)
from edsl.questions import QuestionExtract
q_ex = QuestionExtract(
question_name = "q_ex",
question_text = """Consider all of the articles of clothing in your closet.
Identify the categories of clothing that are most and least valuable to you.""",
answer_template = {
"most_valuable": "socks",
"least_valuable": "shoes"
}
)
result_mc = q_mc.run()
result_cb = q_cb.run()
result_ls = q_ls.run()
result_yn = q_yn.run()
result_bg = q_bg.run()
result_ft = q_ft.run()
result_li = q_li.run()
result_nu = q_nu.run()
result_ex = q_ex.run()
result_mc.select("q_mc").print()
result_cb.select("q_cb").print()
result_ls.select("q_ls").print()
result_yn.select("q_yn").print()
result_bg.select("q_bg").print()
result_ft.select("q_ft").print()
result_li.select("q_li").print()
result_nu.select("q_nu").print()
result_ex.select("q_ex").print()
result_mc.select("q_mc").print(pretty_labels={"answer.q_mc":q_mc.question_text})
result_cb.select("q_cb").print(pretty_labels={"answer.q_cb":q_cb.question_text})
result_ls.select("q_ls").print(pretty_labels={"answer.q_ls":q_ls.question_text})
result_yn.select("q_yn").print(pretty_labels={"answer.q_yn":q_yn.question_text})
result_bg.select("q_bg").print(pretty_labels={"answer.q_bg":q_bg.question_text})
result_ft.select("q_ft").print(pretty_labels={"answer.q_ft":q_ft.question_text})
result_li.select("q_li").print(pretty_labels={"answer.q_li":q_li.question_text})
result_nu.select("q_nu").print(pretty_labels={"answer.q_nu":q_nu.question_text})
result_ex.select("q_ex").print(pretty_labels={"answer.q_ex":q_ex.question_text})
from edsl import Survey
survey = Survey(questions = [
q_mc,
q_cb,
q_ls,
q_yn,
q_bg,
q_ft,
q_li,
q_nu,
q_ex
])
results = survey.run()
results.select("q_mc", "q_cb", "q_ls", "q_yn", "q_bg").print()
results.select("q_ft", "q_li", "q_nu", "q_ex").print()
from edsl import Scenario
scenarios = [Scenario({"item":i}) for i in ["shoes", "hats", "tshirts"]]
q = QuestionNumerical(
question_name = "annual_item_spending",
question_text = "How much do you spend shopping for {{ item }} on an annual basis (in $USD)?",
)
results = q.by(scenarios).run()
results.select("scenario.*", "annual_item_spending").print()
(results
.filter("scenario.item == 'shoes'")
.select("scenario.item", "answer.*")
.print()
)
from edsl import Agent
agent = Agent(name = "Fashion expert", traits = {"persona": "You are an expert in fashion design."})
results = survey.by(agent).run()
results.select("persona", "answer.q_ft").print()
survey.add_targeted_memory(q_li, q_ft)
results = survey.by(agent).run()
(results
.select("q_li", "q_ft_user_prompt", "q_ft")
.print({
"answer.q_li": "(List version) " + q_li.question_text,
"prompt.q_ft_user_prompt": "Prompt for q_ft",
"answer.q_ft": "(Free text version) " + q_ft.question_text
})
)
from edsl import Model
Model.available()
models = [Model(m) for m in ['gpt-3.5-turbo', 'gpt-4-1106-preview']]
results = survey.by(agent).by(models).run()
results.select("model.model", "q_bg", "q_li").print()
results = q_mc.by(scenarios).by(agent).by(models).run()
results.columns