Widget for Jupyter Notebook to check and annotate data. A simplified version of Prodigy for Jupyter Notebook.
Examples of markup tasks that can be solved using ipyannotate
:
Examples of tasks for which ipyannotate
is not suitable:
ipyannotate
is well-suited for conveniently placing one or several labels for a set of objects (pictures, texts, anything that Jupyter can display).
There is a number of tools that do the same thing: Prodigy, Yandex.Toloka, for example. ipyannotate
is a Jupyter widget, and there are three reasons why it is convenient:
Often the whole process of working with data occurs inside Jupyter Notebook. It is inconvenient to format the data in a json or xml file, send it to another service, upload and parse the results. With ipyannotate
you can mark up the data directly in Jupyter:
from ipyannotate import annotate
from ipyannotate.buttons import (
ValueButton as Button,
NextButton as Next,
BackButton as Back
)
data = [1, 15, 62, 33, 83, 12, 949, 71]
annotation = annotate(data, buttons=[Button('even'), Button('odd'), Back(), Next()])
annotation
Failed to display Jupyter Widget of type Annotation
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
annotation.tasks
[Task(output=1, value=odd), Task(output=15, value=odd), Task(output=62, value=even), Task(output=33, value=odd), Task(output=83, value=odd), Task(output=12, value=even), Task(output=949, value=odd), Task(output=71, value=odd)]
Jupyter has a convenient data presentation system. If the result of the command is a graph, the user sees the picture, not <Figure # 881dabb ...>
like in a regular console. This functionality is available in ipyannotate
, for example, you can conveniently mark out the images:
from glob import glob
from PIL import Image
data = [Image.open(_) for _ in glob('i/dogs_cats/*.jpg')]
annotation = annotate(data, buttons=[Button('dog'), Button('cat'), Back(), Next()])
annotation
Annotation(canvas=OutputCanvas(), progress=Progress(atoms=[<ipyannotate.progress.Atom object at 0x10b37f240>, …
When marking texts by category, all possible topics are often not known in advance. Roughly speaking, before starting work, you cannot set a list of buttons in ipyannotate.annotate
. Widgets are interactive, so you can add a button on the go. Also, for example, intermediate markup results can be stored, annotation.tasks
is updated in memory interactively.
data = [
'tours to turkey',
'lake garda september',
'holets at black sea',
'Smartline Konaktepe Hotel 4*',
'amsterdam where to go',
'hotel dream in a forest',
'kabardinka where to go',
'dubovichi restaurant',
'dali museum'
]
buttons = [
Button('place'),
Button('hotel')
]
controls = [
Back(),
Next()
]
annotation = annotate(data, buttons=buttons + controls)
annotation
Failed to display Jupyter Widget of type Annotation
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
fun = Button('fun')
annotation.toolbar.buttons = buttons + [fun] + controls
The main user interface is the annotate
function, it has one required argumenttasks
— a list of tasks, and three optional: buttons
,display
and multi
data = range(10)
annotate(data, buttons=None, display=None, multi=False)
Failed to display Jupyter Widget of type Annotation
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
By default, buttons
is a list of four: "ok", "err", "back", "next". This set is suitable for simple verification of the results of the work of any classifier. The user can specify his own buttons, customize colors and shortcuts:
from ipyannotate.buttons import (
ValueButton as Button,
BackButton as Back,
NextButton as Next
)
buttons = [
Button(2, label='divisible by 2', color='blue', icon='½ ', shortcut='1'),
Button(3, label='by 3', color='red', icon='⅓ ', shortcut='2'),
Button(5, label='by 5', color='green', icon='⅕ ', shortcut='3'),
]
controls = [
Back(),
Next()
]
annotate(data, buttons=buttons + controls)
Failed to display Jupyter Widget of type Annotation
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
When multi = False
, the widget is in radiobutton mode, the user can specify only one label for the object. If multi = True
you can specify several labels:
buttons = [
Button(2, label='divisible by 2', color='blue', icon='½ ', shortcut='1'),
Button(3, label='by 3', color='red', icon='⅓ ', shortcut='2'),
Button(5, label='by 5', color='green', icon='⅕ ', shortcut='3'),
]
controls = [
Back(),
Next()
]
annotation = annotate(data, buttons=buttons + controls, multi=True)
annotation
Failed to display Jupyter Widget of type Annotation
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
If multi=True
then the value
of annotation.tasks
will be set
:
annotation.tasks
[MultiTask(output=0, value={2, 3, 5}), MultiTask(output=1, value=set()), MultiTask(output=2, value={2}), MultiTask(output=3, value={3}), MultiTask(output=4, value={2}), MultiTask(output=5, value={5}), MultiTask(output=6, value={2, 3}), MultiTask(output=7, value=set()), MultiTask(output=8, value={2}), MultiTask(output=9, value={3})]
By default, the standard IPython.display
is used for output. The user can specify his function, for example, display the path to the file with the picture:
data = {_: Image.open(_) for _ in glob('i/dogs_cats/*.jpg')}
def display_item(item):
from IPython.display import display
path, image = item
print(path)
display(image)
buttons = [
Button('dog', shortcut='1'),
Button('cat', shortcut='2'),
Back(),
Next()
]
annotation = annotate(data.items(), buttons=buttons, display=display_item)
annotation
Annotation(canvas=OutputCanvas(), progress=Progress(atoms=[<ipyannotate.progress.Atom object at 0x10b48d518>, …
See ipyannotate-examples repo for more examples.