Skip to content

Commit

Permalink
Add dim property (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephantul authored Oct 6, 2024
1 parent 1edcc7e commit 070fed5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions model2vec/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ def __init__(
else:
self.normalize = self.config.get("normalize", False)

@property
def dim(self) -> int:
"""Get the dimension of the model."""
return self.embedding.weight.shape[1]

@property
def device(self) -> torch.device:
"""Get the device of the model."""
Expand Down
7 changes: 7 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,10 @@ def test_set_normalize(mock_vectors: np.ndarray, mock_tokenizer: Tokenizer) -> N
assert model.config == {"normalize": False}
model.normalize = True
assert model.config == {"normalize": True}


def test_dim(mock_vectors: np.ndarray, mock_tokenizer: Tokenizer, mock_config: dict[str, str]) -> None:
"""Tests the dimensionality of the model."""
model = StaticModel(mock_vectors, mock_tokenizer, mock_config)
assert model.dim == 2
assert model.dim == model.embedding.weight.shape[1]

0 comments on commit 070fed5

Please sign in to comment.