hf_mirrors/job-listing-relevance-model
Model Introduction
Files & versions
Analysis
You are visiting the mirror address of https://modelers.cn/Rose/job-listing-relevance-model. The repo is synchronized in real-time and is only for mirror acceleration access.

openmind使用教程

from openmind import AutoTokenizer,AutoModel, is_torch_npu_available
from openmind_hub import snapshot_download
# from transformers import AAutoTokenizer
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()

job-listing-relevance-model

This model is a fine-tuned version of xlm-roberta-base on the None dataset. It achieves the following results on the evaluation set:

  • Loss: 0.1649

Model description

More information needed

Intended uses & limitations

More information needed

Training and evaluation data

More information needed

Training procedure

Training hyperparameters

The following hyperparameters were used during training:

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

Training results

Training LossEpochStepValidation Loss
0.74350.43500.6889
0.32220.871000.2906
0.25731.31500.1937
0.12051.742000.1411
0.15862.172500.2008
0.07552.613000.1926
0.0623.043500.2257
0.06443.484000.1497
0.10343.914500.1561
0.0084.355000.2067
0.06164.785500.2067
0.07665.226000.1494
0.00295.656500.2078
0.10766.097000.1669
0.00256.527500.1564
0.04986.958000.2355
0.00117.398500.1652
0.02717.829000.1731
0.0128.269500.1590
0.02578.6910000.1638
0.00099.1310500.1851
0.00139.5611000.1613
0.001510.011500.1649

Framework versions

  • Transformers 4.17.0
  • Pytorch 1.11.0+cu113
  • Datasets 2.0.0
  • Tokenizers 0.11.6