Pular para o conteúdo
Esta página ainda não está disponível no seu idioma. Exibindo a versão em inglês.

Spreadsheet and Code Annotation

Show tables from JSON, CSV, TSV, or Excel files and source code to annotators with the spreadsheet and code displays, and mark spans in code.

Potato shows tabular data with the spreadsheet display and source code with the code display. Both are display types under instance_display, so annotators answer ordinary annotation schemes placed beside the table or the code, such as a multiselect of data-quality problems or a span scheme for marking defects in a function. A table or a snippet can be written into the data file or read from a file on disk, and Potato renders a file-loaded table or snippet differently from one written into the data file.

Tables in the data file

The simplest table is an object with a columns list and a rows list inside each item. The config below shows each table under a note on what the table should contain and asks the annotator two questions about it:

yaml
annotation_task_name: "Table Quality Review"
task_dir: .
output_annotation_dir: annotation_output
data_files:
  - data/tables.json
 
item_properties:
  id_key: id
  text_key: description
 
instance_display:
  fields:
    - key: description
      type: text
      label: "What this table should contain"
    - key: table
      type: spreadsheet
      label: "Table"
      display_options:
        max_height: 400
        compact: true
        header_style: light
 
annotation_schemes:
  - annotation_type: multiselect
    name: issues
    description: "Which problems does this table have?"
    labels:
      - name: missing_values
      - name: inconsistent_formats
      - name: duplicate_rows
      - name: impossible_values
      - name: no_issues
  - annotation_type: text
    name: affected_rows
    description: "Order IDs of the rows with a problem, separated by commas"

The data file holds one table per item. The second item names a CSV file in place of a table, and the next section covers file paths:

json
[
  {
    "id": "sales_q1",
    "description": "Customer sales for Q1 2024, one row per order.",
    "table": {
      "columns": ["order", "customer", "date", "amount"],
      "rows": [
        ["A-101", "Ruiz", "2024-01-15", "1250.00"],
        ["A-102", "Okafor", "01/20/2024", "890.50"],
        ["A-103", "", "2024-01-22", "1500.00"],
        ["A-101", "Ruiz", "2024-01-15", "1250.00"]
      ]
    }
  },
  {
    "id": "survey_wave1",
    "description": "Wave 1 survey responses exported from the field team.",
    "table": "tables/survey_wave1.csv"
  }
]

Potato reads three shapes of table data, and the shape decides where the column headers come from:

  • Columns and rows. An object with columns (or headers) and rows shows the named columns in the order given, and the rows may be lists or objects keyed by column name. A column left out of columns is hidden only when the rows are objects. A list row shows every cell, so the row [1, 2, 3] under columns: [a, b] shows a third cell with no header.
  • A list of objects. Each object is one row, and the columns are every key that any row has, in the order the keys first appear. A row without a given key gets an empty cell, so a JSON-lines export that drops empty fields keeps every column.
  • A list of lists. Each inner list is one row, and the table has no header line unless header_row: true turns the first inner list into the headers.

Potato writes a cell holding an object or a list as indented JSON. The table's cell style sets no white-space rule, so the browser likely shows the JSON on one line. Cell values are escaped before they reach the page, and a cell containing HTML shows the HTML as text.

Tables from CSV, TSV, and Excel files

When the table field holds a file path instead of table data, Potato reads the file on the server and shows the result. A relative path resolves against task_dir, the way tables/survey_wave1.csv does in the data file above. Every table file needs the openpyxl library, CSV and TSV files included. The openpyxl library is not a core dependency, so without openpyxl a CSV file shows "Unsupported data format" in place of a table. Install the formats extra for any spreadsheet file. The extra installs openpyxl along with the PDF, Word, Markdown, and Pygments libraries:

bash
pip install "potato-annotation[formats]"

