How do I specify the root node of a dependency graph?

How do I specify the root node of a dependency graph? (both in the UI and in the json format)

Hi Greg!

I'll quote the notification on the recipe docs, you need to double-click.

The ROOT of the sentence needs to be connected to itself. You can achieve this in the relations interface by selecting the label and double-clicking or double-tapping a token.

To see the JSON requirements, it's usually easiest to annotate one example and to then inspect what it looks like from db-out. I'll demonstate this with a somewhat silly example. Suppose I have this examples.jsonl file:

{"text": "word1 root word2"}

Then I can run Prodigy via:

python -m prodigy dep.correct issue-6449 en_core_web_sm examples.jsonl

And it will render this graph:

CleanShot 2023-03-24 at 12.40.46

When I now save this I can see the output via db-out.

python -m prodigy db-out issue-6449 | jq 

This is what it returns.

{
  "text": "word1 root word2",
  "_input_hash": 1408513149,
  "_task_hash": 848574761,
  "tokens": [
    {
      "text": "word1",
      "start": 0,
      "end": 5,
      "id": 0,
      "ws": true
    },
    {
      "text": "root",
      "start": 6,
      "end": 10,
      "id": 1,
      "ws": true
    },
    {
      "text": "word2",
      "start": 11,
      "end": 16,
      "id": 2,
      "ws": false
    }
  ],
  "relations": [
    {
      "head": 1,
      "child": 0,
      "head_span": {
        "start": 6,
        "end": 10,
        "token_start": 1,
        "token_end": 1,
        "label": null
      },
      "child_span": {
        "start": 0,
        "end": 5,
        "token_start": 0,
        "token_end": 0,
        "label": null
      },
      "color": "#96e8ce",
      "label": "compound"
    },
    {
      "head": 2,
      "child": 1,
      "head_span": {
        "start": 11,
        "end": 16,
        "token_start": 2,
        "token_end": 2,
        "label": null
      },
      "child_span": {
        "start": 6,
        "end": 10,
        "token_start": 1,
        "token_end": 1,
        "label": null
      },
      "color": "#96e8ce",
      "label": "compound"
    },
    {
      "head": 2,
      "child": 2,
      "head_span": {
        "start": 11,
        "end": 16,
        "token_start": 2,
        "token_end": 2,
        "label": null
      },
      "child_span": {
        "start": 11,
        "end": 16,
        "token_start": 2,
        "token_end": 2,
        "label": null
      },
      "color": "#c5bdf4",
      "label": "ROOT"
    }
  ],
  "hidden_relations": [],
  "_view_id": "relations",
  "spans": [],
  "answer": "accept",
  "_timestamp": 1679658122
}

Note the "label": "ROOT" in the final relation there.

Ah, I missed that. Thanks!

1 Like