Sentence Similarity
sentence-transformers
Safetensors
nandi_encoder
embeddings
feature-extraction
mteb
retrieval
multilingual
indic
long-context
frontiersmind
nandi
custom_code
Run this model with HF Jobs
Run FrontiersMind/EmbeddingNandi-450M on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/FrontiersMind/EmbeddingNandi-450M. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/FrontiersMind/EmbeddingNandi-450M on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use FrontiersMind/EmbeddingNandi-450M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use FrontiersMind/EmbeddingNandi-450M with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("FrontiersMind/EmbeddingNandi-450M", trust_remote_code=True) sentences = [ "task: sentence similarity | query: How do I return a damaged product?", "task: sentence similarity | query: खराब सामान वापस कैसे करें?", "task: sentence similarity | query: damaged product wapas kaise kare?", "task: sentence similarity | query: What is the weather like today?" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Notebooks
- Google Colab
- Kaggle
Sync tokenization_nandi_encoder.py with EmbeddingNandi-150M
#1
by sn3199 - opened
Files changed (2)
18 unmodified lines1920212223242512 unmodified lines3839404142434445464748495051525354555657585960616263646566676869708 unmodified lines7980818283848518 unmodified linesclass NandiEncoderConfig(PretrainedConfig):r"""Configuration for the Nandi encoder. The architecture is the Nandi decoder's (RMSNorm, SwiGLU, GQA, RoPE,factorized embeddings, layer sharing) with full bidirectional attention.```python>>> from sentence_transformers import SentenceTransformer12 unmodified linesdef __init__(self,vocab_size=131072,hidden_size=832,intermediate_size=2496,num_hidden_layers=16,num_attention_heads=16,num_key_value_heads=4,head_dim=None,hidden_act="silu",max_position_embeddings=2048,initializer_range=0.02,rms_norm_eps=1e-5,pad_token_id=3,bos_token_id=0,eos_token_id=0,mask_token_id=131062,tie_word_embeddings=True,rope_parameters=None,attention_bias=False,attention_dropout=0.0,mlp_bias=False,factorized_embedding=True,embedding_rank=196,layer_sharing=True,layer_sharing_repeats=2,classifier_pooling="mean",classifier_dropout=0.0,qk_norm=False,**kwargs,):self.vocab_size = vocab_size8 unmodified linesself.initializer_range = initializer_rangeself.rms_norm_eps = rms_norm_epsself.mask_token_id = mask_token_idself.rope_parameters = rope_parameters if rope_parameters is not None else {"rope_type": "default", "rope_theta": 100000.0}self.attention_bias = attention_biasself.attention_dropout = attention_dropoutself.mlp_bias = mlp_bias18 unmodified lines19202122232425262712 unmodified lines4041424344454647484950515253545556575859606162636465666768697071728 unmodified lines8182838485868718 unmodified linesclass NandiEncoderConfig(PretrainedConfig):r"""Configuration for the Nandi encoder. The architecture is the Nandi decoder's (RMSNorm, SwiGLU, GQA, RoPE,factorized embeddings, optional layer sharing) with full bidirectional attention. The defaults are theEmbeddingNandi-450M architecture (28 x 1024, 8 query / 2 KV heads, rank-512 factorized embeddings,QK-norm).```python>>> from sentence_transformers import SentenceTransformer12 unmodified linesdef __init__(self,vocab_size=100352,hidden_size=1024,intermediate_size=3712,num_hidden_layers=28,num_attention_heads=8,num_key_value_heads=2,head_dim=None,hidden_act="silu",max_position_embeddings=32768,initializer_range=0.02,rms_norm_eps=1e-6,pad_token_id=3,bos_token_id=0,eos_token_id=0,mask_token_id=4,tie_word_embeddings=False,rope_parameters=None,attention_bias=False,attention_dropout=0.0,mlp_bias=False,factorized_embedding=True,embedding_rank=512,layer_sharing=False,layer_sharing_repeats=1,classifier_pooling="mean",classifier_dropout=0.0,qk_norm=True,**kwargs,):self.vocab_size = vocab_size8 unmodified linesself.initializer_range = initializer_rangeself.rms_norm_eps = rms_norm_epsself.mask_token_id = mask_token_idself.rope_parameters = rope_parameters if rope_parameters is not None else {"rope_type": "default", "rope_theta": 1000000.0}self.attention_bias = attention_biasself.attention_dropout = attention_dropoutself.mlp_bias = mlp_bias
12 unmodified lines1314151617181924 unmodified lines4445464748491 unmodified line51525354555612 unmodified lines# limitations under the License."""Tokenizer of the Nandi encoder: the Nandi BPE tokenizer, with `<|endoftext|>` prepended to every input(`add_special_tokens=True`, the default) because every training document started with it. Unlike the decodertokenizer, no `<|im_start|>` and no extra space are added."""import re24 unmodified linesreturn xclass NandiEncoderTokenizer(TokenizersBackend):model_input_names = ["input_ids", "attention_mask"]model = BPE1 unmodified linedef _encode_plus(self, text, text_pair=None, *args, is_split_into_words=False, **kwargs):if not is_split_into_words:text, text_pair = _absorb_space_before_mask(text), _absorb_space_before_mask(text_pair)return super()._encode_plus(text, text_pair, *args, is_split_into_words=is_split_into_words, **kwargs)def __init__(12 unmodified lines131415161718192024 unmodified lines45464748495051525354555657585960611 unmodified line636465666768697012 unmodified lines# limitations under the License."""Tokenizer of the Nandi encoder: the Nandi BPE tokenizer, with `<|endoftext|>` prepended to every input(`add_special_tokens=True`, the default) because every training document started with it. Unlike the decodertokenizer, no `<|im_start|>` and no extra space are added. With `is_split_into_words=True` (NER) every word gets itsleading space, as in running text."""import re24 unmodified linesreturn xdef _space_split_words(x):"""`is_split_into_words=True`: give every word the leading space it has in running text ("Delhi" -> " Delhi"), asin our NER fine-tuning. Words that already start with whitespace are kept as they are. A `<|mask|>` word gets nospace (same rule as above). Works for one example (list of words) and for a batch (list of lists of words)."""if isinstance(x, (list, tuple)):if all(isinstance(w, str) for w in x):return [_SPACE_BEFORE_MASK.sub("", w if (not w or w[0].isspace()) else " " + w) for w in x]return type(x)(_space_split_words(i) for i in x)return xclass NandiEncoderTokenizer(TokenizersBackend):model_input_names = ["input_ids", "attention_mask"]model = BPE1 unmodified linedef _encode_plus(self, text, text_pair=None, *args, is_split_into_words=False, **kwargs):if not is_split_into_words:text, text_pair = _absorb_space_before_mask(text), _absorb_space_before_mask(text_pair)elif getattr(self, "add_prefix_space", None) is not False: # add_prefix_space=False turns the word spaces offtext, text_pair = _space_split_words(text), _space_split_words(text_pair)return super()._encode_plus(text, text_pair, *args, is_split_into_words=is_split_into_words, **kwargs)def __init__(
configuration_nandi_encoder.py+18-16
tokenization_nandi_encoder.py+15-1