bridge.data.datasets.preference_tokenization#
Module Contents#
Functions#
Tokenize one conversation into |
|
End (exclusive) of a final-turn EOS followed by nothing but whitespace, or None if there is none. |
|
HF |
|
Build the chosen/rejected conversations for one row, or return a drop reason. |
API#
- bridge.data.datasets.preference_tokenization.tokenize_conversation(
- tokenizer,
- messages: list[dict],
- max_seq_length: int,
- tools: Sequence[Mapping[str, Any]] | None = None,
- all_assistant_turns: bool = False,
- chat_template_kwargs: Mapping[str, Any] | None = None,
Tokenize one conversation into
(input_ids, loss_mask), or return a drop reason.Scores the final assistant turn (header included) through its EOS;
all_assistant_turnsalso scores every earlier assistant turn.toolsare rendered into the prompt, never scored.chat_template_kwargsreach the template (e.g.truncate_history_thinking=Falsekeeps the reasoning of assistant turns before the last user turn, which Nemotron 3 / Qwen3 drop by default).
- bridge.data.datasets.preference_tokenization._rendered_eos_end(
- tokenizer,
- input_ids: list[int],
- context_len: int,
- eos_token_id: int,
End (exclusive) of a final-turn EOS followed by nothing but whitespace, or None if there is none.
- bridge.data.datasets.preference_tokenization._as_messages(
- value: str | Sequence[Mapping[str, Any]],
- role: str,
- bridge.data.datasets.preference_tokenization._decode_tool_calls(
- message: Mapping[str, Any],
HF
datasetsstorestool_callsas a JSON string when message schemas differ; the template needs the list.
- bridge.data.datasets.preference_tokenization._decode_arguments(
- call: Mapping[str, Any],
- bridge.data.datasets.preference_tokenization.build_pair_conversations(
- row: Mapping[str, Any],
- *,
- chosen_key: str = 'chosen',
- rejected_key: str = 'rejected',
- prompt_key: str | None = None,
Build the chosen/rejected conversations for one row, or return a drop reason.
Full trajectories (no
prompt_key) must first differ at an assistant turn; the rest is shared context.