Rigveda Embedding Model (ONNX)

This is an ONNX-optimized version of the Ganaraj/rgveda-embedding-gemma model, specifically designed for efficient embedding generation of Sanskrit texts, particularly Rigveda verses.

Model Details

  • Base Model: Ganaraj/rgveda-embedding-gemma
  • Architecture: Gemma-based sentence transformer
  • Format: ONNX (Open Neural Network Exchange)
  • Embedding Dimension: 768
  • Language Support: Sanskrit (primary), English
  • License: Apache 2.0

Usage

Installation

pip install onnxruntime transformers numpy

Python Example

import numpy as np
import onnxruntime
from transformers import AutoTokenizer

class RigvedaONNXInference:
    def __init__(self, model_path):
        # Load tokenizer
        self.tokenizer = AutoTokenizer.from_pretrained(model_path)
        
        # Load ONNX model
        self.session = onnxruntime.InferenceSession(f"{model_path}/model.onnx")
    
    def encode_query(self, queries):
        """Encode queries with task prefix"""
        texts = [f"task: search result | query: {q}" for q in queries]
        return self._get_embeddings(texts)
    
    def encode_document(self, documents):
        """Encode documents with title prefix"""
        texts = [f"title: none | text: {d}" for d in documents]
        return self._get_embeddings(texts)
    
    def _get_embeddings(self, texts):
        inputs = self.tokenizer(texts, padding=True, truncation=True, return_tensors='np')
        onnx_inputs = {
            'input_ids': inputs['input_ids'],
            'attention_mask': inputs['attention_mask']
        }
        outputs = self.session.run(None, onnx_inputs)
        embeddings = outputs[0][:, 0]  # Use [CLS] token
        # Normalize embeddings
        return embeddings / np.linalg.norm(embeddings, axis=1, keepdims=True)

# Usage example
model = RigvedaONNXInference("./")

# Sanskrit query about divine phenomena similar to rain and lightning
query = "वृष्टि-विद्युत्-सदृशं दैविकं आगमनम्"

# Rigveda verses
documents = [
    'असामि हि प्रयज्यवः कण्वं दद प्रचेतसः\nअसामिभिर् मरुत आ न ऊतिभिर् गन्ता वृष्टिं न विद्युतः',
    'उत द्वार उशतीर् वि श्रयन्ताम् उत देवाṁ उशत आ वहेह',
    'प्राग्नये बृहते यज्ञियाय ऋतस्य वृष्णे असुराय मन्म\nघृतं न यज्ञ आस्ये सुपूतं गिरम् भरे वृषभाय प्रतीचीम्'
]

# Get embeddings
query_emb = model.encode_query([query])
doc_emb = model.encode_document(documents)

# Calculate similarity
similarities = np.dot(query_emb, doc_emb.T)
print("Similarities:", similarities)

Model Performance

This ONNX version maintains high fidelity to the original PyTorch model while offering:

  • Faster inference: Optimized for CPU and GPU inference
  • Smaller memory footprint: Efficient memory usage
  • Cross-platform compatibility: Works across different frameworks
  • Production ready: Suitable for deployment scenarios

Intended Use

This model is designed for:

  • Sanskrit text retrieval: Finding relevant Rigveda verses based on semantic queries
  • Comparative study: Analyzing similarities between Sanskrit texts
  • Digital humanities research: Supporting Sanskrit scholarship and research
  • Educational applications: Helping students and researchers explore Vedic literature

Training Data

The base model was trained on Sanskrit texts with a focus on Rigveda verses, enabling it to understand:

  • Classical Sanskrit vocabulary and grammar
  • Vedic terminology and concepts
  • Semantic relationships in ancient texts
  • Cross-lingual understanding (Sanskrit-English)

Limitations

  • Primary focus on Rigveda and classical Sanskrit texts
  • May not perform optimally on modern Sanskrit or non-Vedic texts
  • Limited understanding of highly specialized technical Sanskrit terms
  • Performance may vary with different Sanskrit transliteration schemes

Citation

If you use this model in your research, please cite:

@misc{rigveda-onnx-embedding,
  title={Rigveda Embedding Model (ONNX)},
  author={Converted from Ganaraj/rgveda-embedding-gemma},
  year={2024},
  howpublished={\url{https://huggingface.co/YOUR_USERNAME/rgveda-onnx-model}}
}

Technical Details

  • Conversion Tool: Hugging Face Optimum
  • ONNX Opset: 18
  • Precision: FP32
  • Input Format: Tokenized text with attention masks
  • Output: Normalized embeddings (768-dimensional)

Files Included

  • model.onnx: The ONNX model file
  • config.json: Model configuration
  • tokenizer.json: Fast tokenizer
  • tokenizer_config.json: Tokenizer configuration
  • special_tokens_map.json: Special token mappings

Contact

For questions about this ONNX conversion, please open an issue in the repository. For questions about the base model, please refer to the original Ganaraj/rgveda-embedding-gemma model page.

Downloads last month
13
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support