MCPcopy Create free account
hub / github.com/FlyingFeather/DEA-SQL / embed_by_transformers

Function embed_by_transformers

fewshot/embedding.py:16–25  ·  view source on GitHub ↗
(text: Union[List, str])

Source from the content-addressed store, hash-verified

14
15
16def embed_by_transformers(text: Union[List, str]):
17 model_name = "bert-base-uncased"
18 tokenizer = AutoTokenizer.from_pretrained(model_name)
19 model = AutoModel.from_pretrained(model_name)
20
21 inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=128)
22 output = model(**inputs)
23 embed = output.last_hidden_state.mean(dim=1).detach()
24
25 return embed.numpy()
26
27
28if __name__ == '__main__':

Callers 2

gen_embed_and_saveFunction · 0.90
embedding.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected