angle_emb.utilsο
Attributesο
Functionsο
|
Calculate cosine similarity between two vectors. |
|
Set device automatically |
|
Find all linear layer names |
|
Pooling the model outputs. |
Module Contentsο
- angle_emb.utils.cosine_similarity(vec1: List[int], vec2: List[int])[source]ο
Calculate cosine similarity between two vectors.
- Parameters:
vec1 β a list of integers
vec2 β a list of integers
- Returns:
a float value between 0 and 1, indicating the similarity between the two vectors.
- angle_emb.utils.find_all_linear_names(model: transformers.PreTrainedModel, linear_type: object | None = None) List[str][source]ο
Find all linear layer names
- Parameters:
model β PreTrainedModel
linear_type β Optional[object] = None, linear type, such as nn.Linear and bnb.nn.Linear4bit.
- Returns:
List[str], linear layer names
- angle_emb.utils.get_pooling(outputs: torch.Tensor, inputs: Dict, pooling_strategy: str, padding_side: str) torch.Tensor[source]ο
Pooling the model outputs.
- Parameters:
outputs β torch.Tensor. Model outputs (without pooling)
inputs β Dict. Model inputs
pooling_strategy β str. Pooling strategy [cls, cls_avg, cls_max, last, avg, mean, max, all, int]
padding_side β str. Padding strategy of tokenizers (left or right). It can be obtained by tokenizer.padding_side.