MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / get_text_embedding

Function get_text_embedding

utils/src/model_utils.py:143–166  ·  view source on GitHub ↗

Generate text embeddings for a list of text strings. Args: text (list[str]): A list of text strings. model: The model used for generating embeddings. batchsize (int): The batch size for processing text. Returns: list: A list of text embeddings.

(
    text: list[str], model: BGEM3FlagModel, batchsize: int = 32
)

Source from the content-addressed store, hash-verified

141
142
143def get_text_embedding(
144 text: list[str], model: BGEM3FlagModel, batchsize: int = 32
145) -> list[torch.Tensor]:
146 """
147 Generate text embeddings for a list of text strings.
148
149 Args:
150 text (list[str]): A list of text strings.
151 model: The model used for generating embeddings.
152 batchsize (int): The batch size for processing text.
153
154 Returns:
155 list: A list of text embeddings.
156 """
157 if isinstance(text, str):
158 return torch.tensor(model.encode(text)["dense_vecs"]).to(model.device)
159 result = []
160 for i in range(0, len(text), batchsize):
161 result.extend(
162 torch.tensor(model.encode(text[i : i + batchsize])["dense_vecs"]).to(
163 model.device
164 )
165 )
166 return result
167
168
169def get_image_embedding(

Callers 9

get_historyMethod · 0.90
__post_process__Method · 0.90
set_referenceMethod · 0.90
_valid_outlineMethod · 0.90
get_historyMethod · 0.90
__post_process__Method · 0.90
set_referenceMethod · 0.90
_valid_outlineMethod · 0.90
prs_dedupFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected