# tinker_cookbook.preference.ComparisonRenderer

## _class_ [**tinker_cookbook.preference.ComparisonRenderer**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/preference/types.py#L95)()

Abstract renderer for converting Comparisons to model inputs for preference training.

Subclasses must implement `build_generation_prompt`, `to_model_input_weights`, and the `tokenizer` property.

### [**build_generation_prompt**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/preference/types.py#L102)( _comparison_)

Build a model input for generating a preference label.

**Parameters:**

- [**comparison**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/preference/types.py#L102) ( _[Comparison](https://tinker-docs.thinkingmachines.ai/cookbook/api-reference/preference/comparison/)_ ) – The comparison to render as a prompt.

**Returns:** _types. [ModelInput](https://tinker-docs.thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/preference/types.py#L102)_ – Token-level model input ready for sampling.

### [**to_model_input_weights**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/preference/types.py#L113)( _labeled_comparison_)

Convert a labeled comparison to model input and per-token loss weights.

**Parameters:**

- [**labeled_comparison**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/preference/types.py#L114) ( _[LabeledComparison](https://tinker-docs.thinking-machines-lab/tinker-cookbook/api-reference/preference/labeledcomparison/)_ ) – A comparison annotated with a preference label.

**Returns:** A tuple of (model_input, weights) for training.

### _property_ [**tokenizer**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/preference/types.py#L127)

The tokenizer associated with this renderer.

**Returns:** _Tokenizer_ – The tokenizer instance.

## Referenced by

- [tinker_cookbook.preference.ComparisonRendererFromChatRenderer](https://tinker-docs.thinking-machines.ai/cookbook/api-reference/preference/comparisonrendererfromchatrenderer/)
