Sentence Similarity
sentence-transformers
Safetensors
English
ultrabert
feature-extraction
mteb
long-context
custom_code
Eval Results (legacy)
Instructions to use PhysShell/UltraBERT-Embed-150M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use PhysShell/UltraBERT-Embed-150M with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("PhysShell/UltraBERT-Embed-150M", trust_remote_code=True) sentences = [ "That is a happy person", "That is a happy dog", "That is a very happy person", "Today is a sunny day" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Notebooks
- Google Colab
- Kaggle
File size: 2,209 Bytes
be5c0e2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | from __future__ import annotations
from collections.abc import Iterable
from transformers.configuration_utils import PretrainedConfig
class UltrabertConfig(PretrainedConfig):
model_type = "ultrabert"
def __init__(
self,
vocab_size=32000,
hidden_size=4096,
intermediate_size=11008,
prediction_head_size=None,
num_hidden_layers=32,
num_attention_heads=32,
num_key_value_heads=None,
attention_windows=None,
hidden_act="silu",
initializer_range=0.02,
rms_norm_eps=1e-6,
pad_token_id=0,
bos_token_id=0,
eos_token_id=0,
tie_word_embeddings=False,
rope_theta=10000.0,
attention_bias=False,
attention_dropout=0.0,
mlp_bias=False,
head_dim=None,
classifier_dropout=0.0,
**kwargs,
):
super().__init__(
pad_token_id=pad_token_id,
bos_token_id=bos_token_id,
eos_token_id=eos_token_id,
tie_word_embeddings=tie_word_embeddings,
**kwargs,
)
self.vocab_size = vocab_size
self.hidden_size = hidden_size
self.intermediate_size = intermediate_size
self.prediction_head_size = prediction_head_size
self.num_hidden_layers = num_hidden_layers
self.num_attention_heads = num_attention_heads
self.num_key_value_heads = num_key_value_heads or num_attention_heads
self.attention_windows = (
attention_windows
if isinstance(attention_windows, Iterable)
else [attention_windows] * num_hidden_layers
)
self.hidden_act = hidden_act
self.initializer_range = initializer_range
self.rms_norm_eps = rms_norm_eps
self.rope_theta = (
rope_theta
if isinstance(rope_theta, Iterable)
else [rope_theta] * num_hidden_layers
)
self.attention_bias = attention_bias
self.attention_dropout = attention_dropout
self.mlp_bias = mlp_bias
self.head_dim = head_dim or self.hidden_size // self.num_attention_heads
self.classifier_dropout = classifier_dropout
|