[GH-ISSUE #1507] Grammar and Logits questions #47328

Closed
opened 2026-04-28 03:35:45 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @verdverm on GitHub (Dec 13, 2023).
Original GitHub issue: https://github.com/ollama/ollama/issues/1507

Using a grammar to influence the logits of a model is becoming a useful technique

  • Is this possible with ollama? seems like it ought to be
  • Can we get an example? I'm interested to do so, but some guidance would be helpful, pun intended :] (https://github.com/guidance-ai/guidance)

I'm thinking there could be

  1. a base model that has the logits & grammar code, built in llama2 as an example, but seems most models ought to support this, codellama might be a better choice as one often wants to restrict what comes out with this model
  2. some examples that build on the base model showing how you can add the grammar and prompt
Originally created by @verdverm on GitHub (Dec 13, 2023). Original GitHub issue: https://github.com/ollama/ollama/issues/1507 Using a grammar to influence the logits of a model is becoming a useful technique - Is this possible with ollama? seems like it ought to be - Can we get an example? I'm interested to do so, but some guidance would be helpful, pun intended :] (https://github.com/guidance-ai/guidance) I'm thinking there could be 1. a base model that has the logits & grammar code, built in llama2 as an example, but seems most models ought to support this, codellama might be a better choice as one often wants to restrict what comes out with this model 2. some examples that build on the base model showing how you can add the grammar and prompt
Author
Owner

@DeluxeOwl commented on GitHub (Dec 13, 2023):

I'd like to add this ongoing discussion on hackernews: Bash one-liners for LLMs which talks about using llamafile.

A really nice thing that llamafile allows is passing a grammar as a cli option - link here, used for name generation, this makes it really powerful:

./llava-v1.5-7b-q4-main.llamafile \
    --image lemurs.jpg --temp 0 \
    --grammar 'root ::= [a-z]+ (" " [a-z]+)+' -n 16 \
    -p $'### User: The image has...\n### Assistant:' \
    --silent-prompt 2>/dev/null |
  sed -e's/ /_/g' -e's/$/.jpg/'
<!-- gh-comment-id:1854534843 --> @DeluxeOwl commented on GitHub (Dec 13, 2023): I'd like to add this ongoing discussion on hackernews: [Bash one-liners for LLMs](https://news.ycombinator.com/item?id=38629630) which talks about using `llamafile`. A really nice thing that llamafile allows is passing a grammar as a cli option - [link here, used for name generation](https://justine.lol/oneliners/#filename), this makes it really powerful: ```sh ./llava-v1.5-7b-q4-main.llamafile \ --image lemurs.jpg --temp 0 \ --grammar 'root ::= [a-z]+ (" " [a-z]+)+' -n 16 \ -p $'### User: The image has...\n### Assistant:' \ --silent-prompt 2>/dev/null | sed -e's/ /_/g' -e's/$/.jpg/' ```
Author
Owner

@verdverm commented on GitHub (Dec 13, 2023):

From the same HN discussion, there is a stale PR for ollama: https://github.com/jmorganca/ollama/pull/565

<!-- gh-comment-id:1854541345 --> @verdverm commented on GitHub (Dec 13, 2023): From the same HN discussion, there is a stale PR for ollama: https://github.com/jmorganca/ollama/pull/565
Author
Owner

@verdverm commented on GitHub (Dec 13, 2023):

More issue linking: https://github.com/jmorganca/ollama/issues/808

<!-- gh-comment-id:1854544198 --> @verdverm commented on GitHub (Dec 13, 2023): More issue linking: https://github.com/jmorganca/ollama/issues/808
Author
Owner

@clevcode commented on GitHub (Dec 19, 2023):

Updated PR: #1606

Based on #565, with the very tiny fixes that were needed to apply it to the current repo

<!-- gh-comment-id:1862857102 --> @clevcode commented on GitHub (Dec 19, 2023): Updated PR: #1606 Based on #565, with the very tiny fixes that were needed to apply it to the current repo
Author
Owner

@Kinglord commented on GitHub (Aug 7, 2024):

Hey all, I know there's an automated ping here but just to better align everyone please check out and comment on my new call to the Ollama team for clarity here. As always please be civil and stay on topic! 😄 - https://github.com/ollama/ollama/issues/6237

<!-- gh-comment-id:2273914489 --> @Kinglord commented on GitHub (Aug 7, 2024): Hey all, I know there's an automated ping here but just to better align everyone please check out and comment on my new call to the Ollama team for clarity here. As always please be civil and stay on topic! 😄 - https://github.com/ollama/ollama/issues/6237
Author
Owner

@ParthSareen commented on GitHub (Dec 5, 2024):

Hey! Not going to be supporting passing grammars but are supporting structured outputs by passing in JSON in #7900 - logits is also scoped in and will come early next year!

<!-- gh-comment-id:2518844201 --> @ParthSareen commented on GitHub (Dec 5, 2024): Hey! Not going to be supporting passing grammars but are supporting structured outputs by passing in JSON in #7900 - logits is also scoped in and will come early next year!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#47328