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

gpt2-wechsel-chinese

使用WECHSEL训练的模型:用于单语语言模型跨语言迁移的子词嵌入有效初始化。

代码详见:https://github.com/CPJKU/wechsel

论文详见:https://aclanthology.org/2022.naacl-main.293/

使用方法

from openmind import AutoTokenizer, AutoModelForCausalLM, is_torch_npu_available
from openmind_hub import snapshot_download
import torch.nn.functional as F
from torch import Tensor
import openmind
import torch
import argparse
import sys
import time

def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--model_name_or_path",
        type=str,
        help="Path to model",
        default="zhouhui/gpt2-wechsel-chinese",
    )
    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"
    start_time = time.time()      
    model = AutoModelForCausalLM.from_pretrained(model_path).to(device)
    tokenizer = AutoTokenizer.from_pretrained(model_path)
    model.eval()

    prompt = "Hello, who are you?"
    input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(device)
    outputs = model.generate(input_ids=input_ids, max_length=100)
    response = tokenizer.decode(outputs[0], skip_special_tokens=True)
    print(response)
    end_time = time.time()
    print(f"硬件环境:{device},推理执行时间:{end_time - start_time}秒")
    
if __name__ == "__main__":
    main()

性能

RoBERTa

模型NLI 得分NER 得分平均得分
roberta-base-wechsel-french82.4390.8886.65
camembert-base80.8890.2685.57
模型NLI 得分NER 得分平均得分
roberta-base-wechsel-german81.7989.7285.76
deepset/gbert-base78.6489.4684.05
模型NLI 得分NER 得分平均得分
roberta-base-wechsel-chinese78.3280.5579.44
bert-base-chinese76.5582.0579.30
模型NLI 得分NER 得分平均得分
roberta-base-wechsel-swahili75.0587.3981.22
xlm-roberta-base69.1887.3778.28

GPT2

模型困惑度(PPL)
gpt2-wechsel-french19.71
gpt2(从头重新训练)20.47
模型困惑度(PPL)
gpt2-wechsel-german26.8
gpt2(从头重新训练)27.63
模型困惑度(PPL)
gpt2-wechsel-chinese51.97
gpt2(从头重新训练)52.98
模型困惑度(PPL)
gpt2-wechsel-swahili10.14
gpt2(从头重新训练)10.58

详见我们的论文。

引用

请按以下方式引用 WECHSEL:

@inproceedings{minixhofer-etal-2022-wechsel,
    title = "{WECHSEL}: Effective initialization of subword embeddings for cross-lingual transfer of monolingual language models",
    author = "Minixhofer, Benjamin  and
      Paischer, Fabian  and
      Rekabsaz, Navid",
    booktitle = "Proceedings of the 2022 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies",
    month = jul,
    year = "2022",
    address = "Seattle, United States",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2022.naacl-main.293",
    pages = "3992--4006",
    abstract = "Large pretrained language models (LMs) have become the central building block of many NLP applications. Training these models requires ever more computational resources and most of the existing models are trained on English text only. It is exceedingly expensive to train these models in other languages. To alleviate this problem, we introduce a novel method {--} called WECHSEL {--} to efficiently and effectively transfer pretrained LMs to new languages. WECHSEL can be applied to any model which uses subword-based tokenization and learns an embedding for each subword. The tokenizer of the source model (in English) is replaced with a tokenizer in the target language and token embeddings are initialized such that they are semantically similar to the English tokens by utilizing multilingual static word embeddings covering English and the target language. We use WECHSEL to transfer the English RoBERTa and GPT-2 models to four languages (French, German, Chinese and Swahili). We also study the benefits of our method on very low-resource languages. WECHSEL improves over proposed methods for cross-lingual parameter transfer and outperforms models of comparable size trained from scratch with up to 64x less training effort. Our method makes training large language models for new languages more accessible and less damaging to the environment. We make our code and models publicly available.",
}