Documentation
¶
Overview ¶
Package gemma asks inferd's vision model what only a model can answer: a second reading of a word Tesseract is unsure of, a description of a picture, and the values of a chart (ADR 0044).
The converter runs without it. Open reads inferd's admin socket and returns ErrUnavailable when no daemon is running, it is still loading, or its model sees no images; the caller then goes on as if it had never asked. Every answer passes a guard before it is used. A model's failures read as fluently as its successes, which is what the guards are for: a loop of repeated lines, a reply longer than its image could hold, a reply cut off by the token bound, or the wrong shape is refused, and the caller falls back.
Index ¶
Constants ¶
const ( ReadPrompt = "Transcribe the text in this image exactly as written. Output only the text." DescribePrompt = "Describe this image for someone who cannot see it, in one line of the form " + "`tag: description`, where tag is one lowercase word for what the image is (photo, diagram, " + "logo, screenshot, drawing, map) and description is one sentence of what it shows. " + "Output only that line." ChartPrompt = "This image is a chart. Write its data as a Markdown table: a header row naming " + "each column, a separator row, then one row per data point, with the values as the chart " + "shows them. Output only the table." )
Prompts, each with the shape of its answer stated, since a vision model left to choose writes Markdown, LaTeX and a preamble. ReadPrompt is the one the word-reading spike measured; Google's documented question, "What does the text in this image say?", was answered with a summary and matched 2 of 712 words (ADR 0043).
Variables ¶
var ErrRefused = ocr.ErrRefused
ErrRefused reports that an answer failed its guard. It is ocr.ErrRefused, so ocr.Confirm counts a refusal as a disagreement and any other error as the model failing.
ErrUnavailable reports that inferd has no ready model that sees images.
Functions ¶
func Clean ¶
Clean removes leaked control tokens and the space around the answer. A captioning reply the user ran through transformers ended in "<turn|>".
func Loops ¶
Loops reports a repetition loop, the failure a vision model ends in on dense input: a line said three times or more where there are four lines or more, or a run of one word eight times. The spike saw three lines repeated fifty times on one page.
func ParseTable ¶
ParseTable reads a GFM table from s: a header row, a separator row, then data rows.
Types ¶
type Description ¶
type Description struct{ Tag, Text string }
Description is a picture described: what kind of image it is, and what it shows.
func ParseDescription ¶
func ParseDescription(s string) (Description, error)
ParseDescription reads "tag: description" from s.
func (Description) String ¶
func (d Description) String() string
String is the Markdown form, "tag: description".
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is inferd's vision backend.
func Open ¶
Open finds inferd's vision backend from its admin socket. addr and admin are the generation and admin endpoints, empty for the platform defaults.
func (*Model) Chart ¶
Chart reads a chart's values as a table, header first. Its guard refuses a reply that is not a GFM table of at least one data row, with every row as wide as the header.
func (*Model) Describe ¶
Describe describes a picture. Its guard refuses any reply not of the form "tag: description".