Set overlap

Set overlap for tasks at pool, task suite, and task levels.

Steps to follow

1. Import Toloka-Kit

Connect the Toloka-Kit library to your script.

import toloka.client as toloka

2. Instantiate TolokaClient

Replace the sample API key with your own one.

toloka_client = toloka.
TolokaClient
('PlaceYourRealApiKey_Here', 'PRODUCTION');

3. Set overlap at pool level

Create a pool and set the default overlap value for all the tasks which will be uploaded without additionally specifying it. Use the default_overlap_for_new_task_suites value of the Defaults class for that.

Refer to the Create pool recipe for more information on how to create a pool and what parameters you can use.

new_pool = toloka.pool.
Pool
(

project_id='133047',

private_name='Pool with filters',

will_expire=datetime(2030, 1, 1),

reward_per_assignment=0.05,

assignment_max_duration_seconds=60*5,

defaults=toloka.pool.Pool.
Defaults
(default_overlap_for_new_task_suites=1)

)

new_pool = toloka_client.
create_pool
(new_pool)

4. Set overlap at task suite level

Another way to set overlap is specify it when creating a task suite. Use the overlap parameter of the TaskSuite class object to set a specific overlap value to the tasks inside a task suite.

Refer to the Group tasks in task suites recipe for more information on how to create a task suite and what parameters you can use.

tasks = [
toloka.task.
Task
(input_values={'image': 'https://example.com/image_1.png'}),
toloka.task.
Task
(input_values={'image': 'https://example.com/image_2.png'}),
toloka.task.
Task
(input_values={'image': 'https://example.com/image_3.png'})
]
new_task_suite = toloka.task_suite.
TaskSuite
(pool_id=new_pool.id, tasks=tasks, overlap=3)
toloka_client.
create_task_suite
(new_task_suite)

5. Set overlap at task level

Now, create and upload two tasks: one without the overlap parameter (it will be equal to the default value, set at step 3) and one with the overlap parameter set to 2.

Refer to the Upload tasks recipe for more information on how to upload tasks.

tasks = [
# This task will have the default 'overlap' parameter value (1)
toloka.task.
Task
(input_values={'image': 'https://example.com/image_4.png'}, pool_id=new_pool.id),
# This task will have the 'overlap' parameter value set to 2
toloka.task.
Task
(input_values={'image': 'https://example.com/image_5.png'}, pool_id=new_pool.id, overlap=2)
]
new_task_suite = toloka.task_suite.
create_tasks
(tasks, allow_defaults=True, skip_invalid_items=False)

The task uploading progress will look like this.

100%|████████████████████████████████████████████| 100/100 [00:01<00:00, 52.35it/s]

6. Print tasks with different overlap

Use the get_task_suites() request to get the information about the tasks in the task suite you created. For information about tasks uploaded without grouping, use the get_tasks() method. Use the attributes of the returned objects (TaskSuite and Task accordingly) to print the information you need.

for task_suite in toloka_client.
get_task_suites
(pool_id=new_pool.id):

for task in task_suite.tasks:

print(task.id, task_suite.overlap)


for task in toloka_client.
get_tasks
(pool_id=new_pool.id):

print(task.id, task.overlap)

You should get an output with the IDs of the created tasks and their overlap values which looks like this.

7776f1f0-2a58-4a77-af32-d0043ae6df10 3
aaf9b554-cb3b-477e-ba48-d2581004a7ac 3
80ad8ffb-cf15-4c32-9190-93d994bc5110 3
0000160899--63c5414699e537000bb2113f 1
0000160899--63c5414799e537000bb21141 2

Complete code: Set overlap

import toloka.client as toloka
toloka_client = toloka.TolokaClient('PlaceYourRealApiKey_Here', 'PRODUCTION')
new_pool = toloka.pool.Pool(
project_id='133047',
private_name='Pool with filters',
will_expire=datetime(2030, 1, 1),
reward_per_assignment=0.05,
assignment_max_duration_seconds=60*5,
defaults=toloka.pool.Pool.Defaults(default_overlap_for_new_task_suites=1)
)
new_pool = toloka_client.create_pool(new_pool)
tasks = [
toloka.task.Task(input_values={'image': 'https://example.com/image_1.png'}),
toloka.task.Task(input_values={'image': 'https://example.com/image_2.png'}),
toloka.task.Task(input_values={'image': 'https://example.com/image_3.png'})
]
new_task_suite = toloka.task_suite.TaskSuite(pool_id=new_pool.id, tasks=tasks, overlap=3)
toloka_client.create_task_suite(new_task_suite)
tasks = [
toloka.task.Task(input_values={'image': 'https://example.com/image_4.png'}, pool_id=new_pool.id),
toloka.task.Task(input_values={'image': 'https://example.com/image_5.png'}, pool_id=new_pool.id, overlap=2)
]
toloka_client.create_tasks(tasks, allow_defaults=True, skip_invalid_items=False)
for task_suite in toloka_client.get_task_suites(pool_id=new_pool.id):
for task in task_suite.tasks:
print(task.id, task_suite.overlap)
for task in toloka_client.get_tasks(pool_id=new_pool.id):
print(task.id, task.overlap)
List of classes and methods used in this recipe

See also

Last updated: February 7, 2023

Toloka-Kit
OverviewGetting API keyQuick start
Recipes
Reference
toloka.client
toloka.async_client
toloka.autoquality [autoquality]
toloka.metrics
toloka.streaming