Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correct return type for encoding #1119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions FlagEmbedding/flag_models.py
Original file line number Diff line number Diff line change
@@ -237,7 +237,7 @@ def __init__(
def encode_queries(self, queries: Union[List[str], str],
batch_size: int = 256,
max_length: int = 512,
convert_to_numpy: bool = True) -> np.ndarray:
convert_to_numpy: bool = True) -> Union[np.ndarray, torch.Tensor]:
'''
This function will be used for retrieval task
if there is a instruction for queries, we will add it to the query text
@@ -252,7 +252,7 @@ def encode_corpus(self,
corpus: Union[List[str], str],
batch_size: int = 256,
max_length: int = 512,
convert_to_numpy: bool = True) -> np.ndarray:
convert_to_numpy: bool = True) -> Union[np.ndarray, torch.Tensor]:
'''
This function will be used for retrieval task
encode corpus for retrieval task
@@ -264,7 +264,7 @@ def encode(self,
sentences: Union[List[str], str],
batch_size: int = 256,
max_length: int = 512,
convert_to_numpy: bool = True) -> np.ndarray:
convert_to_numpy: bool = True) -> Union[np.ndarray, torch.Tensor]:
if self.num_gpus > 0:
batch_size = batch_size * self.num_gpus
self.model.eval()
@@ -341,7 +341,7 @@ def __init__(
def encode_queries(self, queries: Union[List[str], str],
batch_size: int = 256,
max_length: int = 512,
convert_to_numpy: bool = True) -> np.ndarray:
convert_to_numpy: bool = True) -> Union[np.ndarray, torch.Tensor]:
'''
This function will be used for retrieval task
if there is a instruction for queries, we will add it to the query text
@@ -350,7 +350,7 @@ def encode_queries(self, queries: Union[List[str], str],
if isinstance(queries, str):
input_texts = self.query_instruction_for_retrieval + queries
else:
input_texts = ['{}{}'.format(self.query_instruction_for_retrieval, q) for q in queries]
input_texts = [(self.query_instruction_for_retrieval + q) for q in queries]
else:
input_texts = queries
return self.encode(input_texts, batch_size=batch_size, max_length=max_length, convert_to_numpy=convert_to_numpy)
@@ -359,7 +359,7 @@ def encode_corpus(self,
corpus: Union[List[str], str],
batch_size: int = 256,
max_length: int = 512,
convert_to_numpy: bool = True) -> np.ndarray:
convert_to_numpy: bool = True) -> Union[np.ndarray, torch.Tensor]:
'''
This function will be used for retrieval task
encode corpus for retrieval task
@@ -371,7 +371,7 @@ def encode(self,
sentences: Union[List[str], str],
batch_size: int = 256,
max_length: int = 512,
convert_to_numpy: bool = True) -> np.ndarray:
convert_to_numpy: bool = True) -> Union[np.ndarray, torch.Tensor]:
if self.num_gpus > 0:
batch_size = batch_size * self.num_gpus
self.model.eval()
2 changes: 1 addition & 1 deletion Tutorials/1_Embedding/1.2.1_BGE_Series.ipynb
Original file line number Diff line number Diff line change
@@ -266,7 +266,7 @@
"```\n",
"LLMEmbedder.encode_keys(keys, batch_size=256, max_length=512, task='qa')\n",
"```\n",
"Similarly, *encode_keys()* also calls *_encode()* and automatically add instructions according to given task."
"Similarly, *encode_keys()* also calls *_encode()* and automatically add instructions according to the given task."
]
},
{