Downloads · 30 days
37
13% of all-time downloads
3okasha/jais-finetuned-v1
jais-finetuned-v1 is a text generation model from 3okasha. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as mit.
Downloads · 30 days
37
13% of all-time downloads
All-time downloads
279
Public
Parameters
13B
26 GB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors26 GB · 100%
From the Hugging Face model README
Model Description:
This model is fine-tuned for paraphrasing Arabic sentences while preserving the original meaning of the sentence. It was trained using the Supervised Fine-Tuning (SFT) method on the Jais-13B model using the TRL library (SFTTrainer) and the PEFT/LoRA library.
# -*- coding: utf-8 -*-
!pip install --upgrade bitsandbytes
!pip install -q datasets
!pip install -q trl
!pip install git+https://github.com/huggingface/peft.git
!pip install -q -U accelerate
from huggingface_hub import login
login()
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
from peft import LoraConfig, get_peft_model, prepare_model_for_kbit_training, PeftModel, PeftConfig
from datasets import load_dataset
from transformers import TrainingArguments, pipeline
from trl import SFTTrainer
bnb_cfg = BitsAndBytesConfig(
load_in_8bit=True,
# bnb_4bit_quant_type="nf4",
# bnb_4bit_use_double_quant=True,
bnb_4bit_compute_dtype="bfloat16",
)
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_path = "3okasha/jais-finetuned-v1"
device = "cuda" if torch.cuda.is_available() else "cpu"
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(
model_path,
quantization_config=bnb_cfg,
device_map="auto",
trust_remote_code=True
)
def user_prompt(human_prompt):
prompt_template=f"input:\n{human_prompt}\n\nparaphrize:\n"
return prompt_template
model.config.use_cache = False
if hasattr(model, "generation_config"): model.generation_config.use_cache = False
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=50-input_len,
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= user_prompt("أعتقد يمكننا أن نبدأ")
print(get_response(text))
## أعتقد أنه يمكننا البدأ
## أعتقد أننا يمكن أن نبدأ