Best strategy for named entity recognition

I am trying to perform named entity recognition of people mentioned in first-person biographies and output the results in JSON format. In the playground, I ask the model to:

“Perform named entity recognition on the text. Only extract the entities that are people. Give each person a unique id. Save any biographical information like name, place of birth, occupation, interests, and personality traits. Find the pair-wise relationships between these people. Structure the data as a network graph where the nodes are people, and the edges are their pairwise relationships, with the name of the relationship as the label property and the identified perceived feelings listed in an array in a “sentiments” property of the relation. Output the results in JSON format.”

This works, but it will often not complete the action, and the JSON is left unfinished if I hit the maximum context length limit.

I could perform the task in batches, cutting the text into chunks likely to leave the input and output within the context length limit. But how would that work?

Say that the biographical account mentions two people, both named Sarah. One is the speaker’s daughter, and the other is her mother, after whom her daughter is named. My experience with the da-vinci and the tuned ChatGPT model is that this is efficiently dealt with. It usually understands from the context when the speaker refers to Sarah, the daughter, and not Sarah, the great-grandmother. However, it needs the full context to do so.

Say that I have a biographical text that is separated into two chunks.

In the first chunk, a sentence may be, “My mother Sarah was born in 1943. I named my daughter after her.”

A partial resulting graph might be:

{
  nodes: [
    {
      id: 'speaker',
      type: 'person',
      name: 'Michael'
    },
    {
      id: 'sarah1',
      type: 'person',
      name: 'Sarah'
    },
    {
      id: 'sarah2',
      type: 'person',
      name: 'Sean'
    }
  ],
  edges: [
    {
      source: 'speaker',
      target: 'sarah2',
      type: 'relationship',
      relationship: 'Mother'
    },
    {
      source: 'sarah1',
      target: 'speaker',
      type: 'relationship',
      relationship: 'Mother'
    }
  ]
}

In the second chunk, we might have the following sentence:

“Sarah’s husband, John, and my mother don’t get along very well.”

Based only on this information, a graph would look like this:

{
  nodes: [
    {
      id: 'speaker',
      type: 'person',
      name: 'Michael'
    },
    {
      id: 'sarah',
      type: 'person',
      name: 'Sarah'
    },
    {
      id: 'mother',
      type: 'person',
      name: ''
    },
    {
      id: 'john',
      type: 'person',
      name: 'John'
    }
  ],
  edges: [
    {
      source: 'mother',
      target: 'speaker',
      type: 'relationship',
      relationship: 'Mother'
    },
    {
      source: 'sarah',
      target: 'john',
      type: 'relationship',
      relationship: 'Married'
    }
  ]
}

What is the best strategy to get the model to analyze chunk 2 and all subsequent chunks in such a way that it keeps the context learned from previous chunks and outputs data that can be added to a growing data structure?

How could I read chunk 2 and ask the model to add the resulting NER to a growing data structure?

Hi, it’s interesting. Have you implement few shot examples as in context learning?