Getting Started with QuantFactory’s Sarvam-2B

Aug 17, 2024 | Educational

Welcome to your beginner’s guide for utilizing the powerful Sarvam-2B model for text completion and supervised finetuning! This guide will help you understand how to effectively set up and use this quantized version of the sarvam-2b model, which is designed to work seamlessly with 10 Indic languages plus English. So let’s dive in!

What is Sarvam-2B?

Sarvam-2B is a small yet powerful language model pre-trained from scratch on a staggering 4 trillion tokens. With its unique training mix of equal parts English and Indic languages, it’s optimally configured for tasks involving multilingual considerations. Supported Indic languages include:

  • Bengali
  • Gujarati
  • Hindi
  • Kannada
  • Malayalam
  • Marathi
  • Oriya
  • Punjabi
  • Tamil
  • Telugu

How to Get Started

To kick off your journey with Sarvam-2B, you’ll need to set up your environment with the transformers library. Here’s how you can do it:

from transformers import pipeline

# Initialize the model pipeline 
pipe = pipeline(model="sarvamaisarvam-2b-v0.5", device=0)

# Use the pipeline for text generation
result = pipe("भारत के प्रथम प्रधानमंत्री", max_new_tokens=15, temperature=0.1, repetition_penalty=1.2)
print(result[0]["generated_text"])

Understanding the Code: The Bakery Analogy

Imagine you are at a bakery, and you want to create a special cake to celebrate an occasion. The Sarvam-2B model can be likened to this bakery:

  • Ingredients (Model and Tokens): In the bakery, the ingredients (4 trillion tokens) are essential for making the perfect cake (language model). Here, the diverse ingredients represent both English and Indic languages, ensuring that the cake (output) is rich and flavorful.
  • Baker (Pipeline): The baker is analogous to the pipeline you set up in the code. The baker uses the chosen recipe (model) to mix the ingredients, ensuring the final dish comes out as intended.
  • Outcome (Text Completion): The final cake (text completion) is what you get after all your efforts. By specifying the initial ingredients and conditions (parameters), you control how the cake tastes (what response you receive)!

Troubleshooting Tips

If you run into issues while using the Sarvam-2B model, here are some troubleshooting ideas:

  • Import Errors: Ensure that the transformers library is properly installed. You can install it using pip:
  • !pip install transformers
  • Runtime Errors: Make sure your device is correctly set (check if you have GPU support enabled if you’re running on a local machine).
  • Text Output Issues: Double-check the parameters you are using for the pipeline call. Sometimes, tweaking the temperature or max_new_tokens can yield better results.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

With this guide, you are now equipped to start experimenting with the Sarvam-2B model for exciting language processing tasks. Happy coding!

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox