How to Get Started with Jais Family Models

Category :

The Jais family of models offers a pioneering set of bilingual English-Arabic large language models that are optimized for Arabic language processing while maintaining strong capabilities in English. If you’re eager to dive into the world of Jais, this guide will unravel the steps you need to follow for implementation, troubleshooting, and insights into the architecture.

Understanding the Jais Family

The Jais models come with various features:

  • Pre-trained from scratch models (jais-family-*).
  • Adaptive models based on Llama-2 (jais-adapted-*).

These models range from 590M to a whopping 70B parameters and have been trained on a colossal dataset consisting of 1.6 trillion tokens of Arabic, English, and code data.

Code Implementation

To utilize the Jais family effectively, you can implement it using the following sample code:

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

model_path = "inceptionai/jais-family-6p7b-chat"

prompt_eng = "### Instruction: Your name is 'Jais', and you are named after Jebel Jais, the highest mountain in UAE. You were made by 'Inception' in the UAE. You are a helpful, respectful, and honest assistant. Always answer as helpfully as possible, while being safe. Complete the conversation between [|Human|] and [|AI|]:\n### Input: [|Human|] {Question}\n[|AI|]\n### Response :"
prompt_ar = "### Instruction: اسمك \"جيس\" وسميت على اسم جبل جيس اعلى جبل في الامارات. تم بنائك بواسطة Inception في الإمارات. أنت مساعد مفيد ومحترم وصادق. أجب دائمًا بأكبر قدر ممكن من المساعدة، مع الحفاظ على البقاء أمناً. أكمل المحادثة بين [|Human|] و[|AI|] :\n### Input:[|Human|] {Question}\n[|AI|]\n### Response :"
device = "cuda" if torch.cuda.is_available() else "cpu"

tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(model_path, device_map="auto", trust_remote_code=True)

def get_response(text, tokenizer=tokenizer, model=model):
    input_ids = tokenizer(text, return_tensors="pt").input_ids
    inputs = input_ids.to(device)
    input_len = inputs.shape[-1]

    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, clean_up_tokenization_spaces=True
    )[0]
    response = response.split("### Response :")[-1]
    return response

# Example Queries
ques = "ما هي عاصمة الامارات؟"
text = prompt_ar.format_map({'Question': ques})
print(get_response(text))

ques = "What is the capital of UAE?"
text = prompt_eng.format_map({'Question': ques})
print(get_response(text))

This code initializes the model, defines the prompt structure in both Arabic and English, and provides a method to get responses based on user queries.

Explaining the Model: An Analogy

Think of the Jais family models as skilled bilingual chefs in a multicultural kitchen. Just like a chef who can whip up a seamless fusion of dishes from different cultures (Arabic and English, in this case), the Jais models are fine-tuned to cook up relevant and context-aware responses based on the rich ingredients they are trained on (1.6 trillion tokens of text). The pre-training and fine-tuning processes act as the chef’s practice, perfecting their skills to serve delicious dishes—responses that are engaging, informative, and culturally relevant.

Troubleshooting

While implementing the Jais family models, you may encounter some challenges. Here are a few troubleshooting tips:

  • No response or timeout: Check your internet connection and ensure the model path is correct.
  • Model not loading: Ensure that you have the necessary libraries installed and that the model path is accessible.
  • Incorrect output: Verify that your prompts are well-formed and consider retraining the model with more context if necessary.

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

Concluding Remarks

The Jais family models are a significant advancement in the field of Arabic natural language processing and provide excellent opportunities for research and commercial applications. While the language capabilities are extensive, it’s vital to remain aware of the models’ limitations and responsible usage.

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

Latest Insights

© 2024 All Rights Reserved

×