How to Get Started with the Jais Family of Models

Aug 8, 2024 | Educational

Welcome to the world of bilingual large language models (LLMs) that bridge the gap between Arabic and English! The Jais family of models is designed to excel particularly in Arabic while supporting English, promising an array of applications for researchers and developers alike. This guide will walk you through the steps necessary to utilize these powerful models, troubleshoot common issues, and unleash their full potential.

Understanding the Jais Family of Models

The Jais family includes two main types of models:

  • Models pre-trained from scratch (jais-family-*)
  • Models pre-trained adaptively from Llama-2 (jais-adapted-*)
This release features 20 models across 8 sizes, ranging from 590M to 70B parameters, and they are all instruction fine-tuned for dialogue using a mix of Arabic and English instruction data.

How to Use the Models

Here’s a straightforward code sample to help you get started:

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

model_path = "inceptionai/jais-family-30b-8k"
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))

In this code, we utilize the Jais model to generate responses based on Arabic and English inputs. Think of the model as an intelligent bilingual librarian who, when asked a question in either language, will provide you with a well-thought-out answer using the wealth of books (data) it has read.

Training and Adaptation Techniques

The Jais models are trained on a staggering amount of diverse data, including text from websites, books, and code. The training data for these models encompasses up to 1.6 trillion tokens in both Arabic and English, which enables them to understand and generate human-like responses effectively.

Troubleshooting Common Issues

If you run into issues, consider the following common troubleshooting tips:

  • Ensure that your environment has PyTorch and the necessary libraries installed.
  • Check if your GPU is correctly recognized by the system; if `cuda` is not available, the model will default to CPU, which might be slower.
  • If the API fails to respond, try reducing the max_length parameter in the generate method.
  • To avoid unexpected bugs, ensure trust_remote_code=True is active while loading models.

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.

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

Tech News and Blog Highlights, Straight to Your Inbox