HuggingFace镜像/verdict-classifier
模型介绍文件和版本分析
下载使用量0

openmind使用教程

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


# 均值池化 - 考虑注意力掩码以进行正确的平均
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="../",
    )
    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"

    # 我们想要获取句子嵌入的句子
    sentences = ['This is an example sentence', 'Each sentence is converted']

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

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

    # 计算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)

    print("Sentence embeddings:")
    print(sentence_embeddings)


if __name__ == "__main__":
    main()

多语言判决分类器

该模型是 xlm-roberta-base 的微调版本,基于来自 Google Fact Check Tools API 的 2500 份去重多语言判决,通过 Google Cloud Translation API 翻译成 65 种语言。 它在包含 1000 份此类判决的评估集上取得了以下结果,但此处包含重复项以反映真实分布:

  • 损失:0.2238
  • F1 宏平均:0.8540
  • F1 虚假信息:0.9798
  • F1 事实性:0.9889
  • F1 其他:0.5934
  • 精确率宏平均:0.8348
  • 精确率虚假信息:0.9860
  • 精确率事实性:0.9889
  • 精确率其他:0.5294

训练过程

训练超参数

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

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

训练结果

训练损失轮次步数验证损失F1 宏平均F1 虚假信息F1 事实性F1 其他精确率宏平均精确率虚假信息精确率事实性精确率其他
1.11090.120001.21660.07130.14970.00.06400.24510.70190.00.0334
0.95510.240000.78010.36110.88890.00.19430.33910.89150.00.1259
0.92750.360000.77120.34680.91230.00.12820.33040.90510.00.0862
0.88810.3980000.53860.39400.95240.00.22970.37230.97480.00.1420
0.78510.49100000.32980.68860.96260.76400.33930.67210.97980.77270.2639
0.6390.59120000.21560.78470.96330.93550.45540.75400.97870.90620.3770
0.56770.69140000.16820.78770.96940.96670.42700.77630.97450.96670.3878
0.52180.79160000.14750.80370.96920.96670.47520.78040.98120.96670.3934
0.46820.89180000.14580.80970.97340.96670.48890.79530.97910.96670.44
0.41880.98200000.14160.83700.97690.97240.56180.81990.98260.96700.5102
0.37351.08220000.16240.80940.96980.93680.52170.77800.98230.890.4615
0.32421.18240000.16480.83380.97690.97270.55170.81670.98260.95700.5106
0.27851.28260000.18430.82610.97390.97800.52630.80180.98360.96740.4545
0.251.38280000.19750.83440.97440.98340.54550.80720.98590.97800.4576
0.21761.48300000.18490.82090.96910.98890.50470.79220.98460.98890.4030
0.19661.58320000.21190.81940.96850.99440.49540.79200.98461.00.3913
0.17381.67340000.21100.83520.97080.99440.54050.80350.98811.00.4225
0.16251.77360000.21520.81650.97090.98340.49500.79050.98350.97800.4098
0.15221.87380000.23000.80970.96970.98320.47620.78560.98350.98880.3846
0.1451.97400000.19550.85190.97740.98890.58950.82800.98600.98890.5091
0.12482.07420000.23080.81490.97030.98890.48540.78970.98350.98890.3968
0.11862.17440000.23680.81720.97330.98340.49480.79420.98360.97800.4211
0.11222.26460000.24010.79680.98040.89570.51430.80010.98491.00.4154
0.10992.36480000.22900.81190.96470.98340.48740.77770.98800.97800.3671
0.10932.46500000.22560.82470.97450.98890.51060.80530.98250.98890.4444
0.10532.56520000.24160.84560.97990.98890.56790.84340.98050.98890.5610
0.10492.66540000.28500.75850.97400.89020.41120.76500.98020.98650.3284
0.0982.76560000.28280.80490.96420.98890.46150.77500.98560.98890.3506
0.09622.86580000.22380.85400.97980.98890.59340.83480.98600.98890.5294
0.09752.95600000.24940.82490.97150.98890.51430.79670.98580.98890.4154
0.08773.05620000.24640.82740.97330.98890.52000.80230.98470.98890.4333
0.08483.15640000.23380.82630.97400.98890.51610.80770.98140.98890.4528
0.08593.25660000.23350.83650.97500.98890.54550.81080.98590.98890.4576
0.0843.35680000.20670.83430.97630.98890.53760.81480.98370.98890.4717
0.08373.45700000.25160.82490.97460.98890.51110.80970.98030.98890.46
0.08093.54720000.29480.82580.97280.99440.51020.80450.98241.00.4310
0.08333.64740000.24570.84940.97440.99440.57940.81730.98931.00.4627
0.07963.74760000.31880.82770.97330.98890.52080.80590.98250.98890.4464
0.08213.84780000.26420.83430.97140.99440.53700.80450.98701.00.4265

框架版本

  • Transformers 4.11.3
  • Pytorch 1.9.0+cu102
  • Datasets 1.9.0
  • Tokenizers 0.10.2