The Jais family of models are sophisticated bilingual large language models (LLMs) designed for Arabic and English. With a variety of sizes and configurations, these models cater to a wide range of applications from natural language processing (NLP) to business solutions. Let’s explore how to set up and utilize these models effectively.
Getting Started with Jais Models
To begin using the Jais models, you’ll need to set up your environment and implement the provided sample code. Follow these straightforward steps:
- Install Required Libraries: Make sure you have
torchandtransformersinstalled in your Python environment. - Choose a Model: Select a model from the Jais family that fits your needs based on size and capabilities.
- Copy the Sample Code: Utilize the following Python snippet to interact with the model.
# -*- coding: utf-8 -*-
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_path = "inceptionai/jais-family-13b-chat"
prompt_eng = "### Instruction: Your name is 'Jais', ... ."
prompt_ar = "### Instruction: اسمك \"جيس\" وسميت على اسم جبل جيس ... ."
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
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))
Understanding the Code
Imagine you’re a chef preparing a recipe. The ingredients you choose and how you mix them can lead to a delicious meal or a culinary disaster. Similarly, when using the Jais models, this code serves as a recipe for generating responses based on user prompts. Below is a breakdown of its key components:
- Model Selection: The line
model_path = "inceptionai/jais-family-13b-chat"is akin to selecting the type of dish you want to prepare. Here, you’re designating which Jais model you want to utilize. - Input & Output: The prompts for both Arabic and English are defined, which serve as the ingredients. Inputting a question triggers the model to ‘cook up’ a response based on instructions.
- Model Generation: The function
get_responseoperates like your oven, taking inputs, applying the model, and producing outputs in the form of responses from the model. It’s an essential tool for executing your recipe.
Troubleshooting Tips
If you encounter issues while using the Jais models, here are some troubleshooting hints:
- Ensure Dependencies: Double-check that
torchandtransformersare correctly installed and up to date. - Device Compatibility: Make sure your device supports CUDA if you aim to leverage GPU acceleration. If not, the model will fall back to CPU, which may affect performance.
- Adjust Input Length: If you’re getting errors regarding input sequences being too long, consider modifying the
max_lengthparameter in thegeneratefunction to fit your needs. - Response Format: Review the prompt structure; an incorrect format might yield undesirable responses.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Conclusion
Utilizing the Jais family of models opens doors to numerous applications in both academic and commercial realms, especially for Arabic-speaking communities. By following the above steps and understanding the intricacies of the provided code, you’ll be well-equipped to maximize the models’ potential.
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.

