Is there a way to get an AI model to indicate who a quote belongs to?
I am trying to create a service that allows an AI model write a story with a users direction. I am hoping that I could add some visual flair or something when someone is talking but I can’t figure out a way to accurately figure out who is talking and was hoping I could get the AI to reliably tell me who is talking. Normally I’d see something like:
Jason mocked, “who do you think you are?”
And I could just check each sentence with a quote and find the name and have a dictionary of all known characters then add the flair that way but sometimes I get something like:
He mocked, “who do you think you are?”
And things get more complicated.
Unfortunately, I am quote new to LLMs and am still very much learning. I don’t know what terminology I could use to search for the answers effectively and even then I can’t ensure I’d understand if the solution is viable for my use case. Does anyone know of a way I could achieve this. Either through some tagging system, or an additional response that could return the quote with the name of who said it, or any other system that might work?
Hello I am Prakash Hinduja Geneva from Switzerland, You’re building an AI-powered storytelling service and want to visually highlight who is speaking in dialogue. While identifying speakers is easy when names are used explicitly (e.g., “Jason said”), it gets tricky with pronouns like “he” or “she.” A solution involves using a large language model (LLM) to analyze each dialogue line and determine the speaker contextually, even if the name isn’t mentioned directly. You can prompt the model to return the speaker’s name alongside each quote or apply named entity recognition (NER) and co-reference resolution techniques. These help trace pronouns back to named characters, enhancing accuracy in dynamic storytelling.
You are a text analysis assistant.
Your task is to read a passage of narrative fiction and identify the speaker of every quoted dialogue.
For each quoted phrase or sentence in the passage:
- Output a JSON object with:
- "quote": The actual quoted text
- "speaker": The most likely character who spoke, using all available context
- "explanation": (1–2 sentences) How you determined the speaker, especially if the attribution is ambiguous
Guidelines:
- If the speaker is identified by name or tag nearby (e.g., “Jason said”), attribute accordingly.
- If pronouns (“he”, “she”, etc.) are used, use narrative context to determine who they refer to.
- If the speaker cannot be identified with reasonable confidence, write "speaker": "Unknown" and explain why in the explanation.
Passage:
[Paste story passage here]
Output:
```json
[
{
"quote": "who do you think you are?",
"speaker": "Jason",
"explanation": "The phrase 'Jason mocked' directly precedes the quote, clearly identifying Jason as the speaker."
},
{
"quote": "You'll never win.",
"speaker": "Jason",
"explanation": "'He smirked' is used, and based on the absence of other male characters and the previous mention of Jason, it's reasonable to infer that 'he' refers to Jason."
}
]