edsl 0.1.46__py3-none-any.whl → 0.1.47__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- edsl/Base.py +86 -19
- edsl/__version__.py +1 -1
- edsl/coop/coop.py +134 -53
- edsl/data/Cache.py +2 -0
- edsl/data/CacheEntry.py +10 -2
- edsl/inference_services/PerplexityService.py +9 -5
- edsl/jobs/Jobs.py +20 -0
- edsl/jobs/JobsComponentConstructor.py +2 -1
- edsl/language_models/LanguageModel.py +6 -6
- edsl/questions/QuestionBase.py +5 -0
- edsl/questions/question_registry.py +6 -7
- edsl/results/DatasetExportMixin.py +99 -2
- edsl/results/Results.py +59 -0
- edsl/scenarios/FileStore.py +112 -7
- edsl/scenarios/ScenarioList.py +130 -0
- edsl/study/Study.py +2 -2
- edsl/surveys/Survey.py +15 -20
- {edsl-0.1.46.dist-info → edsl-0.1.47.dist-info}/METADATA +3 -2
- {edsl-0.1.46.dist-info → edsl-0.1.47.dist-info}/RECORD +21 -33
- edsl/auto/AutoStudy.py +0 -130
- edsl/auto/StageBase.py +0 -243
- edsl/auto/StageGenerateSurvey.py +0 -178
- edsl/auto/StageLabelQuestions.py +0 -125
- edsl/auto/StagePersona.py +0 -61
- edsl/auto/StagePersonaDimensionValueRanges.py +0 -88
- edsl/auto/StagePersonaDimensionValues.py +0 -74
- edsl/auto/StagePersonaDimensions.py +0 -69
- edsl/auto/StageQuestions.py +0 -74
- edsl/auto/SurveyCreatorPipeline.py +0 -21
- edsl/auto/utilities.py +0 -218
- edsl/base/Base.py +0 -279
- {edsl-0.1.46.dist-info → edsl-0.1.47.dist-info}/LICENSE +0 -0
- {edsl-0.1.46.dist-info → edsl-0.1.47.dist-info}/WHEEL +0 -0
edsl/auto/StageGenerateSurvey.py
DELETED
@@ -1,178 +0,0 @@
|
|
1
|
-
from textwrap import dedent
|
2
|
-
from dataclasses import dataclass
|
3
|
-
from collections import defaultdict
|
4
|
-
|
5
|
-
from typing import List, Dict
|
6
|
-
|
7
|
-
from edsl.auto.StageBase import StageBase
|
8
|
-
from edsl.auto.utilities import gen_pipeline
|
9
|
-
from edsl.auto.StageBase import FlowDataBase
|
10
|
-
|
11
|
-
from edsl.auto.StageQuestions import StageQuestions
|
12
|
-
from edsl.auto.StageLabelQuestions import StageLabelQuestions
|
13
|
-
|
14
|
-
from edsl.questions import QuestionList
|
15
|
-
from edsl.scenarios import Scenario
|
16
|
-
from edsl import Model
|
17
|
-
from edsl.surveys import Survey
|
18
|
-
from edsl.questions import QuestionBase
|
19
|
-
|
20
|
-
from edsl.utilities.utilities import is_valid_variable_name
|
21
|
-
from edsl import Model
|
22
|
-
from edsl.questions import QuestionExtract
|
23
|
-
|
24
|
-
|
25
|
-
m = Model()
|
26
|
-
|
27
|
-
|
28
|
-
def chunker(seq, size):
|
29
|
-
return (seq[pos : pos + size] for pos in range(0, len(seq), size))
|
30
|
-
|
31
|
-
|
32
|
-
def get_short_options(question_options, num_chars=20):
|
33
|
-
"""Gets short names for the options of a question
|
34
|
-
>>> get_short_options(["No, I don't own a scooter", "Yes, I own a scooter"])
|
35
|
-
{'No, I don\'t own a scooter': 'no_scooter', 'Yes, I own a scooter': 'yes_scooter'}
|
36
|
-
"""
|
37
|
-
q = QuestionList(
|
38
|
-
question_text=dedent(
|
39
|
-
f"""\
|
40
|
-
We need short (less than {num_chars} characters) names for the options of a question, with no spaces.
|
41
|
-
E.g., if the options were "No, I don't own a scooter" and "Yes, I own a scooter",
|
42
|
-
you could use "no_scooter" and "yes_scooter".
|
43
|
-
They should be all lower case. Use snake case.
|
44
|
-
The short names have to be unique.
|
45
|
-
The options are: {question_options}
|
46
|
-
The names are {question_options} of them."""
|
47
|
-
),
|
48
|
-
# answer_template={k: None for k in question_options},
|
49
|
-
question_name="short_options",
|
50
|
-
)
|
51
|
-
results = q.by(m).run()
|
52
|
-
return results.select("short_options").first()
|
53
|
-
|
54
|
-
|
55
|
-
def get_short_names_chunk(questions, num_chars=20):
|
56
|
-
q = QuestionList(
|
57
|
-
question_text=dedent(
|
58
|
-
f"""\
|
59
|
-
We need short (less than {num_chars} characters) names for the questions, with no spaces.
|
60
|
-
E.g., if the question was: "What is your first name?", you could use "first_name".
|
61
|
-
The short names have to be unique and not starting with numbers. They should be all lower case.
|
62
|
-
The questions are: {questions}
|
63
|
-
"""
|
64
|
-
),
|
65
|
-
question_name="short_names",
|
66
|
-
)
|
67
|
-
results = q.by(m).run()
|
68
|
-
short_names = results.select("short_names").first()
|
69
|
-
return {k: v for k, v in zip(questions, short_names)}
|
70
|
-
|
71
|
-
|
72
|
-
def get_short_names(questions, max_size=10, num_chars=20):
|
73
|
-
"Gets short names for questions"
|
74
|
-
if len(questions) <= max_size:
|
75
|
-
short_names_dict = get_short_names_chunk(questions, num_chars)
|
76
|
-
else:
|
77
|
-
short_names_dict = {}
|
78
|
-
for chunk in chunker(questions, max_size):
|
79
|
-
results = get_short_names_chunk(chunk, num_chars)
|
80
|
-
short_names_dict.update(results)
|
81
|
-
return short_names_dict
|
82
|
-
|
83
|
-
|
84
|
-
class StageGenerateSurvey(StageBase):
|
85
|
-
input = StageLabelQuestions.output
|
86
|
-
|
87
|
-
@dataclass
|
88
|
-
class Output(FlowDataBase):
|
89
|
-
survey: Survey
|
90
|
-
|
91
|
-
output = Output
|
92
|
-
|
93
|
-
def handle_data(self, data):
|
94
|
-
"""This tage uses the question types to generate a survey
|
95
|
-
It constucts the edsl-specific dictionary needed to create a question
|
96
|
-
"""
|
97
|
-
# survey = Survey(name = {data.overall_question, population = data.population, description)
|
98
|
-
survey = Survey()
|
99
|
-
|
100
|
-
short_names = get_short_names(data.questions)
|
101
|
-
|
102
|
-
question_count = -1
|
103
|
-
for question, question_type, options, option_labels in zip(
|
104
|
-
data.questions, data.types, data.options, data.option_labels
|
105
|
-
):
|
106
|
-
question_count += 1
|
107
|
-
short_names_dict = {}
|
108
|
-
if question in short_names:
|
109
|
-
short_names_dict[question] = short_names[question]
|
110
|
-
data = {
|
111
|
-
"question_text": question,
|
112
|
-
"question_type": question_type,
|
113
|
-
"question_name": short_names.get(question, f"q{question_count}"),
|
114
|
-
}
|
115
|
-
if options is not None:
|
116
|
-
data["question_options"] = options
|
117
|
-
# make sure it's not a linear scale question, in which case we don't want to add short names
|
118
|
-
|
119
|
-
if option_labels is not None:
|
120
|
-
data["option_labels"] = dict(zip(options, option_labels))
|
121
|
-
# print(data["option_labels"])
|
122
|
-
# breakpoint()
|
123
|
-
|
124
|
-
if question_type == "linear_scale":
|
125
|
-
option_keys = option_labels
|
126
|
-
else:
|
127
|
-
option_keys = options
|
128
|
-
|
129
|
-
if options is not None:
|
130
|
-
short_options = get_short_options(option_keys)
|
131
|
-
short_names_dict.update(
|
132
|
-
{k: v for k, v in zip(option_keys, short_options)}
|
133
|
-
)
|
134
|
-
|
135
|
-
if question_type not in ["numerical", "free_text"]:
|
136
|
-
data["short_names_dict"] = short_names_dict
|
137
|
-
_ = data.pop("short_names_dict", None)
|
138
|
-
q = QuestionBase.from_dict(data)
|
139
|
-
survey.add_question(q)
|
140
|
-
|
141
|
-
survey.print()
|
142
|
-
return self.output(survey=survey)
|
143
|
-
|
144
|
-
|
145
|
-
if __name__ == "__main__":
|
146
|
-
# pipeline = gen_pipeline([StageQuestions, StageLabelQuestions, StageGenerateSurvey])
|
147
|
-
|
148
|
-
# results = pipeline.process(
|
149
|
-
# pipeline.input(
|
150
|
-
# overall_question="What are some factors that could determine whether someone likes ice cream?",
|
151
|
-
# population="consumers",
|
152
|
-
# )
|
153
|
-
# )
|
154
|
-
# # print(results)
|
155
|
-
# short_options = get_short_options(
|
156
|
-
# ["No, I don't own a scooter", "Yes, I own a scooter"]
|
157
|
-
# )
|
158
|
-
# print(short_options)
|
159
|
-
|
160
|
-
sample_questions = [
|
161
|
-
"What are the primary goals for your company in sponsoring a research center like the MIT IDE?",
|
162
|
-
"How does your company measure the ROI on sponsorships like this?",
|
163
|
-
"What specific aspects of the MIT IDEs work align with your companys strategic interests?",
|
164
|
-
"Can you describe the decision-making process your company uses to select research initiatives for sponsorship?",
|
165
|
-
"What are the most important factors your company considers when deciding to sponsor a research center?",
|
166
|
-
"How important is the visibility and recognition your company receives from sponsoring a research center like the MIT IDE?",
|
167
|
-
"What kind of collaborative opportunities with the MIT IDE are you looking for?",
|
168
|
-
"What are your companys expectations regarding intellectual property and the commercialization of research outcomes?",
|
169
|
-
"How does your company evaluate the success of the research projects it sponsors?",
|
170
|
-
"Would your company be interested in engaging with students or faculty at the MIT IDE for recruitment or professional development opportunities?",
|
171
|
-
"How does your company plan to leverage the research and insights gained from the MIT IDE?",
|
172
|
-
"What challenges has your company faced in previous sponsorships that you would want to avoid in the future?",
|
173
|
-
"Is there any additional support or involvement your company would like to have in the MIT IDE beyond financial sponsorship?",
|
174
|
-
"How do you see your companys role in shaping the research agenda at the MIT IDE?",
|
175
|
-
"What can the MIT IDE do to make its sponsorship opportunities more attractive to your company?",
|
176
|
-
]
|
177
|
-
|
178
|
-
short_names = get_short_names(sample_questions)
|
edsl/auto/StageLabelQuestions.py
DELETED
@@ -1,125 +0,0 @@
|
|
1
|
-
from textwrap import dedent
|
2
|
-
from dataclasses import dataclass
|
3
|
-
from collections import defaultdict
|
4
|
-
|
5
|
-
from typing import List, Dict, Union
|
6
|
-
|
7
|
-
from edsl.auto.StageBase import StageBase
|
8
|
-
from edsl.auto.StageBase import FlowDataBase
|
9
|
-
|
10
|
-
from edsl.auto.StageQuestions import StageQuestions
|
11
|
-
|
12
|
-
from edsl.questions import QuestionMultipleChoice, QuestionList
|
13
|
-
from edsl.scenarios import Scenario
|
14
|
-
from edsl import Model
|
15
|
-
from edsl.auto.utilities import gen_pipeline
|
16
|
-
|
17
|
-
|
18
|
-
question_purpose = {
|
19
|
-
"multiple_choice": "When options are known and limited",
|
20
|
-
"free_text": "When we are asking an open-ended question",
|
21
|
-
"checkbox": "When multiple options can be selected e.g., have you heard of the following products:",
|
22
|
-
"numerical": "When the answer is a single numerical value e.g., a float",
|
23
|
-
"linear_scale": "When options are text like multiple choice, but can be ordered e.g., daily, weekly, monthly, etc.",
|
24
|
-
"yes_no": "When the question can be fully answered with either a yes or a no",
|
25
|
-
}
|
26
|
-
|
27
|
-
|
28
|
-
class StageLabelQuestions(StageBase):
|
29
|
-
input = StageQuestions.output
|
30
|
-
|
31
|
-
@dataclass
|
32
|
-
class Output(FlowDataBase):
|
33
|
-
questions: List[str]
|
34
|
-
types: List[str]
|
35
|
-
options: Dict[str, List[str]]
|
36
|
-
option_labels: Dict[str, Union[List[str], None]]
|
37
|
-
|
38
|
-
output = Output
|
39
|
-
|
40
|
-
def handle_data(self, data):
|
41
|
-
"""
|
42
|
-
Labels each edsl question type. This is then used later to instantiate the questions
|
43
|
-
"""
|
44
|
-
m = Model()
|
45
|
-
label_questions_scenarios = [
|
46
|
-
Scenario({"question": q, "question_purpose": question_purpose})
|
47
|
-
for q in data.questions
|
48
|
-
]
|
49
|
-
q_type = QuestionMultipleChoice(
|
50
|
-
question_text=dedent(
|
51
|
-
"""\
|
52
|
-
Consider this question: "{{ question }}"
|
53
|
-
The question options and purpose are: {{ question_purpose }}
|
54
|
-
Please avoid free text questions much as possible.
|
55
|
-
If it could be a multiple choice, use that type.
|
56
|
-
What type of question should this be to make for an informative survey?"""
|
57
|
-
),
|
58
|
-
question_options=list(question_purpose.keys()),
|
59
|
-
question_name="question_type",
|
60
|
-
)
|
61
|
-
## If it is a linear scale, multiple choice or checkbox question, we need to know the options
|
62
|
-
option_questions = [
|
63
|
-
"multiple_choice",
|
64
|
-
"linear_scale",
|
65
|
-
"checkbox",
|
66
|
-
]
|
67
|
-
q_options_mc = QuestionList(
|
68
|
-
question_text=dedent(
|
69
|
-
"""\
|
70
|
-
Consider this question: "{{ question }}"
|
71
|
-
What options should this question have?"""
|
72
|
-
),
|
73
|
-
question_name="mc_options",
|
74
|
-
)
|
75
|
-
survey = q_type.add_question(q_options_mc).add_stop_rule(
|
76
|
-
"question_type", f"question_type not in {option_questions}"
|
77
|
-
)
|
78
|
-
type_results = survey.by(label_questions_scenarios).by(m).run()
|
79
|
-
type_results.select("question", "question_type", "mc_options").print()
|
80
|
-
|
81
|
-
# breakpoint()
|
82
|
-
|
83
|
-
question_types = type_results.select("question_type").to_list()
|
84
|
-
options = type_results.select("mc_options").to_list()
|
85
|
-
# question_types, options = type_results.select(
|
86
|
-
# "question_type", "mc_options"
|
87
|
-
# ).to_list()
|
88
|
-
|
89
|
-
type_results.select("question", "question_type", "mc_options").print()
|
90
|
-
|
91
|
-
# if the question is a yes/no question, we need to set the options to be yes/no
|
92
|
-
types_to_questions = defaultdict(list)
|
93
|
-
for question_type, question in zip(question_types, data.questions):
|
94
|
-
types_to_questions[question_type].append(question)
|
95
|
-
|
96
|
-
questions_to_options = dict(zip(data.questions, options))
|
97
|
-
question_to_option_labels = dict(
|
98
|
-
zip(data.questions, len(data.questions) * [None])
|
99
|
-
)
|
100
|
-
for question in types_to_questions.get("yes_no", []):
|
101
|
-
questions_to_options[question] = ["Yes", "No"]
|
102
|
-
|
103
|
-
for question in types_to_questions.get("linear_scale", []):
|
104
|
-
options = questions_to_options[question]
|
105
|
-
questions_to_options[question] = list(range(len(options)))
|
106
|
-
question_to_option_labels[question] = options
|
107
|
-
|
108
|
-
return self.output(
|
109
|
-
questions=data.questions,
|
110
|
-
types=question_types,
|
111
|
-
options=list(questions_to_options.values()),
|
112
|
-
option_labels=list(question_to_option_labels.values()),
|
113
|
-
)
|
114
|
-
|
115
|
-
|
116
|
-
if __name__ == "__main__":
|
117
|
-
pipeline = gen_pipeline([StageQuestions, StageLabelQuestions])
|
118
|
-
|
119
|
-
results = pipeline.process(
|
120
|
-
pipeline.input(
|
121
|
-
overall_question="What are some factors that could determine whether someone likes ice cream?"
|
122
|
-
)
|
123
|
-
)
|
124
|
-
|
125
|
-
print(results.options)
|
edsl/auto/StagePersona.py
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
from textwrap import dedent
|
2
|
-
from dataclasses import dataclass
|
3
|
-
from typing import List
|
4
|
-
|
5
|
-
from edsl.auto.StageBase import StageBase
|
6
|
-
from edsl.auto.StageBase import FlowDataBase
|
7
|
-
from edsl import Model
|
8
|
-
from edsl.auto.StageQuestions import StageQuestions
|
9
|
-
|
10
|
-
from edsl.questions import QuestionFreeText
|
11
|
-
from edsl.scenarios import Scenario
|
12
|
-
|
13
|
-
from edsl.auto.utilities import gen_pipeline
|
14
|
-
|
15
|
-
|
16
|
-
class StagePersona(StageBase):
|
17
|
-
input = StageQuestions.output
|
18
|
-
|
19
|
-
@dataclass
|
20
|
-
class Output(FlowDataBase):
|
21
|
-
persona: str
|
22
|
-
questions: List[str]
|
23
|
-
|
24
|
-
output = Output
|
25
|
-
|
26
|
-
def handle_data(self, data):
|
27
|
-
m = Model()
|
28
|
-
q_persona = QuestionFreeText(
|
29
|
-
question_text=dedent(
|
30
|
-
"""\
|
31
|
-
Imagine a person from the population {{ population }} responding to these questions: "{{ questions }}"
|
32
|
-
Make up a 1 paragraph persona for this person who would have answers for these questions.
|
33
|
-
"""
|
34
|
-
),
|
35
|
-
question_name="persona",
|
36
|
-
)
|
37
|
-
results = (
|
38
|
-
q_persona.by(m)
|
39
|
-
.by(Scenario({"questions": data.questions, "population": data.population}))
|
40
|
-
.run()
|
41
|
-
)
|
42
|
-
print("Constructing a persona that could answer the following questions:")
|
43
|
-
print(data.questions)
|
44
|
-
results.select("persona").print(
|
45
|
-
pretty_labels={
|
46
|
-
"answer.persona": f"Persona that can answer: {data.questions}"
|
47
|
-
},
|
48
|
-
split_at_dot=False,
|
49
|
-
)
|
50
|
-
persona = results.select("persona").first()
|
51
|
-
return self.output(persona=persona, questions=data.questions)
|
52
|
-
|
53
|
-
|
54
|
-
if __name__ == "__main__":
|
55
|
-
pipeline = gen_pipeline([StageQuestions, StagePersona])
|
56
|
-
pipeline.process(
|
57
|
-
pipeline.input(
|
58
|
-
overall_question="What are some factors that could determine whether someone likes ice cream?",
|
59
|
-
persona="People",
|
60
|
-
)
|
61
|
-
)
|
@@ -1,88 +0,0 @@
|
|
1
|
-
from textwrap import dedent
|
2
|
-
from dataclasses import dataclass
|
3
|
-
|
4
|
-
from typing import List
|
5
|
-
|
6
|
-
from edsl.auto.StageBase import StageBase
|
7
|
-
from edsl.auto.StageBase import FlowDataBase
|
8
|
-
|
9
|
-
from edsl.auto.StagePersonaDimensionValues import StagePersonaDimensionValues
|
10
|
-
|
11
|
-
from edsl.questions import QuestionList
|
12
|
-
from edsl.scenarios import Scenario
|
13
|
-
from edsl import Model
|
14
|
-
from edsl.auto.utilities import gen_pipeline
|
15
|
-
|
16
|
-
|
17
|
-
class StagePersonaDimensionValueRanges(StageBase):
|
18
|
-
input = StagePersonaDimensionValues.output
|
19
|
-
|
20
|
-
@dataclass
|
21
|
-
class Output(FlowDataBase):
|
22
|
-
focal_dimension_values: List[dict]
|
23
|
-
mapping: dict
|
24
|
-
persona: str
|
25
|
-
|
26
|
-
output = Output
|
27
|
-
|
28
|
-
def handle_data(self, data):
|
29
|
-
# breakpoint()
|
30
|
-
"""Goal with this stage is to, for each dimension, get a range of values that the persona might have for that dimension."""
|
31
|
-
dimension_values = data["dimension_values"]
|
32
|
-
attribute_results = data["attribute_results"]
|
33
|
-
persona = data["persona"]
|
34
|
-
m = Model()
|
35
|
-
d = dict(zip(attribute_results, dimension_values))
|
36
|
-
q = QuestionList(
|
37
|
-
question_text=dedent(
|
38
|
-
"""\
|
39
|
-
Consider the following persona: {{ persona }}.
|
40
|
-
They were categorized as having the following attributes: {{ d }}.
|
41
|
-
For this dimension: {{ focal_dimension }},
|
42
|
-
What are values that other people might have on this attribute?
|
43
|
-
"""
|
44
|
-
),
|
45
|
-
question_name="focal_dimension_values",
|
46
|
-
)
|
47
|
-
s = [
|
48
|
-
Scenario({"persona": persona, "d": d, "focal_dimension": k})
|
49
|
-
for k in d.keys()
|
50
|
-
]
|
51
|
-
results = q.by(s).by(m).run()
|
52
|
-
# breakpoint()
|
53
|
-
results.select("focal_dimension", "answer.*").print(
|
54
|
-
pretty_labels={
|
55
|
-
"scenario.focal_dimension": f"Dimensions of a persona",
|
56
|
-
"answer.focal_dimension_values": f"Values a person might have for that dimension",
|
57
|
-
},
|
58
|
-
split_at_dot=False,
|
59
|
-
)
|
60
|
-
|
61
|
-
focal_dimension_values = results.select("focal_dimension_values").to_list()
|
62
|
-
mapping = dict(zip(attribute_results, focal_dimension_values))
|
63
|
-
return self.output(
|
64
|
-
focal_dimension_values=focal_dimension_values,
|
65
|
-
mapping=mapping,
|
66
|
-
persona=persona,
|
67
|
-
)
|
68
|
-
|
69
|
-
|
70
|
-
if __name__ == "__main__":
|
71
|
-
from edsl.auto.StageQuestions import StageQuestions
|
72
|
-
from edsl.auto.StagePersona import StagePersona
|
73
|
-
from edsl.auto.StagePersonaDimensions import StagePersonaDimensions
|
74
|
-
|
75
|
-
pipeline = gen_pipeline(
|
76
|
-
[
|
77
|
-
StageQuestions,
|
78
|
-
StagePersona,
|
79
|
-
StagePersonaDimensions,
|
80
|
-
StagePersonaDimensionValues,
|
81
|
-
StagePersonaDimensionValueRanges,
|
82
|
-
]
|
83
|
-
)
|
84
|
-
pipeline.process(
|
85
|
-
pipeline.input(
|
86
|
-
overall_question="What are some factors that could determine whether someone likes ice cream?"
|
87
|
-
)
|
88
|
-
)
|
@@ -1,74 +0,0 @@
|
|
1
|
-
from textwrap import dedent
|
2
|
-
from dataclasses import dataclass
|
3
|
-
|
4
|
-
from typing import List, Dict
|
5
|
-
|
6
|
-
from edsl.auto.StageBase import StageBase
|
7
|
-
from edsl.auto.StageBase import FlowDataBase
|
8
|
-
|
9
|
-
from edsl.auto.StagePersonaDimensions import StagePersonaDimensions
|
10
|
-
from edsl import Model
|
11
|
-
from edsl.questions import QuestionList, QuestionExtract
|
12
|
-
from edsl.scenarios import Scenario
|
13
|
-
|
14
|
-
from edsl.auto.utilities import gen_pipeline
|
15
|
-
|
16
|
-
|
17
|
-
class StagePersonaDimensionValues(StageBase):
|
18
|
-
input = StagePersonaDimensions.output
|
19
|
-
|
20
|
-
@dataclass
|
21
|
-
class Output(FlowDataBase):
|
22
|
-
attribute_results: List[str]
|
23
|
-
dimension_values: Dict[str, str]
|
24
|
-
persona: str
|
25
|
-
|
26
|
-
output = Output
|
27
|
-
|
28
|
-
def handle_data(self, data):
|
29
|
-
attribute_results = data.attribute_results
|
30
|
-
persona = data.persona
|
31
|
-
m = Model()
|
32
|
-
q = QuestionExtract(
|
33
|
-
question_text=dedent(
|
34
|
-
"""\
|
35
|
-
This is a persona: "{{ persona }}"
|
36
|
-
They vary on the following dimensions: "{{ attribute_results }}"
|
37
|
-
For each dimenion, what are some values that this persona might have for that dimension?
|
38
|
-
Please keep answers very short, ideally one word.
|
39
|
-
"""
|
40
|
-
),
|
41
|
-
answer_template={k: None for k in attribute_results},
|
42
|
-
question_name="dimension_values",
|
43
|
-
)
|
44
|
-
results = (
|
45
|
-
q.by(Scenario({"attribute_results": attribute_results, "persona": persona}))
|
46
|
-
.by(m)
|
47
|
-
.run()
|
48
|
-
)
|
49
|
-
results.select("attribute_results", "dimension_values").print()
|
50
|
-
return self.output(
|
51
|
-
dimension_values=results.select("dimension_values").first(),
|
52
|
-
attribute_results=attribute_results,
|
53
|
-
persona=persona,
|
54
|
-
)
|
55
|
-
|
56
|
-
|
57
|
-
if __name__ == "__main__":
|
58
|
-
from edsl.auto.StageQuestions import StageQuestions
|
59
|
-
from edsl.auto.StagePersona import StagePersona
|
60
|
-
from edsl.auto.StagePersonaDimensions import StagePersonaDimensions
|
61
|
-
|
62
|
-
pipeline = gen_pipeline(
|
63
|
-
[
|
64
|
-
StageQuestions,
|
65
|
-
StagePersona,
|
66
|
-
StagePersonaDimensions,
|
67
|
-
StagePersonaDimensionValues,
|
68
|
-
]
|
69
|
-
)
|
70
|
-
pipeline.process(
|
71
|
-
pipeline.input(
|
72
|
-
overall_question="What are some factors that could determine whether someone likes ice cream?"
|
73
|
-
)
|
74
|
-
)
|
@@ -1,69 +0,0 @@
|
|
1
|
-
from textwrap import dedent
|
2
|
-
from dataclasses import dataclass
|
3
|
-
|
4
|
-
from typing import List
|
5
|
-
|
6
|
-
from edsl.auto.StageBase import StageBase
|
7
|
-
from edsl.auto.StageBase import FlowDataBase
|
8
|
-
|
9
|
-
from edsl.auto.StagePersona import StagePersona
|
10
|
-
|
11
|
-
from edsl.questions import QuestionList
|
12
|
-
from edsl.scenarios import Scenario
|
13
|
-
from edsl import Model
|
14
|
-
|
15
|
-
from edsl.auto.utilities import gen_pipeline
|
16
|
-
|
17
|
-
|
18
|
-
class StagePersonaDimensions(StageBase):
|
19
|
-
input = StagePersona.output
|
20
|
-
|
21
|
-
@dataclass
|
22
|
-
class Output(FlowDataBase):
|
23
|
-
attribute_results: List[str]
|
24
|
-
persona: str
|
25
|
-
|
26
|
-
output = Output
|
27
|
-
|
28
|
-
def handle_data(self, data):
|
29
|
-
q_attributes = QuestionList(
|
30
|
-
question_text=dedent(
|
31
|
-
"""\
|
32
|
-
Here is a persona: "{{ persona }}"
|
33
|
-
It was construced to be someone who could answer these questions: "{{ questions }}"
|
34
|
-
|
35
|
-
We want to identify the general dimensions that make up this persona.
|
36
|
-
E.g., if the person is desribed as 'happy' then a dimenion would be 'mood'
|
37
|
-
"""
|
38
|
-
),
|
39
|
-
question_name="find_attributes",
|
40
|
-
)
|
41
|
-
m = Model()
|
42
|
-
results = (
|
43
|
-
q_attributes.by(
|
44
|
-
Scenario({"persona": data.persona, "questions": data.questions})
|
45
|
-
)
|
46
|
-
.by(m)
|
47
|
-
.run()
|
48
|
-
)
|
49
|
-
(
|
50
|
-
results.select("find_attributes").print(
|
51
|
-
pretty_labels={
|
52
|
-
"answer.find_attributes": f'Persona dimensions for: "{data.persona}"'
|
53
|
-
},
|
54
|
-
split_at_dot=False,
|
55
|
-
)
|
56
|
-
)
|
57
|
-
attribute_results = results.select("find_attributes").first()
|
58
|
-
return self.output(attribute_results=attribute_results, persona=data.persona)
|
59
|
-
|
60
|
-
|
61
|
-
if __name__ == "__main__":
|
62
|
-
from edsl.auto.StageQuestions import StageQuestions
|
63
|
-
|
64
|
-
pipeline = gen_pipeline([StageQuestions, StagePersona, StagePersonaDimensions])
|
65
|
-
pipeline.process(
|
66
|
-
pipeline.input(
|
67
|
-
overall_question="What are some factors that could determine whether someone likes ice cream?"
|
68
|
-
)
|
69
|
-
)
|
edsl/auto/StageQuestions.py
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
from dataclasses import dataclass
|
2
|
-
from typing import List
|
3
|
-
from textwrap import dedent
|
4
|
-
|
5
|
-
|
6
|
-
from edsl import Scenario
|
7
|
-
from edsl import Model
|
8
|
-
from edsl.questions.QuestionList import QuestionList
|
9
|
-
|
10
|
-
from edsl.auto.StageBase import StageBase
|
11
|
-
from edsl.auto.StageBase import FlowDataBase
|
12
|
-
|
13
|
-
from edsl.auto.utilities import gen_pipeline
|
14
|
-
|
15
|
-
|
16
|
-
class StageQuestions(StageBase):
|
17
|
-
"This stages takes as input an overall question and returns a list of questions"
|
18
|
-
|
19
|
-
@dataclass
|
20
|
-
class Input(FlowDataBase):
|
21
|
-
overall_question: str
|
22
|
-
population: str
|
23
|
-
|
24
|
-
@dataclass
|
25
|
-
class Output(FlowDataBase):
|
26
|
-
questions: List[str]
|
27
|
-
population: str
|
28
|
-
|
29
|
-
input = Input
|
30
|
-
output = Output
|
31
|
-
|
32
|
-
def handle_data(self, data):
|
33
|
-
m = Model()
|
34
|
-
overall_question = data.overall_question
|
35
|
-
population = data.population
|
36
|
-
s = Scenario({"overall_question": overall_question, "population": population})
|
37
|
-
q = QuestionList(
|
38
|
-
question_text=dedent(
|
39
|
-
"""\
|
40
|
-
Suppose I am interested in the question:
|
41
|
-
"{{ overall_question }}"
|
42
|
-
What would be some survey questions I could ask to {{ population }} that might shed light on this question?
|
43
|
-
"""
|
44
|
-
),
|
45
|
-
question_name="questions",
|
46
|
-
)
|
47
|
-
results = q.by(s).by(m).run()
|
48
|
-
(
|
49
|
-
results.select("questions").print(
|
50
|
-
pretty_labels={
|
51
|
-
"answer.questions": f'Questions for overall question: "{overall_question }"'
|
52
|
-
},
|
53
|
-
split_at_dot=False,
|
54
|
-
)
|
55
|
-
)
|
56
|
-
|
57
|
-
raw_questions = results.select("questions").first()
|
58
|
-
questions = [q.replace("'", "").replace(":", "") for q in raw_questions]
|
59
|
-
return self.Output(questions=questions, population=population)
|
60
|
-
|
61
|
-
|
62
|
-
if __name__ == "__main__":
|
63
|
-
pipeline = gen_pipeline([StageQuestions])
|
64
|
-
|
65
|
-
pipeline.process(
|
66
|
-
pipeline.input(
|
67
|
-
overall_question="What are some factors that could determine whether someone likes ice cream?",
|
68
|
-
population="Consumers",
|
69
|
-
)
|
70
|
-
)
|
71
|
-
|
72
|
-
results = StageQuestions.func(
|
73
|
-
overall_question="Why aren't my students studying more?", population="Tech"
|
74
|
-
)
|
@@ -1,21 +0,0 @@
|
|
1
|
-
import random
|
2
|
-
from typing import Dict, List, Any, TypeVar, Generator, Optional
|
3
|
-
|
4
|
-
from textwrap import dedent
|
5
|
-
|
6
|
-
# from edsl.language_models.model_interfaces.LanguageModelOpenAIFour import LanguageModelOpenAIFour
|
7
|
-
from edsl import Model
|
8
|
-
from edsl.agents.AgentList import AgentList
|
9
|
-
from edsl.results.Results import Results
|
10
|
-
from edsl import Agent
|
11
|
-
|
12
|
-
from edsl import Scenario
|
13
|
-
from edsl.surveys.Survey import Survey
|
14
|
-
|
15
|
-
from edsl.questions.QuestionMultipleChoice import QuestionMultipleChoice
|
16
|
-
from edsl.questions.QuestionFreeText import QuestionFreeText
|
17
|
-
from edsl.auto.utilities import gen_pipeline
|
18
|
-
from edsl.utilities.naming_utilities import sanitize_string
|
19
|
-
|
20
|
-
|
21
|
-
m = Model()
|