HuggingFace镜像/vi-gemma-2b-RAG
模型介绍文件和版本分析
下载使用量0

开放思维

import argparse

import torch
from openmind import is_torch_npu_available
from openmind import AutoTokenizer, AutoModelForCausalLM


def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--model_name_or_path",
        type=str,
        help="Path to model",
        default=None,
    )

    args = parser.parse_args()
    return args


def main():
    args = parse_args()
    if args.model_name_or_path:
        model_path = args.model_name_or_path
    else:
        model_path = "../"

    if is_torch_npu_available():
        device = "npu:0"
    else:
        device = "cpu"

    tokenizer = AutoTokenizer.from_pretrained("Rose/vi-gemma-2b-RAG")
    model = AutoModelForCausalLM.from_pretrained("Rose/vi-gemma-2b-RAG").to(device)

    input_ids = tokenizer("Gra", return_tensors='pt').to(model.device)["input_ids"]
    output = model.generate(input_ids, max_new_tokens=48, do_sample=True, temperature=0.7)
    print(tokenizer.decode(output[0]))


if __name__ == "__main__":
    main()

模型卡片:vi-gemma-2b-RAG

(英文内容见下方)

越南语

模型描述:

vi-gemma-2b-RAG 是一个基于基础模型 google/gemma-1.1-2b-it 采用 LoRA 技术微调的大型语言模型。该模型在越南语文本数据集上进行训练,旨在提升越南语处理能力,并优化检索增强生成(Retrieval Augmented Generation - RAG)任务的性能。

使用目的:

vi-gemma-2b-RAG 模型适用于以下任务:

  • 基于越南语上下文的问答。
  • 越南语文本摘要。
  • 越南语机器翻译。
  • 其他越南语文本生成任务。

局限性:

尽管已针对越南语进行了微调,vi-gemma-2b-RAG 仍可能存在一些局限性:

  • 可能生成不准确或错误的信息。
  • 可能表现出偏见或不当观点。
  • 性能可能受到输入数据质量的影响。

使用方法:

以下是一些快速开始使用模型的代码片段。首先,请确保已安装 pip install -U transformers,然后复制与您用例相关的代码段。

我们建议默认使用 torch.bfloat16。

# 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>
'''

训练:

  • 基础模型: google/gemma-1.1-2b-it
  • 数据集: lamhieu/mabrycodes_dialogue_vi
  • 微调方法: LoRA、结合 Unsloth 的 PEFT

模型卡片:vi-gemma-2b-RAG

英文

模型描述:

vi-gemma-2b-RAG 是一个基于基础模型 google/gemma-1.1-2b-it 并使用 LoRA 技术进行微调的大型语言模型。该模型在越南语数据集上进行训练,旨在提升其越南语处理能力,并增强其在检索增强生成(RAG)任务中的表现。

预期用途:

vi-gemma-2b-RAG 模型适用于以下任务:

  • 越南语问答。
  • 越南语文本摘要。
  • 越南语机器翻译。
  • 以及其他越南语文本生成任务。

局限性:

尽管针对越南语进行了微调,vi-gemma-2b-RAG 仍可能存在一些局限性:

  • 可能会生成不正确或具有误导性的信息。
  • 可能会表现出偏见或不当观点。
  • 其性能可能会受到输入数据质量的影响。

使用方法:

使用说明

以下是一些帮助您快速开始运行模型的代码片段。首先请确保运行 pip install -U transformers 命令,然后根据您的使用场景复制相关部分的代码片段。

我们建议将 torch.bfloat16 作为默认数据类型。

# 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]))


训练信息:

  • 基础模型: google/gemma-1.1-2b-it
  • 数据集: lamhieu/mabrycodes_dialogue_vi
  • 微调方法: LoRA、PEFT 及 Unsloth

使用示例仓库: https://github.com/Martincrux/Vietnamese-RAG-system-building-with-vi-gemma-2b-RAG-and-halong_embedding

已上传模型

  • 开发者: hiieu、himmeow the coder、cuctrinh
  • 许可证: apache-2.0
  • 微调自模型: unsloth/gemma-1.1-2b-it-bnb-4bit

此 gemma 模型借助 Unsloth 和 Huggingface 的 TRL 库,训练速度提升了 2 倍。