In the realm of artificial intelligence, language models play a pivotal role in bridging communication barriers. Enter the Jais family of models—a series of powerful bilingual English-Arabic Large Language Models (LLMs) designed to excel in Arabic while maintaining strong capabilities in English. This guide will provide a user-friendly approach to understanding and using these models effectively.
Understanding the Jais Family Models
The Jais family consists of two primary variants:
- Models pre-trained from scratch (
jais-family-*) - Models pre-trained adaptively from Llama-2 (
jais-adapted-*)
Each model in the Jais family comes in various sizes, finely tuned for dialog generation in both Arabic and English. This extensive release includes 20 models, ranging from 590M to 70B parameters, trained with a whopping 1.6 trillion tokens across multiple data sources.
Getting Started with the Jais Models
To make use of the Jais family of models, follow these simple steps:
Step 1: Install Required Libraries
You will need the Transformers library from Hugging Face:
pip install transformers torch
Step 2: Sample Code Implementation
Below is a sample code snippet to get you started with using the Jais family models for generating text:
# -*- coding: utf-8 -*-
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_path = "inceptionai/jais-family-30b-16k"
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]
return response
text = "عاصمة دولة الإمارات العربية المتحدة ه"
print(get_response(text))
text = "The capital of UAE is"
print(get_response(text))
This code performs the following actions:
- Imports necessary libraries for model usage.
- Loads the tokenizer and model onto a device (GPU if available).
- Defines a function to generate a response based on the input text.
Explaining the Code Through an Analogy
Imagine you are a chef (the model) in a restaurant (the programming environment), and you have your ingredient pantry (the tokenizer) from which you get everything you need to create a dish (generate text). You start by pulling out the ingredients that correspond to your dish’s recipe (input text). Once you have everything, you begin cooking (process the inputs through the model) to serve the perfect meal (response) to your guests (users). The parameters like top_p and temperature act as your unique cooking techniques that influence the dish’s outcome.
Troubleshooting Common Issues
If you encounter issues while using the Jais family of models, here are a few troubleshooting tips:
- Model Loading Issues: Ensure that you have
trust_remote_code=Truewhile loading your model. - GPU Not Available: If you are running into problems using a GPU, try switching to CPU by changing the device variable.
- Token Length Limit Error: If the input text exceeds the max length defined in the model, reduce the input size and re-run.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Conclusion
The Jais family models are breaking new ground in Arabic NLP, serving both academic and commercial users. With a comprehensive set of tools and a user-friendly approach, these models empower developers and researchers alike to push boundaries in bilingual NLP tasks.
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.

