MCPcopy Create free account
hub / github.com/ScienciaLAB/document-qa / average_pool

Function average_pool

document_qa/deployment/_embeddings_app.py:64–67  ·  view source on GitHub ↗

Mean-pool token embeddings, ignoring padding positions.

(last_hidden_states: Tensor, attention_mask: Tensor)

Source from the content-addressed store, hash-verified

62
63
64def average_pool(last_hidden_states: Tensor, attention_mask: Tensor) -> Tensor:
65 """Mean-pool token embeddings, ignoring padding positions."""
66 last_hidden = last_hidden_states.masked_fill(~attention_mask[..., None].bool(), 0.0)
67 return last_hidden.sum(dim=1) / attention_mask.sum(dim=1)[..., None]
68
69
70def load_embedding_model(model_name: str, model_revision: str):

Callers 1

run_embedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected