Model Card: vi-gemma-2b-RAG

(English below)

TiαΊΏng Việt (Vietnamese)

Mô tả mô hình:

vi-gemma-2b-RAG lΓ  mα»™t mΓ΄ hΓ¬nh ngΓ΄n ngα»― lα»›n được tinh chỉnh tα»« mΓ΄ hΓ¬nh cΖ‘ sở google/gemma-1.1-2b-it sα»­ dα»₯ng kα»Ή thuαΊ­t LoRA. MΓ΄ hΓ¬nh được huαΊ₯n luyện trΓͺn tαΊ­p dα»― liệu tiαΊΏng Việt vα»›i mα»₯c tiΓͺu cαΊ£i thiện khαΊ£ nΔƒng xα»­ lΓ½ ngΓ΄n ngα»― tiαΊΏng Việt vΓ  nΓ’ng cao hiệu suαΊ₯t cho cΓ‘c tΓ‘c vα»₯ truy xuαΊ₯t thΓ΄ng tin mở (Retrieval Augmented Generation - RAG).

Mα»₯c Δ‘Γ­ch sα»­ dα»₯ng:

MΓ΄ hΓ¬nh vi-gemma-2b-RAG phΓΉ hợp cho cΓ‘c tΓ‘c vα»₯ sau:

  • TrαΊ£ lời cΓ’u hỏi dα»±a trΓͺn ngα»― cαΊ£nh tiαΊΏng Việt.
  • TΓ³m tαΊ―t vΔƒn bαΊ£n tiαΊΏng Việt.
  • Dα»‹ch mΓ‘y tiαΊΏng Việt.
  • VΓ  cΓ‘c tΓ‘c vα»₯ tαΊ‘o vΔƒn bαΊ£n tiαΊΏng Việt khΓ‘c.

Giα»›i hαΊ‘n:

MαΊ·c dΓΉ Δ‘Γ£ được tinh chỉnh cho tiαΊΏng Việt, vi-gemma-2b-RAG vαΊ«n cΓ³ thể gαΊ·p phαΊ£i mα»™t sα»‘ hαΊ‘n chαΊΏ:

  • CΓ³ thể tαΊ‘o ra thΓ΄ng tin sai lệch hoαΊ·c khΓ΄ng chΓ­nh xΓ‘c.
  • CΓ³ thể thể hiện thΓ nh kiαΊΏn ​​hoαΊ·c quan Δ‘iểm khΓ΄ng phΓΉ hợp.
  • Hiệu suαΊ₯t cΓ³ thể bα»‹ αΊ£nh hưởng bởi chαΊ₯t lượng của dα»― liệu Δ‘αΊ§u vΓ o.

CΓ‘ch sα»­ dα»₯ng:

DΖ°α»›i Δ‘Γ’y chΓΊng tΓ΄i chia sαΊ» mα»™t sα»‘ Δ‘oαΊ‘n mΓ£ về cΓ‘ch bαΊ―t Δ‘αΊ§u nhanh chΓ³ng để sα»­ dα»₯ng mΓ΄ hΓ¬nh. TrΖ°α»›c tiΓͺn, hΓ£y Δ‘αΊ£m bαΊ£o Δ‘Γ£ cΓ i Δ‘αΊ·t pip install -U transformers, sau Δ‘Γ³ sao chΓ©p Δ‘oαΊ‘n mΓ£ tα»« phαΊ§n cΓ³ liΓͺn quan Δ‘αΊΏn usecase của bαΊ‘n.

ChΓΊng tΓ΄i khuyαΊΏn nghα»‹ sα»­ dα»₯ng torch.bfloat16 lΓ m mαΊ·c Δ‘α»‹nh.

# pip install transformers torch accelerate
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

# Khởi tαΊ‘o tokenizer vΓ  model tα»« checkpoint Δ‘Γ£ lΖ°u
tokenizer = AutoTokenizer.from_pretrained("himmeow/vi-gemma-2b-RAG")
model = AutoModelForCausalLM.from_pretrained(
    "himmeow/vi-gemma-2b-RAG",
    device_map="auto",
    torch_dtype=torch.bfloat16
)

# Sα»­ dα»₯ng GPU nαΊΏu cΓ³
if torch.cuda.is_available():
    model.to("cuda")

# Định dαΊ‘ng prompt cho model
prompt = """
### Instruction and Input:
Dα»±a vΓ o ngα»― cαΊ£nh/tΓ i liệu sau:
{}
Hãy trả lời cÒu hỏi: {}

### Response:
{}
"""

