:py:mod:`src.wic`
=================

.. py:module:: src.wic


Submodules
----------
.. toctree::
   :titlesonly:
   :maxdepth: 1

   contextual_embedder/index.rst
   deepmistake/index.rst
   distance/index.rst
   model/index.rst


Package Contents
----------------

Classes
~~~~~~~

.. autoapisummary::

   src.wic.ContextualEmbedder
   src.wic.DeepMistake
   src.wic.WICModel




.. py:class:: ContextualEmbedder(**data: Any)


   Bases: :py:obj:`src.wic.model.WICModel`

   .. py:property:: device
      :type: torch.device


   .. py:property:: tokenizer
      :type: transformers.PreTrainedTokenizerBase


   .. py:property:: model
      :type: transformers.PreTrainedModel


   .. py:attribute:: truncation_tokens_before_target
      :type: float

      

   .. py:attribute:: similarity_metric
      :type: Callable[Ellipsis, float]

      

   .. py:attribute:: normalization
      :type: None | Callable[[torch.Tensor], torch.Tensor]

      

   .. py:attribute:: ckpt
      :type: str

      

   .. py:attribute:: layers
      :type: conlist(item_type=conint(ge=0), unique_items=True)

      

   .. py:attribute:: embedding_cache
      :type: EmbeddingCache | None

      

   .. py:attribute:: gpu
      :type: int | None

      

   .. py:attribute:: layer_aggregator
      :type: LayerAggregator

      

   .. py:attribute:: subword_aggregator
      :type: SubwordAggregator

      

   .. py:attribute:: encode_only
      :type: bool

      

   .. py:attribute:: _embeddings
      :type: dict[src.use.Use, torch.Tensor]

      

   .. py:attribute:: _device
      :type: torch.device

      

   .. py:attribute:: _tokenizer
      :type: transformers.PreTrainedTokenizerBase

      

   .. py:attribute:: _model
      :type: transformers.PreTrainedModel

      

   .. py:method:: __enter__()


   .. py:method:: __exit__(exc_type, exc_val, exc_tb)


   .. py:method:: as_df() -> pandas.DataFrame


   .. py:method:: truncation_indices(target_subword_indices: list[bool]) -> tuple[int, int]


   .. py:method:: predict(use_pairs: Iterable[tuple[src.use.Use, src.use.Use]]) -> list[float]


   .. py:method:: tokenize(use: src.use.Use) -> transformers.BatchEncoding


   .. py:method:: aggregate(tensor: torch.Tensor, layers: list[int]) -> torch.Tensor


   .. py:method:: encode_all(uses: list[src.use.Use], type: Type[T] = np.ndarray) -> list[T]


   .. py:method:: encode(use: src.use.Use, type: Type[T] = np.ndarray) -> T



.. py:class:: DeepMistake


   Bases: :py:obj:`src.wic.model.WICModel`

   .. py:property:: path
      :type: pathlib.Path


   .. py:property:: repo_dir
      :type: pathlib.Path


   .. py:property:: ckpt_dir
      :type: pathlib.Path


   .. py:attribute:: ckpt
      :type: Model

      

   .. py:attribute:: cache
      :type: Cache | None

      

   .. py:method:: __enter__() -> None


   .. py:method:: __exit__(exc_type, exc_val, exc_tb)


   .. py:method:: as_df() -> pandas.DataFrame


   .. py:method:: clone_repo() -> None


   .. py:method:: __unzip_ckpt(zipped: pathlib.Path) -> None


   .. py:method:: __download_ckpt() -> pathlib.Path


   .. py:method:: predict(use_pairs: list[tuple[src.use.Use, src.use.Use]]) -> list[float]



.. py:class:: WICModel(**data: Any)


   Bases: :py:obj:`pydantic.BaseModel`, :py:obj:`abc.ABC`

   Helper class that provides a standard way to create an ABC using
   inheritance.

   .. py:class:: Config


      .. py:attribute:: json_encoders

         


   .. py:attribute:: _cache
      :type: pandas.DataFrame

      

   .. py:attribute:: _cache_path
      :type: pathlib.Path

      

   .. py:attribute:: scaler
      :type: Any

      

   .. py:attribute:: predictions
      :type: dict[tuple[src.use.UseID, src.use.UseID], float]

      

   .. py:method:: as_df() -> pandas.DataFrame
      :abstractmethod:


   .. py:method:: predict(use_pairs: Iterable[tuple[src.use.Use, src.use.Use]], **kwargs) -> list[float]
      :abstractmethod:


   .. py:method:: predict_all(use_pairs: list[tuple[src.use.Use, src.use.Use]]) -> list[float]



