如何使用 boto3 提交 Mechanical Turk 外部问题

2024-02-19

我正在尝试使用 boto3 以编程方式创建一个关于 Mechanical Turk 的问题,但我似乎做错了一些事情,因为ExternalQuestion所需的数据结构create_hit似乎不见了。

我尝试像这样创建 HIT:

import boto3

#...

client = boto3.client(
    'mturk',
    endpoint_url=endpoint_url,
    region_name=region_name,
    aws_access_key_id=aws_access_key_id,
    aws_secret_access_key=aws_secret_access_key,
)

question = ExternalQuestion(external_url=question_target, frame_height=800)

response = client.create_hit(
        MaxAssignments=10,
        Title='Test',
        Description='This is a test of ExternalQuestion',
        Question=question,
        AssignmentDurationInSeconds=60,
        LifetimeInSeconds=24 * 60 * 60,
        Reward=0.01)

哪个失败了:

Traceback (most recent call last):
  File "createTask.py", line 21, in <module>
    question = ExternalQuestion(external_url=question_target, frame_height=800)
NameError: name 'ExternalQuestion' is not defined

非常感谢任何有关如何进行的建议。


如果您还有旧版本boto安装完毕后,最简单的就是使用get_as_xml()的方法ExternalQuestion:

import boto3
from boto.mturk.question import ExternalQuestion

mturk = boto3.client(
    'mturk',
    endpoint_url='https://mturk-requester-sandbox.us-east-1.amazonaws.com',
    region_name='us-east-1',
    aws_access_key_id='your_access_key',
    aws_secret_access_key='your_secret_key',
)

question = ExternalQuestion("https://example.com/mypage.html", frame_height=600)
new_hit = mturk.create_hit(
    Title='Answer a simple question',
    Description='Help research a topic',
    Keywords='question, answer, research',
    Reward='0.15',
    MaxAssignments=1,
    LifetimeInSeconds=172800,
    AssignmentDurationInSeconds=600,
    AutoApprovalDelayInSeconds=14400,
    Question=question.get_as_xml(),   # <--- this does the trick
)
print "HITID = " + new_hit['HIT']['HITId']

如果你看一下输出question.get_as_xml(),你会发现它非常简单,你可以自己生成它:

<ExternalQuestion xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2006-07-14/ExternalQuestion.xsd">
   <ExternalURL>https://example.com/mypage.html</ExternalURL>
   <FrameHeight>600</FrameHeight>
</ExternalQuestion>

您需要确保对问题 URL 中的字符进行转义,使其成为有效的 XML 文件。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 boto3 提交 Mechanical Turk 外部问题 的相关文章

随机推荐