# ChuαΊ©n bα»‹ dα»― liệu Δ‘αΊ§u vΓ o
input_data = """
Short Tandem Repeats (STRs) lΓ  cΓ‘c trΓ¬nh tα»± DNA lαΊ·p lαΊ‘i ngαΊ―n (2- 6 nucleotides) xuαΊ₯t hiện phα»• biαΊΏn trong hệ gen của con người. CΓ‘c trΓ¬nh tα»± nΓ y cΓ³ tΓ­nh Δ‘a hΓ¬nh rαΊ₯t cao trong tα»± nhiΓͺn, Δ‘iều nΓ y khiαΊΏn cΓ‘c STRs trở thΓ nh nhα»―ng markers di truyền rαΊ₯t quan trọng trong nghiΓͺn cα»©u bαΊ£n Δ‘α»“ gen người vΓ  chuαΊ©n Δ‘oΓ‘n bệnh lΓ½ di truyền cΕ©ng nhΖ° xΓ‘c Δ‘α»‹nh danh tΓ­nh trong lΔ©nh vα»±c phΓ‘p y.
CΓ‘c STRs trở nΓͺn phα»• biαΊΏn tαΊ‘i cΓ‘c phΓ²ng xΓ©t nghiệm phΓ‘p y bởi vΓ¬ việc nhΓ’n bαΊ£n vΓ  phΓ’n tΓ­ch STRs chỉ cαΊ§n lượng DNA rαΊ₯t thαΊ₯p ngay cαΊ£ khi ở dαΊ‘ng bα»‹ phΓ’n hủy việc Δ‘inh danh vαΊ«n cΓ³ thể được thα»±c hiện thΓ nh cΓ΄ng. HΖ‘n nα»―a việc phΓ‘t hiện vΓ  Δ‘Γ‘nh giΓ‘ sα»± nhiα»…m DNA mαΊ«u trong cΓ‘c mαΊ«u vαΊ­t cΓ³ thể được giαΊ£i quyαΊΏt nhanh vα»›i kαΊΏt quαΊ£ phΓ’n tΓ­ch STRs. Ở Hoa Kα»³ hiện nay, tα»« bα»™ 13 markers nay Δ‘Γ£ tΔƒng lΓͺn 20 markers chΓ­nh Δ‘ang được sα»­ dα»₯ng để tαΊ‘o ra mα»™t cΖ‘ sở dα»― liệu DNA trΓͺn toΓ n Δ‘αΊ₯t nΖ°α»›c được gọi lΓ  The FBI Combined DNA Index System (Expaned CODIS).
CODIS vΓ  cΓ‘c cΖ‘ sα»­ dα»― liệu DNA tΖ°Ζ‘ng tα»± Δ‘ang được sα»­ dα»₯ng thα»±c sα»± thΓ nh cΓ΄ng trong việc liΓͺn kαΊΏt cΓ‘c hα»“ sΖ‘ DNA tα»« cΓ‘c tα»™i phαΊ‘m vΓ  cΓ‘c bαΊ±ng chα»©ng hiện trường vα»₯ Γ‘n. KαΊΏt quαΊ£ Δ‘α»‹nh danh STRs cΕ©ng được sα»­ dα»₯ng để hα»— trợ hΓ ng trΔƒm nghΓ¬n trường hợp xΓ©t nghiệm huyαΊΏt thα»‘ng cha con mα»—i nΔƒm'
"""
query = "HΓ£y cho tΓ΄i biαΊΏt mα»™t sα»‘ tΓ­nh chαΊ₯t của STRs được dΓΉng để lΓ m gΓ¬?"

# Định dαΊ‘ng input text
input_text = prompt.format(input_data, query," ")

# MΓ£ hΓ³a input text thΓ nh input ids
input_ids = tokenizer(input_text, return_tensors="pt")

# Sα»­ dα»₯ng GPU cho input ids nαΊΏu cΓ³
if torch.cuda.is_available():
    input_ids = input_ids.to("cuda") 

# Tẑo văn bản bằng model
outputs = model.generate(
    **input_ids,
    max_new_tokens=500,
    no_repeat_ngram_size=5,  # NgΔƒn chαΊ·n lαΊ·p lαΊ‘i cΓ‘c cα»₯m tα»« 5 gram
    # do_sample=True,   # KΓ­ch hoαΊ‘t chαΊΏ Δ‘α»™ tαΊ‘o vΔƒn bαΊ£n dα»±a trΓͺn lαΊ₯y mαΊ«u. Trong chαΊΏ Δ‘α»™ nΓ y, model sαΊ½ chọn ngαΊ«u nhiΓͺn token tiαΊΏp theo dα»±a trΓͺn xΓ‘c suαΊ₯t được tΓ­nh tα»« phΓ’n phα»‘i xΓ‘c suαΊ₯t của cΓ‘c token.
    # temperature=0.7,  # GiαΊ£m temperature để kiểm soΓ‘t tΓ­nh ngαΊ«u nhiΓͺn
    # early_stopping=True,  # Dα»«ng tαΊ‘o vΔƒn bαΊ£n khi tΓ¬m thαΊ₯y kαΊΏt thΓΊc phΓΉ hợp
)
# GiαΊ£i mΓ£ vΓ  in kαΊΏt quαΊ£
print(tokenizer.decode(outputs[0]))