The file reader runs with fixed settings in 2.14.0:

  • The first row of the file becomes the column headers.
  • Blank lines in a CSV or TSV file and empty rows in a workbook are skipped, and Potato reads only the first 1,000 data rows. In a workbook the 1,000-row limit counts physical rows, empty ones included, so a sheet with blank rows shows fewer than 1,000 rows of data.
  • A workbook shows only the sheet that was active when the workbook was last saved. No option selects a different sheet, so export every other sheet as a separate CSV file to annotate it.
  • A formula cell shows the last value Excel saved for the formula.
  • A merged range shows the merged value in the top-left cell and leaves the rest of the range empty.
  • An empty cell in a CSV or TSV file shows as nan, because Potato reads CSV and TSV files with pandas. An empty cell in an Excel workbook shows as empty.
  • The pandas reader also guesses a type for each CSV or TSV column. A cell holding 007 shows as 7.0, and an integer column with a blank cell shows 5 as 5.0.
  • Legacy .xls workbooks do not load. The openpyxl library reads only the newer .xlsx format, and the field shows "Unsupported data format" in place of a table. Convert the workbook to .xlsx before adding the path.

A file-loaded table keeps max_height, max_width, and the rounded corners of border_style: rounded, and ignores the other options that style rows and cells (striped, compact, header_style, and the others), because the file reader builds a separate plain table. The reader's settings cannot be changed from the config. display_options accepts the options in the table further down, along with the resizable and min_height options that every display type takes. Potato stops at startup on any other key.

Labels on rows and whole tables

Annotation schemes attach to the table as a whole, the way a multiselect or radio scheme attaches to any item. A spreadsheet field accepts span_target: true without an error, and the flag does nothing beyond a warning in the server log. Potato 2.14.0 saves no row or cell selection with the annotation, whatever annotation_mode and selectable are set to. Two designs collect row-level answers instead. First, ask for the affected rows in a text scheme, as affected_rows does in the config above, and give the table an identifier column so annotators can name rows by identifier. Second, put one row in each item when every row needs its own label, and show the full table in a second field as context.

Spreadsheet display options

OptionDefaultEffect
annotation_moderowrow, cell, or range; changes the table's markup, and no selection is saved
show_headerstrueShows the header row when the data has headers
header_rowfalseUses the first inner list of a list of lists as the headers
max_height400Height before the table scrolls; a bare number means pixels
max_widthnoneWidth before the table scrolls sideways
stripedtrueAlternating row shading
hoverabletrueHighlights the row under the pointer
compactfalseTighter table styling
border_styledefaultdefault, bordered, minimal, rounded, or none
header_styledefaultdefault, dark, primary, gradient, light, or transparent
custom_classnoneExtra CSS classes on the table, as a string or a list
custom_cssnoneInline CSS on the table
selectablefalseRow checkboxes in row mode; the ticks are not saved
sortablefalseAccepted, with no effect in 2.14.0
filterablefalseAccepted, with no effect in 2.14.0

sortable marks the header cells as sortable, but the script that sorts columns is not loaded on the annotation page in 2.14.0, so clicking a header does nothing. Leave selectable off as well, since an annotator who ticks a row checkbox loses the tick on the next item.

Source code

The code display shows a code string from the data file in a monospaced block. The config below asks annotators to highlight defects in a function and give a merge verdict:

yaml
annotation_task_name: "Code Defect Spans"
task_dir: .
output_annotation_dir: annotation_output
data_files:
  - data/functions.json
 
item_properties:
  id_key: id
  text_key: summary
 
instance_display:
  fields:
    - key: summary
      type: text
      label: "What the function is meant to do"
    - key: code
      type: code
      label: "Function under review"
      span_target: true
      display_options:
        language: python
        max_height: 500
 
annotation_schemes:
  - annotation_type: span
    name: defects
    description: "Highlight each defect in the code"
    labels:
      - name: bug
      - name: security
      - name: style
  - annotation_type: radio
    name: verdict
    description: "Would you merge this function?"
    labels:
      - name: merge
      - name: merge_after_fixes
      - name: reject

Each item holds the code as one string with \n line breaks:

json
[
  {
    "id": "auth_01",
    "summary": "Check a username and password against the user store.",
    "code": "def authenticate(username, password):\n    users = {'admin': 'password123'}\n    if username in users and users[username] == password:\n        return True\n    return False"
  }
]

