Downloads · 30 days
16
6% of all-time downloads
alexpro100/MathBERT-GGUF
MathBERT-GGUF is a fill-mask model from alexpro100. Use it when you need the model to fill a missing word. It is set up for sentence-transformers.
This model was converted to GGUF format from tbs17/MathBERT using llama.cpp.
Downloads · 30 days
16
6% of all-time downloads
All-time downloads
286
Public
Repo size
774 MB
Likes
0
Public
Click a slice to open those files.
.gguf774 MB · 100%
From the Hugging Face model README
This model was converted to GGUF format from tbs17/MathBERT using llama.cpp.
For more information go to here.
import numpy as np
from sentence_transformers import SentenceTransformer
from sentence_transformers.util import cos_sim
import openai
# ./llama.cpp/build/bin/llama-server --models-dir MathBERT-GGUF/ --embeddings
openai_client = openai.OpenAI(
base_url="http://127.0.0.1:8080/v1",
api_key="sk-no-key-required",
)
# embedding get
def get_embedding(text: str, limit_tokens: int=2048, model="embedding") -> list[float]:
response = openai_client.embeddings.create(
input=text[:limit_tokens],
model=model,
)
return response.data[0].embedding
model = SentenceTransformer(
"tbs17/MathBERT",
)
text = """This is text for math. It contains some math formulas, such as $E=mc^2$ and $\\int_0^\\infty e^{-x} dx = 1$."""
embed1 = model.encode(text)
for quant in ["Q8_0", "F16", "F32"]:
embed2 = np.array(get_embedding(text, model=f"MathBERT-0.1B-{quant}"), dtype=np.float32)
print(f"Cosine Similarity with {quant}: {cos_sim(embed1, embed2).item()}")
Output:
Cosine Similarity with Q8_0: 0.9999127984046936
Cosine Similarity with F16: 0.9999980926513672
Cosine Similarity with F32: 0.9999997019767761
To get the GGUF file, you have to:
MathBERT/1_Pooling/config.json:{"word_embedding_dimension":768,"pooling_mode":"mean","pooling_mode_cls_token":false,"pooling_mode_mean_tokens":true,"pooling_mode_max_tokens":false,"pooling_mode_mean_sqrt_len_tokens":false}
[
{
"idx": 0,
"name": "0",
"path": "",
"type": "sentence_transformers.models.Transformer"
},
{
"idx": 1,
"name": "1",
"path": "1_Pooling",
"type": "sentence_transformers.models.Pooling"
}
]
./llama.cpp/convert_hf_to_gguf.py MathBERT --outtype q8_0 --outfile MathBERT-GGUF/MathBERT-0.1B-Q8_0.gguf
./llama.cpp/convert_hf_to_gguf.py MathBERT --outtype f16 --outfile MathBERT-GGUF/MathBERT-0.1B-F16.gguf
./llama.cpp/convert_hf_to_gguf.py MathBERT --outtype f32 --outfile MathBERT-GGUF/MathBERT-0.1B-F32.gguf