'''
<bos>
### Instruction and Input:
Dα»±a vΓ o ngα»― cαΊ£nh/tΓ i liệu sau:

Short Tandem Repeats (STRs) lΓ  cΓ‘c trΓ¬nh tα»± DNA lαΊ·p lαΊ‘i ngαΊ―n (2- 6 nucleotides) xuαΊ₯t hiện phα»• biαΊΏn trong hệ gen của con người. CΓ‘c trΓ¬nh tα»± nΓ y cΓ³ tΓ­nh Δ‘a hΓ¬nh rαΊ₯t cao trong tα»± nhiΓͺn, Δ‘iều nΓ y khiαΊΏn cΓ‘c STRs trở thΓ nh nhα»―ng markers di truyền rαΊ₯t quan trọng trong nghiΓͺn cα»©u bαΊ£n Δ‘α»“ gen người vΓ  chuαΊ©n Δ‘oΓ‘n bệnh lΓ½ di truyền cΕ©ng nhΖ° xΓ‘c Δ‘α»‹nh danh tΓ­nh trong lΔ©nh vα»±c phΓ‘p y.
CΓ‘c STRs trở nΓͺn phα»• biαΊΏn tαΊ‘i cΓ‘c phΓ²ng xΓ©t nghiệm phΓ‘p y bởi vΓ¬ việc nhΓ’n bαΊ£n vΓ  phΓ’n tΓ­ch STRs chỉ cαΊ§n lượng DNA rαΊ₯t thαΊ₯p ngay cαΊ£ khi ở dαΊ‘ng bα»‹ phΓ’n hủy việc Δ‘inh danh vαΊ«n cΓ³ thể được thα»±c hiện thΓ nh cΓ΄ng. HΖ‘n nα»―a việc phΓ‘t hiện vΓ  Δ‘Γ‘nh giΓ‘ sα»± nhiα»…m DNA mαΊ«u trong cΓ‘c mαΊ«u vαΊ­t cΓ³ thể được giαΊ£i quyαΊΏt nhanh vα»›i kαΊΏt quαΊ£ phΓ’n tΓ­ch STRs. Ở Hoa Kα»³ hiện nay, tα»« bα»™ 13 markers nay Δ‘Γ£ tΔƒng lΓͺn 20 markers chΓ­nh Δ‘ang được sα»­ dα»₯ng để tαΊ‘o ra mα»™t cΖ‘ sở dα»― liệu DNA trΓͺn toΓ n Δ‘αΊ₯t nΖ°α»›c được gọi lΓ  The FBI Combined DNA Index System (Expaned CODIS).
CODIS vΓ  cΓ‘c cΖ‘ sα»­ dα»― liệu DNA tΖ°Ζ‘ng tα»± Δ‘ang được sα»­ dα»₯ng thα»±c sα»± thΓ nh cΓ΄ng trong việc liΓͺn kαΊΏt cΓ‘c hα»“ sΖ‘ DNA tα»« cΓ‘c tα»™i phαΊ‘m vΓ  cΓ‘c bαΊ±ng chα»©ng hiện trường vα»₯ Γ‘n. KαΊΏt quαΊ£ Δ‘α»‹nh danh STRs cΕ©ng được sα»­ dα»₯ng để hα»— trợ hΓ ng trΔƒm nghΓ¬n trường hợp xΓ©t nghiệm huyαΊΏt thα»‘ng cha con mα»—i nΔƒm'

HΓ£y trαΊ£ lời cΓ’u hỏi: HΓ£y cho tΓ΄i biαΊΏt mα»™t sα»‘ tΓ­nh chαΊ₯t của STRs được dΓΉng để lΓ m gΓ¬?

### Response:
 
STRs được sα»­ dα»₯ng để xΓ‘c Δ‘α»‹nh danh tΓ­nh, chuαΊ©n Δ‘oΓ‘n bệnh lΓ½ vΓ  xΓ‘c Δ‘α»‹nh bệnh lΓ½ di truyền.
<eos>
'''

