HuggingFace镜像/dictalm2.0-instruct-fine-tuned
模型介绍文件和版本分析
下载使用量0

ronigold/dictalm2.0-instruct-fine-tuned 模型卡片

这是 Dicta-IL dictalm2.0-instruct 模型的微调版本,专门用于基于希伯来语维基百科摘录生成问答对。 该模型经过微调,以提升其理解和生成希伯来语自然问题及对应答案的能力。

模型详情

模型描述

ronigold/dictalm2.0-instruct-fine-tuned 模型是在合成生成的数据集上对 dictalm2.0-instruct 模型进行微调得到的版本。该数据集由模型自身利用希伯来语维基百科的摘录创建,随后用于生成问题和答案,从而增强模型在这一特定任务上的能力。

  • 开发者: Roni Goldshmidt
  • 模型类型: 基于 Transformer,微调自 Dicta-IL dictalm2.0-instruct
  • 语言(NLP): 希伯来语
  • 许可证: MIT
  • 微调基础模型: dicta-il/dictalm2.0-instruct

用途

在 openmind 中的使用

import os
import time
import argparse
import torch
import numpy as np
from openmind import pipeline, is_torch_npu_available
from openmind import AutoTokenizer, AutoModelForCausalLM
from openmind_hub import snapshot_download

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

def model_npu_inference(model_path: str):
    # 确保使用 NPU 设备
    if is_torch_npu_available():
        print("NPU available, use device_map='auto'.")
        device_map = "auto"
    else:
        print("NPU not available, use device_map='cpu'.")
        device_map = "cpu"

        # 创建 Text Generation pipeline,指定 NPU 设备
    try:
        task_pipeline = pipeline(
            task="text-generation",
            model=model_path,
            device_map=device_map,
            framework="pt",
            truncation=True
        )

        abs_model_path = os.path.abspath(model_path)
        model_name = os.path.basename(abs_model_path)

        chat = [
            {
                "role": "user",
                "content": "How many helicopters can a human eat in one sitting?",
            },
        ]

        chat_input = task_pipeline.tokenizer.apply_chat_template(chat, tokenize=False)

        # 定义推理样例
        prompt = [
            chat_input,
        ]

        # 推理性能测试
        inference_times = []
        num_runs = 10

        print(f"\n=== NPU {model_name} 性能测试 ===")

        for _ in range(num_runs):
            # 随机选择输入文本
            input_text = prompt[_ % len(prompt)]

            # 性能计时
            start_time = time.time()
            results = task_pipeline(input_text, max_new_tokens=50)
            torch.npu.synchronize()

            inference_time = time.time() - start_time
            inference_times.append(inference_time)

            # 打印第一次推理的详细结果
            if _ == 0:
                print(f"输入文本: {input_text}")
                print("生成结果:")
                print(f"  {results[0]['generated_text']}")

                # 计算性能统计
        avg_time = np.mean(inference_times)
        std_time = np.std(inference_times)

        print("\n性能分析:")
        print(f"NPU平均推理时间: {avg_time:.4f} 秒")
        print(f"NPU推理时间标准差: {std_time:.4f} 秒")
        print("推理时间列表:", inference_times)

    except Exception as e:
        print(f"NPU 推理发生错误!")
        raise e

def main():
    # 解析命令行参数
    # 参数:--model_name_or_path
    args = parse_args()
    model_path = args.model_name_or_path
    model_npu_inference(model_path)


if __name__ == "__main__":
    main()

直接使用

该模型非常适合教育和信息类应用场景,这类场景需要从文本内容中生成上下文相关的问答对,尤其适用于希伯来语。

超出范围的使用

该模型不适合用于生成对未经验证来源的事实准确性有严格要求的答案,例如医疗建议或法律信息。

偏差、风险和局限性

尽管该模型在生成上下文相关的问答对方面表现稳健,但它仍可能继承或放大训练数据中存在的偏差,而训练数据主要来源于维基百科。用户应批判性地评估模型输出,尤其是在敏感场景中。

