You need to agree to share your contact information to access this model

This repository is publicly accessible, but you have to accept the conditions to access its files and content.

Log in or Sign Up to review the conditions and access this model content.

Mô hình iVote3P - Tiếng Việt

iVote3P

==============================================================
    _ _     __      _        _____
   (_) |   / /___  | |_ ___ |___ /
   | | |  / /  _ \ | __/ _ \  |_    | | | / /  (_) || |_  __/ ___) |
   |_|_|/_/ \___/  \__\___| |____/   ver:1.0 18/8/2026
==============================================================

Đây là một mô hình ngôn ngữ iVote3P phiên bản 1.0

Chi tiết Mô hình

Mô hình iVote3P được phát triển dựa trên kiến trúc iVoteModel tùy chỉnh. Các tham số chính của mô hình được cấu hình như sau (chi tiết đầy đủ có trong config.json):

  • Kiến trúc: iVoteModel (GPT-like, custom)
  • Kích thước Từ vựng (Vocab Size): 50368
  • Độ dài Ngữ cảnh (Context Length): 2048
  • Số lớp (Number of Layers): 18
  • Kích thước Nhúng (Embedding Dimension): 640
  • Kích thước Hidden (Hidden Dimension): 2048
  • Số đầu Attention (Number of Heads): 10
  • Kích thước Head (Head Dimension): 64
  • Số nhóm KV (KV Groups): 2
  • Chuẩn hóa QK (QK Norm): True (Mode: 2)
  • Định dạng Trọng số: safetensors

Cách sử dụng

Để sử dụng mô hình này, bạn cần tải toàn bộ file từ repo về, chúng tôi có sẵn ipynb để bạn sử dụng.

Cài đặt và Tải Toàn Bộ File

  1. Cài đặt thư viện:

    pip install torch safetensors huggingface_hub tokenizers
    
  2. Tải toàn bộ repo về máy: Bạn có thể dùng huggingface_hub để tải toàn bộ thư mục mô hình về máy (ví dụ tải vào thư mục ./ivote3p_model):

    from huggingface_hub import snapshot_download
    model_dir = snapshot_download(repo_id="shumi2011/ivote3p", local_dir="./ivote3p_model")
    print(f"Đã tải toàn bộ file mô hình về: {model_dir}")
    
  3. Đảm bảo codebase iVote3P có sẵn: Sao chép thư mục ivote3p/ từ dự án iVote3P gốc vào thư mục làm việc của bạn hoặc thêm đường dẫn đến nó vào sys.path.

Tải mô hình và Inference (Tạo văn bản)

Sau khi đã tải repo về máy, bạn có thể khởi tạo mô hình và inference như sau:

import sys
import json
from pathlib import Path
import torch
import safetensors.torch
from tokenizers import Tokenizer

# Khai báo đường dẫn đến thư mục vừa tải
MODEL_DIR = Path("./ivote3p_model")

# Đảm bảo hàm generate_text và iVoteModel được import từ codebase gốc
# sys.path.append("/path/to/your/iVote3P_project")
from ivote3p.parity_model import iVoteModel, generate_text

# --- Bước 1: Tải Tokenizer ---
tokenizer = Tokenizer.from_file(str(MODEL_DIR / "tokenizer.json"))

# --- Bước 2: Tải cấu hình mô hình (config.json) ---
with open(MODEL_DIR / "config.json", 'r', encoding='utf-8') as f:
    model_cfg_params = json.load(f)

# --- Bước 3: Khởi tạo mô hình tùy chỉnh `iVoteModel` ---
model_cfg_for_init = {k: v for k, v in model_cfg_params.items() if k not in ['_name_or_path', 'architectures', 'torch_dtype', 'transformers_version', 'model_type']}
if isinstance(model_cfg_for_init.get('dtype'), str):
    model_cfg_for_init['dtype'] = getattr(torch, model_cfg_for_init['dtype'].rsplit('.', 1)[-1])
model = iVoteModel(model_cfg_for_init)

# --- Bước 4: Tải trọng số mô hình (model.safetensors) ---
state_dict = safetensors.torch.load_file(MODEL_DIR / "model.safetensors", device="cpu")
model.load_state_dict(state_dict, strict=False)

