Skip to content

Commit

Permalink
fix: nomic tensor return (#1683)
Browse files Browse the repository at this point in the history
* fix nomic tensor return

* add typehint
  • Loading branch information
Samoed authored Jan 2, 2025
1 parent 8d3c917 commit f5e6401
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions mteb/models/nomic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from functools import partial
from typing import Any

import numpy as np
import torch
import torch.nn.functional as F
from sentence_transformers import SentenceTransformer
Expand Down Expand Up @@ -43,7 +44,7 @@ def encode( # type: ignore
prompt_type: PromptType | None = None,
batch_size: int = 32,
**kwargs: Any,
):
) -> np.ndarray:
input_type = self.get_prompt_name(self.model_prompts, task_name, prompt_type)

# default to search_document if input_type and prompt_name are not provided
Expand All @@ -60,8 +61,9 @@ def encode( # type: ignore
emb = torch.tensor(emb)
emb = F.layer_norm(emb, normalized_shape=(emb.shape[1],))
emb = F.normalize(emb, p=2, dim=1)
if kwargs.get("convert_to_tensor", False):
emb = emb.cpu().detach().numpy()

if isinstance(emb, torch.Tensor):
emb = emb.cpu().detach().float().numpy()

return emb

Expand Down

0 comments on commit f5e6401

Please sign in to comment.