meta-encoder-v1 / chat_template.jinja
Jinapeng's picture
Upload folder using huggingface_hub
d5de844 verified
Raw History Blame Contribute Delete
1.61 kB
{#-
MetaEncoder v1 embedding template: renders one input exactly as the encoder was trained on it.
messages: an optional {"role": "system"} message whose content is the task instruction, then one
{"role": "user"} message holding the input as {"type": "image"} parts followed by an optional
{"type": "text"} part. The embedding is the final hidden state of the closing <|eot|>.
The date line is fixed so an input embeds identically on any day.
-#}
{%- macro render_content(content) -%}
{%- if content is string -%}
{{- content -}}
{%- elif content is not none -%}
{%- for part in content -%}
{%- if part['type'] == 'image' -%}
{{- '<|patch|>' -}}
{%- elif part['type'] == 'text' -%}
{{- part['text'] -}}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endmacro -%}
{%- set ns = namespace(instruction='') -%}
{%- for message in messages -%}
{%- if message['role'] == 'system' -%}
{%- set ns.instruction = render_content(message['content']) -%}
{%- endif -%}
{%- endfor -%}
{{- bos_token -}}
{{- '<|start|>system<|message|>You are Meta AI, a friendly AI Assistant.\n\nKnowledge cutoff: 2025-10-26.\n\nCurrent date: 2026-01-01.\n\nRepresent the user\'s input.' -}}
{%- if ns.instruction -%}
{{- '\n\n' + ns.instruction -}}
{%- endif -%}
{{- '\n\n# Valid recipients: "user".<|eot|>' -}}
{%- for message in messages -%}
{%- if message['role'] == 'user' -%}
{{- '<|start|>user<|message|>' + render_content(message['content']) + '<|eot|>' -}}
{%- endif -%}
{%- endfor -%}