How to Get Started with the Jais Family Model

Aug 9, 2024 | Educational

Welcome to the world of bilingual large language models! The Jais family of models provides powerful tools for understanding and generating text in both Arabic and English, making it an essential asset for researchers, developers, and businesses targeting Arabic-speaking audiences. If you’re ready to dive in, this guide will walk you through how to get started with the Jais models, alongside some troubleshooting tips to ensure your experience is smooth and productive.

Introduction to Jais Models

The Jais family consists of large language models that excel particularly in Arabic while providing robust capabilities in English. With twenty different models across eight sizes, you’re bound to find one that fits your needs, whether you’re looking for lightweight options or powerful 70B parameter setups.

Key Features of Jais Models

  • Bilingual Support: Understand and generate text efficiently in both Arabic and English.
  • Diverse Sizes: Choose from model sizes ranging from 590M to 70B parameters.
  • Context Length: Some models support context lengths of up to 16k tokens, allowing for longer conversations and more complex prompts.
  • Pre-training Techniques: Models are either pre-trained from scratch or adaptively fine-tuned from Llama-2, leveraging large datasets to enhance performance.

Getting Started with Jais Models

Here’s a simple step-by-step guide to using the Jais models in your Python applications:

Step 1: Install the Required Libraries

First, ensure you have the necessary packages installed. You can install the `transformers` library using pip:

pip install transformers torch

Step 2: Load the Model

Here’s a snippet of code to get you started with a specific Jais model:


# -*- coding: utf-8 -*-
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

model_path = "inceptionai/jais-family-30b-8k-chat"
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(model_path, device_map="auto", trust_remote_code=True)

Step 3: Generate Responses

Now that you have loaded the model, you can generate text responses with the following function:


def get_response(text, tokenizer=tokenizer, model=model):
    input_ids = tokenizer(text, return_tensors="pt").input_ids
    inputs = input_ids.to(device)
    
    generate_ids = model.generate(
        inputs,
        top_p=0.9,
        temperature=0.3,
        max_length=2048,
        min_length=input_len + 4,
        repetition_penalty=1.2,
        do_sample=True,
    )
    
    response = tokenizer.batch_decode(generate_ids, skip_special_tokens=True)[0]
    return response

Test the Model

You can now test the model with sample inputs in both Arabic and English:


# Sample queries
ques_ar = "ما هي عاصمة الامارات؟"
text_ar = f"### Instruction: ...\n### Input: [|Human|] {ques_ar}\n[|AI|]\n### Response :"

ques_eng = "What is the capital of UAE?"
text_eng = f"### Instruction: ...\n### Input: [|Human|] {ques_eng}\n[|AI|]\n### Response :"

print(get_response(text_ar))
print(get_response(text_eng))

Understanding the Code: Let’s Use an Analogy

Think of using the Jais model like setting up a special kind of chef in a restaurant. This chef has a unique skill set of cooking in two languages – Arabic and English. The steps outlined above are akin to:

  • Step 1 – Installing Libraries: This is like acquiring all the necessary kitchen tools and ingredients.
  • Step 2 – Loading the Model: You’re bringing the chef into the kitchen and ensuring they have access to all the spices and cooking ware (the required models and settings).
  • Step 3 – Generating Responses: Now you’re telling the chef what dish (response) you want based on the customer’s order (your prompt), and they prepare it with their unique cooking style (model architecture).

Troubleshooting Tips

If you encounter issues while using the Jais family models, here’s what you can do:

  • Issue with Model Loading: Ensure your internet connection is stable and that the correct model path is specified.
  • Memory Errors: If you face memory-related problems, consider using a smaller model size to better fit within your system’s constraints.
  • Unexpected Outputs: If the model’s responses are not as expected, try tweaking the `top_p`, `temperature`, and other parameters to refine the generation process.
  • Documentation: Always refer back to the official documentation for up-to-date information and troubleshooting.

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

Conclusion

In summary, the Jais family of models opens the door to powerful multilingual capabilities, improving the landscape for Arabic Natural Language Processing. As you venture into this exciting field, we hope this guide helps you get acquainted with the models effectively.

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.

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

Tech News and Blog Highlights, Straight to Your Inbox