Attempts to infer a Spec describing a Model's constructor parameters. The Model base class attempts to infer a Spec for the constructor using `lit_nlp.api.types.infer_spec_for_func()`. If successful, this function will return a `dict[str, LitType]`. If unsucessful (i.e., the infere
(cls)
| 103 | |
| 104 | @classmethod |
| 105 | def init_spec(cls) -> Optional[Spec]: |
| 106 | """Attempts to infer a Spec describing a Model's constructor parameters. |
| 107 | |
| 108 | The Model base class attempts to infer a Spec for the constructor using |
| 109 | `lit_nlp.api.types.infer_spec_for_func()`. |
| 110 | |
| 111 | If successful, this function will return a `dict[str, LitType]`. If |
| 112 | unsucessful (i.e., the inferencer raises a `TypeError` because it encounters |
| 113 | a parameter that it not supported by `infer_spec_for_func()`), this function |
| 114 | will return None, log a warning describing where and how the inferencing |
| 115 | failed, and LIT users **will not** be able to load new instances of this |
| 116 | model from the UI. |
| 117 | |
| 118 | Returns: |
| 119 | A Spec representation of the Model's constructor, or None if a Spec could |
| 120 | not be inferred. |
| 121 | """ |
| 122 | try: |
| 123 | spec = types.infer_spec_for_func(cls.__init__) |
| 124 | except TypeError as e: |
| 125 | spec = None |
| 126 | logging.warning( |
| 127 | "Unable to infer init spec for model '%s'. %s", cls.__name__, str(e) |
| 128 | ) |
| 129 | return spec |
| 130 | |
| 131 | def is_compatible_with_dataset(self, dataset: lit_dataset.Dataset) -> bool: |
| 132 | """Return true if this model is compatible with the dataset spec.""" |
no outgoing calls