HuggingFace镜像/deberta-v3-large-reward-model
模型介绍文件和版本分析

如何使用

# from openmind import omdatasets, pipeline, is_torch_npu_available, AutoTokenizer
# import argparse
# import time
# def parse_args():
#     parser = argparse.ArgumentParser()
#     parser.add_argument(
#         "--model_name_or_path",
#         type=str,
#         help="Path to model",
#         default="/home/ma-user/work/pretrainmodel/deberta-v3-large-reward-model",
#     )
#     args = parser.parse_args()
#     return args

# args = parse_args()
# model_path = args.model_name_or_path

# if is_torch_npu_available():
#     device = "npu:0"
# else:
#     device = "cpu"
# #device = "cpu"
# start_time = time.time()
# unmasker = pipeline('text-classification', model=model_path,device=device)
# print(unmasker("The man worked as a <mask>."))
# end_time = time.time()
# print(f"硬件环境:{device},推理执行时间:{end_time - start_time}秒")



from openmind import AutoTokenizer, AutoModel, is_torch_npu_available
from openmind_hub import snapshot_download
import torch
import argparse
import torch.nn.functional as F
import os
import time

# 均值池化 - 考虑注意力掩码以进行正确的平均
def mean_pooling(model_output, attention_mask):
    token_embeddings = model_output[0] # model_output的第一个元素包含所有token嵌入
    input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
    return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)

def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--model_name_or_path",
        type=str,
        help="Path to model",
        default="zhouhui/deberta-v3-large-reward-model",
    )
    args = parser.parse_args()
    return args

def main():
    args = parse_args()
    model_path = args.model_name_or_path

    if is_torch_npu_available():
        device = "npu:0"
    else:
        device = "cpu"
    #device = "cpu"
    start_time = time.time()
    # 我们想要获取句子嵌入的句子
    sentences = ['This is an example sentence', 'Each sentence is converted']

    # 从openmind_hub加载模型
    tokenizer = AutoTokenizer.from_pretrained(model_path)
    model = AutoModel.from_pretrained(model_path).to(device)
    #model = AutoModel.from_pretrained(model_path).to("cpu")

    # 对句子进行分词
    encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt').to(device)
    #encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt').to("cpu")

    # 计算token嵌入
    with torch.no_grad():
        model_output = model(**encoded_input)

    # 执行池化
    sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])

    # 归一化嵌入
    sentence_embeddings = F.normalize(sentence_embeddings, p=2, dim=1)
    end_time = time.time()
    print("Sentence embeddings:")
    print(sentence_embeddings)
    time_taken = end_time - start_time
    print(f"硬件环境:{device},推理执行时间:{time_taken}秒")
    #print(f"硬件环境:cpu,推理执行时间:{time_taken}秒")

if __name__ == "__main__":
    main()

deberta-v3-large-reward-model

该模型是 microsoft/deberta-v3-large 在一个未知数据集上的微调版本。 它在评估集上取得了以下结果:

  • 损失:0.0106
  • 准确率:0.995

模型描述

需要更多信息

预期用途与局限性

需要更多信息

训练与评估数据

需要更多信息

训练过程

训练超参数

训练过程中使用了以下超参数:

  • 学习率:1.41e-05
  • 训练批次大小:16
  • 评估批次大小:8
  • 随机种子:42
  • 梯度累积步数:2
  • 总训练批次大小:32
  • 优化器:Adam,betas=(0.9,0.999),epsilon=1e-08
  • 学习率调度器类型:线性
  • 训练轮数:10.0

训练结果

训练损失轮次步数验证损失准确率
0.02132.01000.02050.995
0.0024.02000.01280.995
0.00056.03000.01070.995
0.00018.04000.01100.995
0.000110.05000.01060.995

框架版本

  • Transformers 4.41.2
  • Pytorch 2.3.0
  • Datasets 2.19.1
  • Tokenizers 0.19.1
下载使用量0