span_target: true lets the span scheme highlight characters in the code. Potato stores each span the same way as a span on a text field, with its label and its start and end character offsets into the code string. In span-target mode the display shows the code as one preformatted block without line numbers or highlighted lines, because a table of numbered lines would throw off the character offsets.

Without span_target, the display numbers each line, and three options help with an excerpt from a longer file. start_line gives the first line the number the line has in the original file, highlight_lines shades the listed lines, and wrap_lines wraps long lines instead of scrolling sideways. The instance_display block below replaces the one in the config above for a reading task:

yaml
instance_display:
  fields:
    - key: code
      type: code
      label: "Excerpt from billing.py"
      display_options:
        language: python
        start_line: 120
        highlight_lines: [123]
        wrap_lines: true

highlight_lines counts in the displayed numbering, so with start_line: 120 the fourth line of the snippet is line 123.

Potato 2.14.0 does not color code by syntax. language adds a class and a data attribute to the block, and no stylesheet or script in the release colors the tokens, so Potato shows every snippet in one color. theme: dark switches the block to light text on a dark background. The copy button that copy_button adds has no click handler in 2.14.0, and copy_button: false keeps a button that does nothing off the page.

Code from files

A code field may hold a path to a source file instead of the code itself. Potato recognizes 48 file extensions, and the list covers .py, .js, .ts, .java, .go, .rs, .sql, and 41 others. Potato reads a recognized file relative to task_dir and renders the file with line numbers through Pygments, which comes with the formats extra. Without Pygments installed, the field shows the file path itself as a one-line snippet. A file-loaded snippet suits reading and rating tasks only. The rendered file has none of the markup that Potato's span tools attach to, so put the code into the data file whenever annotators highlight spans. language, show_line_numbers, start_line, highlight_lines, and wrap_lines do not apply to a file-loaded snippet.

Code display options

OptionDefaultEffect
languagenoneAdds a language class and data attribute; no coloring in 2.14.0
show_line_numberstrueNumbers each line; off in span-target mode
start_line1Number given to the first line
highlight_linesnoneList of line numbers to shade, in the displayed numbering
wrap_linesfalseWraps long lines instead of scrolling sideways
max_height500Height before the block scrolls; a bare number means pixels
max_widthnoneWidth before the block scrolls sideways
themedefaultdefault or dark
copy_buttontrueDraws a copy button with no click handler in 2.14.0

The format_handling block

format_handling is a real top-level key, and Potato checks the values inside the block at startup:

KeyAccepted values
enabledtrue or false
default_formatauto, pdf, docx, markdown, spreadsheet, or code
pdf.extraction_modetext, ocr, or hybrid
pdf.cache_extractedtrue or false
spreadsheet.annotation_moderow, cell, or range
spreadsheet.max_rowsa positive integer

Nothing in Potato 2.14.0 reads the block after checking the values. The file type always comes from the extension, a table file is read with the fixed settings listed earlier, and spreadsheet.max_rows leaves the 1,000-row limit unchanged. Leave the block out of new configs. An existing block does no harm.

The code display and coding_trace

The code display shows one snippet or one file. A coding agent's session belongs in the coding_trace display, which shows tool calls, file diffs, and terminal output from a trace rather than a code string. The coding_trace display has its own options (e.g., diff_view and show_file_tree), and options do not transfer between the two displays. Potato rejects highlight_lines on a coding_trace field and diff_view on a code field at startup, and the error lists the options the display accepts. Coding agent annotation covers the trace display.

Stored annotations and export

Answers to the schemes beside a table or a snippet are stored like any other annotation, in <output_annotation_dir>/<user>/user_state.json, and export_annotation_format writes the answers out in any of the export formats. Each span on inline code keeps its label and its start and end offsets into the code string through the export.

Example projects

Two runnable examples ship in the Potato repository. examples/advanced/spreadsheet-annotation shows three inline tables with a data-quality multiselect and a notes field. examples/advanced/code-annotation shows Python functions with a quality rating, an issue checklist, and written feedback. The code example sets span_target: true without a span scheme, so the functions show without line numbers until span_target is removed. Start either example from the repository root:

bash
potato start examples/advanced/spreadsheet-annotation/config.yaml -p 8000

Further reading