Replace weights of models in the pipeline with those provided in the params dictionary. Can be used as a contextmanager, in which case, models go back to their original weights after the block. params (dict): A dictionary of parameters keyed by model ID. EXAMPLE:
(self, params: Optional[dict])
| 1475 | |
| 1476 | @contextmanager |
| 1477 | def use_params(self, params: Optional[dict]): |
| 1478 | """Replace weights of models in the pipeline with those provided in the |
| 1479 | params dictionary. Can be used as a contextmanager, in which case, |
| 1480 | models go back to their original weights after the block. |
| 1481 | |
| 1482 | params (dict): A dictionary of parameters keyed by model ID. |
| 1483 | |
| 1484 | EXAMPLE: |
| 1485 | >>> with nlp.use_params(optimizer.averages): |
| 1486 | >>> nlp.to_disk("/tmp/checkpoint") |
| 1487 | |
| 1488 | DOCS: https://spacy.io/api/language#use_params |
| 1489 | """ |
| 1490 | if not params: |
| 1491 | yield |
| 1492 | else: |
| 1493 | contexts = [ |
| 1494 | pipe.use_params(params) # type: ignore[attr-defined] |
| 1495 | for name, pipe in self.pipeline |
| 1496 | if hasattr(pipe, "use_params") and hasattr(pipe, "model") |
| 1497 | ] |
| 1498 | # TODO: Having trouble with contextlib |
| 1499 | # Workaround: these aren't actually context managers atm. |
| 1500 | for context in contexts: |
| 1501 | try: |
| 1502 | next(context) |
| 1503 | except StopIteration: |
| 1504 | pass |
| 1505 | yield |
| 1506 | for context in contexts: |
| 1507 | try: |
| 1508 | next(context) |
| 1509 | except StopIteration: |
| 1510 | pass |
| 1511 | |
| 1512 | @overload |
| 1513 | def pipe( |
no outgoing calls
no test coverage detected