Using JSON-structured output seems to affect the model's output. #6707

Closed
opened 2025-11-12 13:42:43 -06:00 by GiteaMirror · 1 comment
Owner

Originally created by @luyi661 on GitHub (Apr 10, 2025).

What is the issue?

I am using deepseek-r1:32b for information extraction, and part of the code is as follows:

model_name = "deepseek-r1:32b"
prompt = "Read the following announcement and extract information\n" + announcement_content + "\nRead the above announcement and extract information. Return the following content in JSON format\n" + current_format + "\n"
response = generate(
    model=model_name,
    prompt=prompt,
    format='json',
    options={'temperature': 0}
)

The response is as follows
model='deepseek-r1:32b' created_at='2025-04-10T05:17:21.608087865Z' done=False done_reason=None total_duration=None load_duration=None prompt_eval_count=None prompt_eval_duration=None eval_count=None eval_duration=None response='{ "Stock Code": "000560", "Announcement Date": "2022-06-10", "Announcement Type": "Other Transaction Reports", "Borrowing Company Name": "Beijing 5i5j Real Estate Brokerage Co., Ltd." }\n \n \n\n \n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n' context=None
If I remove format='json', that is:

model_name = "deepseek-r1:32b"
prompt = "Read the following announcement and extract information\n" + announcement_content + "\nRead the above announcement and extract information. Return the following content in JSON format\n" + current_format + "\n"
response = generate(
    model=model_name,
    prompt=prompt,
    options={'temperature': 0}
)

The response is as follows:

model='deepseek-r1:32b' created_at='2025-04-10T05:27:23.663206073Z' done=True done_reason='stop' total_duration=17459820462 load_duration=4557198990 prompt_eval_count=2048 prompt_eval_duration=1022000000 eval_count=438 eval_duration=11877000000 response='<think>
Okay, I need to process the user's query now. They provided a piece of announcement content and requested to extract specific information from it and return it in JSON format. First, I need to carefully read the user's requirements to ensure I understand the meaning and source of each field.

The announcement provided by the user is about a guarantee contract announcement from 5i5j Holding Group Co., Ltd. My task is to extract four pieces of information: stock code, announcement date, announcement type, and borrowing company name, and organize them into JSON format.

First, the stock code. It is usually found at the beginning of the announcement, commonly in the position of the stock code. I quickly scanned the announcement content and found that it mentions "The Board of Directors of 5i5j Holding Group Co., Ltd. June 10, 2022" at the end. However, the stock code is not directly provided. It might be necessary to check if there is any missing part or if the user's announcement indeed lacks this information. If it cannot be found, it should be marked as not found.

Next is the announcement date. It clearly states "June 10, 2022" at the end of the announcement, so this field should be "2022-06-10".

Then comes the announcement type. The user provided three options: Board Resolution Announcement, Shareholders' Meeting Resolution Announcement, and Other Transaction Reports. Based on the content of the announcement, this is a contract announcement about the company providing a guarantee for its subsidiary, which falls under Other Transaction Reports.

Finally, the borrowing company name. The announcement mentions that "Beijing 5i5j Real Estate Brokerage Co., Ltd." is the guaranteed party, borrowing from Xiamen International Bank Beijing Branch. Therefore, the borrowing company name should be filled in as "Beijing 5i5j Real Estate Brokerage Co., Ltd."

Now, I will organize this information into JSON format and ensure that each field is accurate. If the stock code is indeed not present in the announcement, it should be marked as not found.

In summary, my thought process includes: identifying each required piece of information, determining their locations and contents, handling possible missing situations, and ultimately organizing them into the format requested by the user.
</think>

```json
{
  "Stock Code": "Not Found",
  "Announcement Date": "2022-06-10",
  "Announcement Type": "Other Transaction Reports",
  "Borrowing Company Name": "Beijing 5i5j Real Estate Brokerage Co., Ltd."
}
```'

I feel that using format='json' seems to affect the model's output. This is because when using format='json':
1.The stock code can be extracted, but it cannot be extracted without using it. I set 'temperature': 0 and conducted multiple tests, and I found that this is not a coincidence.For other arguments, there are also cases with types.The model's output becomes different.
2.It seems that the content of the output has been reduced, as the runtime with the argument format='json' is only one-third of that without the argument.
3.done=False.
What could be the reason for this?

Relevant log output


OS

Linux

GPU

Nvidia

CPU

Intel

Ollama version

0.5.13

