首页
/ Expected Parrot Domain-Specific Language (EDSL) 使用教程

Expected Parrot Domain-Specific Language (EDSL) 使用教程

2025-04-17 07:57:43作者:段琳惟

1. 项目介绍

Expected Parrot Domain-Specific Language (EDSL) 是一个专为计算社会科学和市场研究设计的领域特定语言。它使得设计、运行包含众多AI代理和大型语言模型(LLMs)的调查和实验变得简单。用户可以使用EDSL进行复杂的数据标注和其他研究任务,并且生成的结果格式化为指定的数据集,可以免费复制,并带有内置的分析、可视化和协作方法。

2. 项目快速启动

首先,确保您的Python环境版本在3.9到3.12之间。然后,通过以下命令安装EDSL:

pip install edsl

接下来,您需要创建一个账户以在Expected Parrot服务器上运行调查,并访问存储的响应的通用远程缓存,以便复制结果。

  • 选择使用自己的语言模型密钥,或者获取一个Expected Parrot密钥来一次性访问所有可用模型。
  • 安全地管理您团队的密钥、开支和使用情况。

运行入门教程和探索其他演示笔记本,以了解各种用例。

3. 应用案例和最佳实践

以下是使用EDSL的一些典型应用案例:

设计调查问卷

使用EDSL中的QuestionMultipleChoice类来创建一个多项选择题:

from edsl import QuestionMultipleChoice

q = QuestionMultipleChoice(
    question_name="example",
    question_text="How do you feel today?",
    question_options=["Bad", "OK", "Good"]
)
results = q.run()

使用参数化提示

利用ScenarioListQuestionLinearScale来轻松控制参数化提示:

from edsl import ScenarioList, QuestionLinearScale

q = QuestionLinearScale(
    question_name="example",
    question_text="How much do you enjoy {{ scenario.activity }}?",
    question_options=[1, 2, 3, 4, 5],
    option_labels={1: "Not at all", 5: "Very much"}
)
sl = ScenarioList.from_list("activity", ["coding", "sleeping"])
results = q.by(sl).run()

构建AI代理人格

创建带有相关特征的AI代理,为调查提供多样化的响应:

from edsl import AgentList, QuestionList

al = AgentList(
    Agent(traits={"persona": p}) for p in ["botanist", "detective"]
)
q = QuestionList(
    question_name="example",
    question_text="What are your favorite colors?",
    max_list_items=3
)
results = q.by(al).run()

简化LLM访问

选择使用自己的API密钥或Expected Parrot密钥来访问所有可用的LLM:

from edsl import ModelList, QuestionFreeText

ml = ModelList(Model(m) for m in ["gpt-4o", "gemini-1.5-flash"])
q = QuestionFreeText(
    question_name="example",
    question_text="What is your top tip for using LLMs to answer surveys?"
)
results = q.by(ml).run()

使用管道和跳过逻辑

构建丰富的数据标注流程,并添加调查逻辑,如跳过和停止规则:

from edsl import QuestionMultipleChoice, QuestionFreeText, Survey

q1 = QuestionMultipleChoice(
    question_name="color",
    question_text="What is your favorite primary color?",
    question_options=["red", "yellow", "blue"]
)
q2 = QuestionFreeText(
    question_name="flower",
    question_text="Name a flower that is {{ color.answer }}"
)
survey = Survey(questions=[q1, q2])
results = survey.run()

4. 典型生态项目

EDSL项目作为一个开源项目,其生态系统包括:

  • Coop:一个集成的平台,用于运行实验、分享工作流程和启动混合人类/AI调查。
  • Discord:获取更新和讨论的社区平台。
  • GitHub:项目的代码托管和开发协作平台。
  • PyPI:Python软件包索引,用于包的安装和管理。

通过这些平台和工具,研究人员和开发者可以更有效地进行AI驱动的社会科学和市场研究。

登录后查看全文
热门项目推荐