Errors When Getting Citation
Understanding the issue
When executing a program that utilizes the granite_io
library to generate chat completions, users may encounter errors related to citations. Specifically, the errors "Cited text not found in corresponding document" and "Unexpected error in generated citation context span" may occur. In this article, we will delve into the possible causes of these errors and provide guidance on how to resolve them.
Possible causes of the errors
- Incorrect citation formatting: The citation format used in the document may not be compatible with the citation style required by the chat completion model. This can lead to errors when trying to add context spans to the citation.
- Missing or incomplete citations: If the citations in the document are missing or incomplete, the chat completion model may not be able to generate accurate citations, resulting in errors.
- Incompatible document and model: The document and the chat completion model may not be compatible, leading to errors when trying to generate citations.
Resolving the errors
1. Check the citation formatting
Ensure that the citation format used in the document is compatible with the citation style required by the chat completion model. You can check the documentation of the granite_io
library to see which citation styles are supported.
2. Verify the completeness of citations
Make sure that all citations in the document are complete and accurate. Check that the citations include the necessary information, such as the author's name, title, publication date, and page numbers.
3. Update the document and model compatibility
If the document and the chat completion model are not compatible, you may need to update the document to use a compatible citation style or update the model to support the citation style used in the document.
4. Use the citations
parameter
You can use the citations
parameter to specify the citation style and format. For example:
parameters = {
"documents": [{"text": doc}],
"controls": {
"hallucinations": True,
"citations": {
"style": "APA",
"format": "numeric"
}
}
}
This will specify the APA citation style and numeric format for the citations.
5. Use the context
parameter
You can use the context
parameter to specify the context in which the citation should be generated. For example:
parameters = {
"documents": [{"text": doc}],
"controls": {
"hallucinations": True,
"citations": True,
"context": "The study found that..."
}
}
This will specify the context in which the citation should be generated.
Example code
Here is an example of how to modify the code to resolve the errors:
from granite_io import make_backend
from granite_io import make_io_processor
from granite_io.types import ChatCompletionInputs
doc = """
Audrey Faith McGraw (born September 21, 1967) is an American singer
and record producer. She is one of the most successful country artists
of all time, having sold more than 40 million albums worldwide. Hill is
married to American singer Tim McGraw, with she has recorded several duets.
Hill's first two albums, Take Me as I Am (1993) and It Matters to Me (1995),
were major successes and placed a combined three number ones on Billboard's
country charts. Hill's debut album was Take Me as I Am (1993); sales were strong,
buoyed by the chart success of "Wild One". Hill became the first female country
singer in 30 years to hold Billboard's number one position for four consecutive
weeks when "Wild One" managed the feat in 1994. Her version of "Piece of My Heart",
also went to the top of the country charts in 1994. The album sold a total of
3 million copies. Other singles from the album include "Take Me as I Am". The recording
of Faith's second album was delayed by surgery to repair a ruptured blood vessel on
her vocal cords. It Matters to Me finally appeared in 1995 and was another
success, with the title track becoming her third number-one country single.
Several other top 10 singles followed, and more than 3 million copies of the
album were sold. The fifth single from the album, "I Can't Do That Anymore",
was written by country music artist Alan Jackson. Other singles from the album
include "You Can't Lose Me", "Someone Else's Dream", and "Let's Go to Vegas".
During this period, Hill appeared on the acclaimed PBS music program Austin City Limits.
In spring 1996, Hill began the Spontaneous Combustion Tour with country singer Tim McGraw.
At that time, Hill had recently become engaged to her former producer, Scott Hendricks,
and McGraw had recently broken an engagement. McGraw and Hill were quickly
attracted to each other and began an affair. After discovering that Hill was
pregnant with their first child, the couple married on October 6, 1996. The
couple have three daughters together: Gracie Katherine (born 1997), Maggie Elizabeth (born 1998)
and Audrey Caroline (born 2001). Since their marriage, Hill and McGraw have endeavored
never to be apart for more than three consecutive days. After the release of It Matters to Me,
Hill took a three-year break from recording to give herself a rest from four years of touring
and to begin a family with McGraw. During her break, she joined forces with her husband
for their first duet, "It's Your Love". The song stayed at number one for six weeks,
and won awards from both the Academy of Country Music and the Country Music Association.
Hill has remarked that sometimes when they perform the song together,
"it [doesn't] feel like anybody else was really watching."
"""
backend = make_backend(
"openai",
{
"model_name": "granite3.2:8b",
},
)
processor_name = "granite3.2:8b"
io_processor = make_io_processor(processor_name, backend=backend)
parameters = {
"documents": [{"text": doc}],
"controls": {
"hallucinations": True,
"citations": {
"style": "APA",
"format": "numeric"
},
"": "The study found that..."
}
}
messages = [{'role': 'user', 'content': 'Did Faith Hill take a break from recording after releasing her second album, It Matters to Me?', 'defsite': 'text.0'}]
inputs = {"messages": messages} | parameters
inputs = ChatCompletionInputs.model_validate(inputs)
result = io_processor.create_chat_completion(inputs)
print(result.model_dump())
Q: What are the possible causes of the errors "Cited text not found in corresponding document" and "Unexpected error in generated citation context span"?
A: The possible causes of these errors are:
- Incorrect citation formatting: The citation format used in the document may not be compatible with the citation style required by the chat completion model.
- Missing or incomplete citations: If the citations in the document are missing or incomplete, the chat completion model may not be able to generate accurate citations, resulting in errors.
- Incompatible document and model: The document and the chat completion model may not be compatible, leading to errors when trying to generate citations.
Q: How can I resolve the errors?
A: To resolve the errors, you can try the following:
- Check the citation formatting: Ensure that the citation format used in the document is compatible with the citation style required by the chat completion model.
- Verify the completeness of citations: Make sure that all citations in the document are complete and accurate.
- Update the document and model compatibility: If the document and the chat completion model are not compatible, you may need to update the document to use a compatible citation style or update the model to support the citation style used in the document.
- Use the
citations
parameter: You can use thecitations
parameter to specify the citation style and format. For example:
parameters = "documents"], "controls": "hallucinations" } }
This will specify the APA citation style and numeric format for the citations.
* **Use the `context` parameter**: You can use the `context` parameter to specify the context in which the citation should be generated. For example:
```python
parameters = {
"documents": [{"text": doc}],
"controls": {
"hallucinations": True,
"citations": True,
"context": "The study found that..."
}
}
This will specify the context in which the citation should be generated.
Q: What is the citations
parameter?
A: The citations
parameter is used to specify the citation style and format. It is a dictionary that contains the following keys:
- style: The citation style to use (e.g. APA, MLA, Chicago).
- format: The citation format to use (e.g. numeric, author-date).
Q: What is the context
parameter?
A: The context
parameter is used to specify the context in which the citation should be generated. It is a string that contains the context in which the citation should be generated.
Q: How do I use the citations
and context
parameters?
A: To use the citations
and context
parameters, you can add them to the controls
dictionary in the parameters
dictionary. For example:
parameters = {
"documents": [{"text": doc "controls": {
"hallucinations": True,
"citations": {
"style": "APA",
"format": "numeric"
},
"context": "The study found that..."
}
}
This will specify the APA citation style and numeric format for the citations, and the context in which the citation should be generated.
Q: What are the benefits of using the citations
and context
parameters?
A: The benefits of using the citations
and context
parameters are:
- Improved citation accuracy: By specifying the citation style and format, you can ensure that the citations are accurate and consistent.
- Improved context understanding: By specifying the context in which the citation should be generated, you can ensure that the citation is relevant and accurate.
Q: Are there any limitations to using the citations
and context
parameters?
A: Yes, there are limitations to using the citations
and context
parameters. For example:
- Limited support for certain citation styles: The
citations
parameter may not support certain citation styles, such as the Chicago Manual of Style. - Limited support for certain contexts: The
context
parameter may not support certain contexts, such as academic or technical writing.
Q: How can I troubleshoot issues with the citations
and context
parameters?
A: To troubleshoot issues with the citations
and context
parameters, you can try the following:
- Check the documentation: Check the documentation for the
citations
andcontext
parameters to ensure that you are using them correctly. - Check the error messages: Check the error messages to see if they provide any clues about the issue.
- Contact support: Contact support for further assistance.