# Chuyển mô hình sang chế độ đánh giá và đẩy lên thiết bị (GPU nếu có)
model.eval()
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
print("Mô hình và tokenizer đã được tải và sẵn sàng sử dụng.")

# --- Bước 5: Chạy Inference ---
prompt = "[BOS]Xin chào, đây là một câu chuyện về"
with torch.no_grad():
    generated_text_custom = generate_text(model, tokenizer, prompt, device, max_new_tokens=100)
    print("
--- Văn bản tạo ra ---")
    print(generated_text_custom)

Sample:

from huggingface_hub import snapshot_download
from tokenizers import Tokenizer
import safetensors.torch
import torch
import json
import sys
from pathlib import Path

# --- 1. Tải toàn bộ repo về thư mục cục bộ ---
repo_id = "shumi2011/ivote3p"
local_model_dir = Path("./ivote3p_model_local")

print(f"Đang tải mô hình từ repo_id về local_model_dir...")
snapshot_download(repo_id=repo_id, local_dir=local_model_dir)
print("Tải hoàn tất!")

# --- 2. Khởi tạo Tokenizer và Config ---
tokenizer = Tokenizer.from_file(str(local_model_dir / "tokenizer.json"))
with open(local_model_dir / "config.json", 'r', encoding='utf-8') as f:
    model_cfg_params = json.load(f)

# --- 3. Khởi tạo Model (dùng hàm pm.iVoteModel đã có từ quá trình train) ---
model_cfg_for_init = {k: v for k, v in model_cfg_params.items() if k not in ['_name_or_path', 'architectures', 'torch_dtype', 'transformers_version', 'model_type']}
if isinstance(model_cfg_for_init.get('dtype'), str):
    model_cfg_for_init['dtype'] = getattr(torch, model_cfg_for_init['dtype'].rsplit('.', 1)[-1])
local_model = pm.iVoteModel(model_cfg_for_init)

# --- 4. Tải trọng số từ file safetensors ---
state_dict = safetensors.torch.load_file(local_model_dir / "model.safetensors", device="cpu")
local_model.load_state_dict(state_dict, strict=False)

device = "cuda" if torch.cuda.is_available() else "cpu"
local_model.to(device)
print("Mô hình local đã sẵn sàng!")

# --- 5. Chạy thử Inference ---
local_model.eval()
prompt = "[BOS] Ngay"
with torch.no_grad():
    text = pm.generate_text(local_model, tokenizer, prompt, device, max_new_tokens=40)
print(text)

Fine-tuning (Huấn luyện lại)

Để fine-tune hoặc tiếp tục huấn luyện mô hình iVote3P trên dữ liệu mới:

  1. Dữ liệu: Chuẩn bị dữ liệu và encode nó thành file .bin sử dụng file tokenizer.json bạn vừa tải về trong thư mục ./ivote3p_model.
  2. Khởi tạo Model: Làm tương tự Bước 1 đến Bước 4 ở phần Inference bên trên để có biến model.
  3. Vòng lặp huấn luyện: Sử dụng optimizer, tính toán loss và step cập nhật như trong project gốc iVote3P.
# Ví dụ thiết lập optimizer từ codebase
# from ivote3p.parity_model import build_optimizer_param_groups, forward_with_mtp_loss

# optimizer = torch.optim.AdamW(
#     build_optimizer_param_groups(model, model_cfg_params, weight_decay=0.0),
#     lr=1e-5,
#     betas=(0.9, 0.999),
# )

# model.train()
# # X, Y = get_batch("train")
# # fw = forward_with_mtp_loss(model, X, Y, model_cfg_params, iter + 1)
# # total_loss = fw["total_loss"]
# # optimizer.zero_grad()
# # total_loss.backward()
# # optimizer.step()

Dữ liệu Huấn luyện

Mô hình được huấn luyện trên một tập dữ liệu tiếng Việt tùy chỉnh, tập trung vào các đặc tính văn bản cụ thể liên quan đến dự án iVote3P.

Tokenizer

Tokenizer được sử dụng là một tokenizer Byte-Pair Encoding (BPE) tùy chỉnh, được huấn luyện trên dữ liệu tiếng Việt.

Lời cảm ơn

Mô hình này là một phần của dự án iVote3P.

Downloads last month
211
Safetensors
Model size
0.1B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support