hf_mirrors/verdict-classifier
Model Introduction
Files & versions
Analysis

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()

Multilingual Verdict Classifier

This model is a fine-tuned version of xlm-roberta-base on 2,500 deduplicated multilingual verdicts from Google Fact Check Tools API, translated into 65 languages with the Google Cloud Translation API. It achieves the following results on the evaluation set, being 1,000 such verdicts, but here including duplicates to represent the true distribution:

  • Loss: 0.2238
  • F1 Macro: 0.8540
  • F1 Misinformation: 0.9798
  • F1 Factual: 0.9889
  • F1 Other: 0.5934
  • Prec Macro: 0.8348
  • Prec Misinformation: 0.9860
  • Prec Factual: 0.9889
  • Prec Other: 0.5294

Training procedure

Training hyperparameters

The following hyperparameters were used during training:

  • learning_rate: 2e-05
  • train_batch_size: 4
  • eval_batch_size: 4
  • seed: 42
  • gradient_accumulation_steps: 8
  • total_train_batch_size: 32
  • optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
  • lr_scheduler_type: linear
  • lr_scheduler_warmup_steps: 162525
  • num_epochs: 1000

Training results

Training LossEpochStepValidation LossF1 MacroF1 MisinformationF1 FactualF1 OtherPrec MacroPrec MisinformationPrec FactualPrec Other
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

Framework versions

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