建议

当在敏感或关键应用中使用该模型时,建议增加一层人工监督,以确保生成内容的准确性和适当性。

如何开始使用模型

要开始使用,请通过 Hugging Face 的 Transformers 库加载模型:

from transformers import AutoModelForQuestionAnswering, AutoTokenizer

model_name = "ronigold/dictalm2.0-instruct-fine-tuned"
model = AutoModelForQuestionAnswering.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)

训练详情

训练数据

训练数据包含从希伯来语维基百科生成的合成问答对。随后,这些数据被用于通过特定的损失函数和优化策略对模型进行微调,以提升其生成类似问答对的性能。

# Example of setting up training in PyTorch using the Transformers library
from transformers import Trainer, TrainingArguments

training_args = TrainingArguments(
    output_dir='./results',          # output directory
    num_train_epochs=3,              # number of training epochs
    per_device_train_batch_size=16,  # batch size per device during training
    warmup_steps=500,                # number of warmup steps for learning rate scheduler
    weight_decay=0.01,               # strength of weight decay
    logging_dir='./logs',            # directory for storing logs
    logging_steps=10,
)

trainer = Trainer(
    model=model,                         # the instantiated 🤗 Transformers model to be trained
    args=training_args,                  # training arguments, defined above
    train_dataset=train_dataset,         # training dataset
    eval_dataset=eval_dataset            # evaluation dataset
)

trainer.train()

训练过程

训练超参数

  • 训练模式: 混合精度训练(fp16),以优化 GPU 使用率并加快训练速度,同时保持精度。
# Configuration for mixed precision training
from transformers import set_seed

set_seed(42)  # Set seed for reproducibility

# Adding mixed precision policy
from torch.cuda.amp import GradScaler, autocast

scaler = GradScaler()

# Training loop
for epoch in range(int(training_args.num_train_epochs)):
    model.train()
    for batch in train_dataloader:
        optim.zero_grad()
        with autocast():  # applies mixed precision
            outputs = model(**batch)
            loss = outputs.loss
        scaler.scale(loss).backward()
        scaler.step(optim)
        scaler.update()

评估

测试数据、影响因素与指标

测试数据

本模型在一个独立的保留集上进行评估,该保留集同样通过与训练集相似的方式人工合成生成。

影响因素

  • 领域:评估涵盖了希伯来语维基百科内的多个领域,以确保模型在不同类型内容上的泛化能力。
  • 难度:问题的复杂度各不相同,以此测试模型处理简单直接和复杂查询的能力。

指标

评估指标包括F1分数和精确匹配率(EM),用于衡量模型生成答案的准确性。

结果

该模型取得了88%的F1分数和75%的精确匹配率,表明其在生成准确答案方面表现优异,尤其在合成问题的语境下。

技术规格

模型架构与目标

该模型采用基于Transformer的架构,并进行了针对性修改,以优化问题生成和问答任务的性能。

计算基础设施

训练在云GPU上进行,具体使用了NVIDIA Tesla V100 GPU,为高效训练提供了必要的计算能力。

环境影响

引用

BibTeX格式:

@misc{ronigold_dictalm2.0_instruct_finetuned_2024,
  author = {Goldshmidt, Roni},
  title = {Hebrew QA Fine-tuned Model},
  year = {2024},
  publisher = {Hugging Face's Model Hub},
  journal = {Hugging Face's Model Hub}
}

更多信息

有关更详细的使用方法,包括高级配置和提示,请参考仓库的 README 或联系模型作者。该模型是增强希伯来语自然语言处理(NLP)能力这一更广泛计划的一部分,旨在为有兴趣将先进人工智能技术应用于希伯来语文本的开发人员和研究人员提供支持。

模型卡片作者

  • Roni Goldshmidt:微调模型的主要研究员和开发人员。

模型卡片联系方式

如对模型有任何问题或反馈,请通过 Hugging Face 个人资料联系,或直接发送邮件至 ronigoldsmid@gmail.com。