{
  "name": "Gemma 4 Text KIE",
  "description": "Keyed information extraction (KIE) from text, also known as key-value (pair) extraction: a keyed information extractor that applies a Gemma 4 language model, run with llama.cpp from a GGUF file, to input TextDocuments (e.g., OCR transcriptions of chyrons or slates) and writes, for each, the keyed information (a JSON dictionary of keys and values, such as a person's name and title) as a new TextDocument. The `keys` parameter lists the keys: the app appends them to the end of the system prompt, and builds from them a JSON schema that llama.cpp enforces during decoding, so every response is a dictionary with exactly those keys. Each input text is appended to the final user turn of `prompt` (the first one in `user-only` mode); the prompts describe what each key holds, and a multi-value `prompt` in `turn-taking` mode can carry few-shot examples. The default prompts are a general fallback that copies values from the text; a task with its own conventions (e.g., a \"Lastname, Firstname\" order for normalized names) needs a system prompt that describes them. Keyed information stored as JSON in a TextDocument is provisional, until it has its own annotation types (clamsproject/clams-vocabulary#13). A `model` runtime parameter selects the Gemma 4 size and quantization (default `ggml-org/gemma-4-E4B-it-GGUF:Q8_0`); see metadata.py for the GPU memory each needs. The app runs its own llama-server process and needs the `llama-server` executable (included in the container image).",
  "app_version": "v0.1",
  "mmif_version": "1.2.0",
  "analyzer_versions": {
    "ggml-org/gemma-4-E2B-it-GGUF:Q8_0": "6938c58",
    "ggml-org/gemma-4-E2B-it-GGUF:Q4_0": "6938c58",
    "ggml-org/gemma-4-E4B-it-GGUF:Q8_0": "a69f018",
    "ggml-org/gemma-4-E4B-it-GGUF:Q4_0": "a69f018",
    "ggml-org/gemma-4-12B-it-GGUF:Q8_0": "790d826",
    "ggml-org/gemma-4-12B-it-GGUF:Q4_0": "790d826"
  },
  "app_license": "Apache 2.0",
  "analyzer_license": "Apache 2.0",
  "identifier": "http://apps.clams.ai/gemma4-text-kie/v0.1",
  "url": "https://github.com/clamsproject/app-gemma4-text-kie",
  "input": [
    {
      "@type": "http://clams.ai/vocabulary/type/TextDocument/v2",
      "description": "Text to extract keyed information from. The app reads the TextDocuments of the last view that has any; without such a view, the top-level TextDocuments of the MMIF. Empty texts and \"no text\" markers (e.g., `NONE`, `N/A`, as an OCR step may answer for a frame without text) are skipped.",
      "required": true
    }
  ],
  "output": [
    {
      "@type": "http://clams.ai/vocabulary/type/TextDocument/v2",
      "description": "The keyed information extracted from one input TextDocument, as a JSON dictionary with the keys in `keys`, in that order. The `origins` property points to the input TextDocument, and `document` is copied from it when present.",
      "properties": {
        "origins": "*",
        "origination": "derived",
        "mime": "application/json"
      }
    }
  ],
  "parameters": [
    {
      "name": "keys",
      "description": "Keys of the output dictionary, in order. A key ending in `[]` holds a list of strings (e.g., `attributes[]`), any other key a string. Key names can contain any characters, including colons. The keys are used in two ways. (1) The app appends them to the end of `systemPrompt`, one line per key (e.g., `- attributes: a list of strings`), so a custom system prompt should end by introducing them, as the default does. (2) The app builds a JSON schema from them, and llama.cpp enforces it during decoding, so every response is a JSON object with exactly these keys, in this order. An unknown value is an empty string or list.",
      "type": "string",
      "multivalued": true
    },
    {
      "name": "prompt",
      "description": "User prompt(s) sent to the model. A single value runs as a one-shot generation. A multi-value list is interpreted as a multi-turn static prompt; see ``promptMode`` for how turns are assembled.",
      "type": "string",
      "default": "Text:",
      "multivalued": true
    },
    {
      "name": "systemPrompt",
      "description": "Optional system-role text prepended to the conversation. Empty by default.",
      "type": "string",
      "default": "Extract key-value pairs (keyed information) from the text in the user message. Take each value from the text. Copy it as written, unless the key name asks for another form (for example, a normalized name or date). Use an empty string, or an empty list, when the text has no value for a key. Do not add information that is not in the text. Answer with a JSON object that has exactly these keys, in this order:",
      "multivalued": false
    },
    {
      "name": "promptMode",
      "description": "How to interpret a multi-value ``prompt`` list. Has no effect when ``prompt`` has a single value. For semantics of each choice and worked examples, see https://clams.ai/clams-python/app-baseclasses.html#promptable-multiturn",
      "type": "string",
      "choices": [
        "user-only",
        "turn-taking"
      ],
      "default": "turn-taking",
      "multivalued": false
    },
    {
      "name": "maxNewTokens",
      "description": "Maximum number of new tokens generated per inference call. Forwarded to the backend's ``generate``-equivalent. Larger values grow the KV cache linearly and increase GPU memory usage; reduce if VRAM is constrained.",
      "type": "integer",
      "default": 512,
      "multivalued": false
    },
    {
      "name": "useReasoning",
      "description": "Request the model's reasoning (\"thinking\") mode. Off by default. Honored only by apps whose backing model has a distinct reasoning mode; apps without one ignore it. When honored and enabled, the reasoning trace is split from the answer and stored in the ``modelReasoningTrace`` property of the output ``TextDocument`` (kept out of the document text). Reasoning is markedly slower and far more token-hungry: the whole trace is generated before the answer and drawn from the same budget capped by ``maxNewTokens``, so raise ``maxNewTokens`` substantially (thousands of tokens, not hundreds) when enabling this, or the trace may consume the entire budget and the answer be truncated or empty. Small reasoning models (as a rule of thumb, roughly 4B parameters and under) are especially prone to non-terminating \"thinking loops\" that exhaust the budget without producing an answer; validate termination per model before relying on it.",
      "type": "boolean",
      "default": false,
      "multivalued": false
    },
    {
      "name": "temperature",
      "description": "Sampling temperature. The default ``0.0`` selects deterministic / greedy decoding for maximum reproducibility; override for sampled generation.",
      "type": "number",
      "default": 0,
      "multivalued": false
    },
    {
      "name": "topP",
      "description": "Nucleus-sampling cumulative probability cutoff. Only meaningful when ``temperature`` is greater than 0.",
      "type": "number",
      "default": 1,
      "multivalued": false
    },
    {
      "name": "topK",
      "description": "Top-K sampling cutoff. Only meaningful when ``temperature`` is greater than 0.",
      "type": "integer",
      "default": 50,
      "multivalued": false
    },
    {
      "name": "maxImagesPerPrompt",
      "description": "Maximum number of images the app bundles into a single prompt (one generation, one output TextDocument). ``0`` means no limit, so all images for a TimeFrame go into one prompt and yield one TextDocument. With a positive N, the app splits a TimeFrame whose frames exceed N into consecutive groups of at most N; each group produces its own TextDocument aligned to the same TimeFrame and grounded to its own source TimePoints via ``origins``. This bounds GPU memory for long dynamic scenes. The value is operator-set, so the number of output TextDocuments is deterministic and does not vary by GPU. Composes with the number of prompts the backend runs together (``parallelPrompts`` in apps that offer it).",
      "type": "integer",
      "default": 0,
      "multivalued": false
    },
    {
      "name": "imagesPerPromptMode",
      "description": "How the images of a TimeFrame that exceeds ``maxImagesPerPrompt`` are spread over its prompts. Has no effect when ``maxImagesPerPrompt`` is ``0``. Both choices produce the same number of prompts. \"max\" fills each prompt to the cap and puts the remainder in the last one (33 images at a cap of 32 give 32 and 1). \"balanced\" spreads the images evenly, so prompt sizes differ by at most one (33 images at a cap of 32 give 17 and 16).",
      "type": "string",
      "choices": [
        "max",
        "balanced"
      ],
      "default": "max",
      "multivalued": false
    },
    {
      "name": "model",
      "description": "Model to use for this request. Must be one of the model ids declared in this app's ``analyzer_versions``; the SDK pins the corresponding commit hash at load time. A model id is a Hugging Face repository, optionally followed by ``:<quantization>`` (e.g. ``org/repo-GGUF:Q8_0``). When the app ships a single model, this parameter defaults to it and can be omitted.",
      "type": "string",
      "choices": [
        "ggml-org/gemma-4-E2B-it-GGUF:Q8_0",
        "ggml-org/gemma-4-E2B-it-GGUF:Q4_0",
        "ggml-org/gemma-4-E4B-it-GGUF:Q8_0",
        "ggml-org/gemma-4-E4B-it-GGUF:Q4_0",
        "ggml-org/gemma-4-12B-it-GGUF:Q8_0",
        "ggml-org/gemma-4-12B-it-GGUF:Q4_0"
      ],
      "default": "ggml-org/gemma-4-E4B-it-GGUF:Q8_0",
      "multivalued": false
    },
    {
      "name": "pretty",
      "description": "The JSON body of the HTTP response will be re-formatted with 2-space indentation",
      "type": "boolean",
      "default": false,
      "multivalued": false
    },
    {
      "name": "runningTime",
      "description": "The running time of the app will be recorded in the view metadata",
      "type": "boolean",
      "default": true,
      "multivalued": false
    },
    {
      "name": "hwFetch",
      "description": "The hardware information (architecture, GPU and vRAM) will be recorded in the view metadata",
      "type": "boolean",
      "default": false,
      "multivalued": false
    },
    {
      "name": "tfSamplingMode",
      "description": "Sampling mode for TimeFrame annotations. Has no effect when the app does not process TimeFrames. \"representatives\" uses all representative timepoints if present, otherwise skips the TimeFrame. \"single\" uses the middle representative if present, otherwise extracts an image from the midpoint of the start/end interval (midpoint is calculated by floor division of the sum of start and end). \"all\" uses all target timepoints if present, otherwise extracts all images from the time interval.",
      "type": "string",
      "choices": [
        "representatives",
        "single",
        "all"
      ],
      "default": "representatives",
      "multivalued": false
    }
  ],
  "est_gpu_mem_min": 3500,
  "est_gpu_mem_typ": 9000
}