Originally created by @luyi661 on GitHub (Apr 10, 2025). ### What is the issue? I am using deepseek-r1:32b for information extraction, and part of the code is as follows: ``` model_name = "deepseek-r1:32b" prompt = "Read the following announcement and extract information\n" + announcement_content + "\nRead the above announcement and extract information. Return the following content in JSON format\n" + current_format + "\n" response = generate( model=model_name, prompt=prompt, format='json', options={'temperature': 0} ) ``` The response is as follows `model='deepseek-r1:32b' created_at='2025-04-10T05:17:21.608087865Z' done=False done_reason=None total_duration=None load_duration=None prompt_eval_count=None prompt_eval_duration=None eval_count=None eval_duration=None response='{ "Stock Code": "000560", "Announcement Date": "2022-06-10", "Announcement Type": "Other Transaction Reports", "Borrowing Company Name": "Beijing 5i5j Real Estate Brokerage Co., Ltd." }\n \n \n\n \n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n' context=None` If I remove format='json', that is: ``` model_name = "deepseek-r1:32b" prompt = "Read the following announcement and extract information\n" + announcement_content + "\nRead the above announcement and extract information. Return the following content in JSON format\n" + current_format + "\n" response = generate( model=model_name, prompt=prompt, options={'temperature': 0} ) ``` The response is as follows: ``` model='deepseek-r1:32b' created_at='2025-04-10T05:27:23.663206073Z' done=True done_reason='stop' total_duration=17459820462 load_duration=4557198990 prompt_eval_count=2048 prompt_eval_duration=1022000000 eval_count=438 eval_duration=11877000000 response='<think> Okay, I need to process the user's query now. They provided a piece of announcement content and requested to extract specific information from it and return it in JSON format. First, I need to carefully read the user's requirements to ensure I understand the meaning and source of each field. The announcement provided by the user is about a guarantee contract announcement from 5i5j Holding Group Co., Ltd. My task is to extract four pieces of information: stock code, announcement date, announcement type, and borrowing company name, and organize them into JSON format. First, the stock code. It is usually found at the beginning of the announcement, commonly in the position of the stock code. I quickly scanned the announcement content and found that it mentions "The Board of Directors of 5i5j Holding Group Co., Ltd. June 10, 2022" at the end. However, the stock code is not directly provided. It might be necessary to check if there is any missing part or if the user's announcement indeed lacks this information. If it cannot be found, it should be marked as not found. Next is the announcement date. It clearly states "June 10, 2022" at the end of the announcement, so this field should be "2022-06-10". Then comes the announcement type. The user provided three options: Board Resolution Announcement, Shareholders' Meeting Resolution Announcement, and Other Transaction Reports. Based on the content of the announcement, this is a contract announcement about the company providing a guarantee for its subsidiary, which falls under Other Transaction Reports. Finally, the borrowing company name. The announcement mentions that "Beijing 5i5j Real Estate Brokerage Co., Ltd." is the guaranteed party, borrowing from Xiamen International Bank Beijing Branch. Therefore, the borrowing company name should be filled in as "Beijing 5i5j Real Estate Brokerage Co., Ltd." Now, I will organize this information into JSON format and ensure that each field is accurate. If the stock code is indeed not present in the announcement, it should be marked as not found. In summary, my thought process includes: identifying each required piece of information, determining their locations and contents, handling possible missing situations, and ultimately organizing them into the format requested by the user. </think> ```json { "Stock Code": "Not Found", "Announcement Date": "2022-06-10", "Announcement Type": "Other Transaction Reports", "Borrowing Company Name": "Beijing 5i5j Real Estate Brokerage Co., Ltd." } ```' ``` I feel that using format='json' seems to affect the model's output. This is because when using format='json': 1.The stock code can be extracted, but it cannot be extracted without using it. I set 'temperature': 0 and conducted multiple tests, and I found that this is not a coincidence.For other arguments, there are also cases with types.The model's output becomes different. 2.It seems that the content of the output has been reduced, as the runtime with the argument format='json' is only one-third of that without the argument. 3.done=False. What could be the reason for this? ### Relevant log output ```shell ``` ### OS Linux ### GPU Nvidia ### CPU Intel ### Ollama version 0.5.13
GiteaMirror added the bug label 2025-11-12 13:42:43 -06:00
Author
Owner

@luyi661 commented on GitHub (Apr 10, 2025):

This might be due to the GBNF syntax. It seems that GBNF syntax can improve the accuracy and speed of information extraction in some cases.But I'm not sure if done=False is normal.

@luyi661 commented on GitHub (Apr 10, 2025): This might be due to the GBNF syntax. It seems that GBNF syntax can improve the accuracy and speed of information extraction in some cases.But I'm not sure if done=False is normal.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama-ollama#6707