HuαΊ₯n luyện:

  • MΓ΄ hΓ¬nh cΖ‘ sở: google/gemma-1.1-2b-it
  • TαΊ­p dα»― liệu: lamhieu/mabrycodes_dialogue_vi
  • PhΖ°Ζ‘ng phΓ‘p tinh chỉnh: LoRA, PEFT vα»›i Unsloth

Model Card: vi-gemma-2b-RAG

English

Model Description:

vi-gemma-2b-RAG is a large language model fine-tuned from the base model google/gemma-1.1-2b-it using LoRA. The model is trained on a Vietnamese dataset to improve its Vietnamese language processing capabilities and enhance its performance for Retrieval Augmented Generation (RAG) tasks.

Intended Use:

The vi-gemma-2b-RAG model is suitable for tasks such as:

  • Vietnamese question answering.
  • Vietnamese text summarization.
  • Vietnamese machine translation.
  • And other Vietnamese text generation tasks.

Limitations:

While fine-tuned for Vietnamese, vi-gemma-2b-RAG may still have some limitations:

  • It may generate incorrect or misleading information.
  • It may exhibit biases or inappropriate opinions.
  • Its performance may be affected by the quality of the input data.

How to Use:

Usage

Below we share some code snippets on how to get quickly started with running the model. First make sure to pip install -U transformers, then copy the snippet from the section that is relevant for your usecase.

We recommend torch.bfloat16 as the default dtype.

# pip install transformers torch accelerate

from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

# Initialize the tokenizer and model from the saved checkpoint
tokenizer = AutoTokenizer.from_pretrained("himmeow/vi-gemma-2b-RAG")
model = AutoModelForCausalLM.from_pretrained(
    "himmeow/vi-gemma-2b-RAG",
    device_map="auto",
    torch_dtype=torch.bfloat16
)

# Use GPU if available
if torch.cuda.is_available():
    model.to("cuda")

# Define the prompt format for the model
prompt = """
### Instruction and Input:
Based on the following context/document:
{}
Please answer the question: {}

### Response:
{}
"""

# Prepare the input data
input_data = """
Short Tandem Repeats (STRs) are short (2-6 nucleotides) repeating DNA sequences that are widespread in the human genome. These sequences are highly polymorphic in nature, which makes STRs very important genetic markers in human gene mapping and diagnosis of hereditary diseases as well as identification in the field of forensics.
STRs have become popular in forensic laboratories because the replication and analysis of STRs requires very small amounts of DNA, even in decomposed form, identification can still be performed successfully. Furthermore, the detection and assessment of sample DNA contamination in specimens can be quickly resolved with STR analysis results. In the United States today, the set of 13 markers has now been increased to 20 main markers being used to create a nationwide DNA database called The FBI Combined DNA Index System (Expaned CODIS).
CODIS and similar DNA databases are being used very successfully in linking DNA records from criminals and crime scene evidence. STR identification results are also used to support hundreds of thousands of paternity test cases each year.'
"""
query = "Tell me what are some properties of STRs used for?"

# Format the input text
input_text = prompt.format(input_data, query," ")

# Encode the input text into input ids
input_ids = tokenizer(input_text, return_tensors="pt")

# Use GPU for input ids if available
if torch.cuda.is_available():
    input_ids = input_ids.to("cuda") 

# Generate text using the model
outputs = model.generate(
    **input_ids,
    max_new_tokens=500, # Limit the number of tokens generated
    no_repeat_ngram_size=5,  # Prevent repetition of 5-gram phrases
    # do_sample=True,
    # temperature=0.7,  # Adjust the randomness of the generated text
    # early_stopping=True,  # Stop generating text when a suitable ending is found
)
# Decode and print the results
print(tokenizer.decode(outputs[0]))


Training:

  • Base Model: google/gemma-1.1-2b-it
  • Dataset: lamhieu/mabrycodes_dialogue_vi
  • Fine-tuning Method: LoRA, PEFT and Unsloth

Using example repository: https://github.com/Martincrux/Vietnamese-RAG-system-building-with-vi-gemma-2b-RAG-and-halong_embedding

Uploaded model

This gemma model was trained 2x faster with Unsloth and Huggingface's TRL library.

Downloads last month
201
Safetensors
Model size
2.51B params
Tensor type
BF16
Β·
Inference Providers NEW
Input a message to start chatting with ricepaper/vi-gemma-2b-RAG.

Model tree for ricepaper/vi-gemma-2b-RAG

Finetuned
(51)
this model
Finetunes
7 models
Quantizations
3 models

Spaces using ricepaper/vi-gemma-2b-RAG 5

Collection including ricepaper/vi-gemma-2b-RAG