Build a static index. Args: inputs: a lit Dataset preds: a lit Dataset, parallel to inputs input_identifier_keys: (optional), list of keys to treat as identifiers for matching inputs. If None, will use all fields in inputs.spec()
(self,
inputs: lit_dataset.Dataset,
preds: lit_dataset.Dataset,
input_identifier_keys: Optional[list[str]] = None)
| 42 | return self._all_inputs |
| 43 | |
| 44 | def __init__(self, |
| 45 | inputs: lit_dataset.Dataset, |
| 46 | preds: lit_dataset.Dataset, |
| 47 | input_identifier_keys: Optional[list[str]] = None): |
| 48 | """Build a static index. |
| 49 | |
| 50 | Args: |
| 51 | inputs: a lit Dataset |
| 52 | preds: a lit Dataset, parallel to inputs |
| 53 | input_identifier_keys: (optional), list of keys to treat as identifiers |
| 54 | for matching inputs. If None, will use all fields in inputs.spec() |
| 55 | """ |
| 56 | self._all_inputs = inputs |
| 57 | self._input_spec = inputs.spec() |
| 58 | self._output_spec = preds.spec() |
| 59 | self._description = preds.description() |
| 60 | self.input_identifier_keys = input_identifier_keys or self._input_spec.keys( |
| 61 | ) |
| 62 | # Filter to only the identifier keys |
| 63 | self._input_spec = { |
| 64 | k: self._input_spec[k] for k in self.input_identifier_keys |
| 65 | } |
| 66 | |
| 67 | # Build the index for prediction lookups |
| 68 | self._index = { |
| 69 | self.key_fn(ex): pred |
| 70 | for ex, pred in zip(inputs.examples, preds.examples) |
| 71 | } |
| 72 | |
| 73 | def _predict_single(self, example: JsonDict): |
| 74 | key = self.key_fn(example) |
nothing calls this directly
no test coverage detected