Cache projections from ProjectorModel dimensionality reducers.
(self, inputs: Iterable[JsonDict])
| 250 | ## |
| 251 | # For internal use |
| 252 | def fit_transform(self, inputs: Iterable[JsonDict]): |
| 253 | """Cache projections from ProjectorModel dimensionality reducers.""" |
| 254 | wrapped = self.wrapped |
| 255 | if not isinstance(wrapped, lit_model.ProjectorModel): |
| 256 | raise TypeError( |
| 257 | "Attempted to call fit_transform() on a non-ProjectorModel." |
| 258 | ) |
| 259 | |
| 260 | inputs_as_list = list(inputs) |
| 261 | cache_keys = [self.key_fn(d) for d in inputs_as_list] |
| 262 | if (none_keys := [k for k in cache_keys if k is None]): |
| 263 | logging.warning( |
| 264 | "Attmepting to cache %d (of %d) where the cache key is None " |
| 265 | "- this can be from a missing or empty example id. These" |
| 266 | " will be recomputed on subsequent attempts.", |
| 267 | len(none_keys), |
| 268 | len(cache_keys), |
| 269 | ) |
| 270 | outputs = list(wrapped.fit_transform(inputs_as_list)) |
| 271 | with self._cache.lock: |
| 272 | for cache_key, output in zip(cache_keys, outputs): |
| 273 | self._cache.put(output, cache_key) |
| 274 | return outputs |
| 275 | |
| 276 | def predict(self, |
| 277 | inputs: Iterable[JsonDict], |