HuggingFace镜像/indobert-large-p2-openmind
模型介绍文件和版本分析
下载使用量0

IndoBERT Large 模型(第二阶段 - 不区分大小写)

IndoBERT 是基于 BERT 模型的印尼语最先进语言模型。该预训练模型通过掩码语言建模(MLM)目标和下一句预测(NSP)目标进行训练。

所有预训练模型

模型参数数量架构训练数据
indobenchmark/indobert-base-p11.245 亿BaseIndo4B(23.43 GB 文本)
indobenchmark/indobert-base-p21.245 亿BaseIndo4B(23.43 GB 文本)
indobenchmark/indobert-large-p13.352 亿LargeIndo4B(23.43 GB 文本)
indobenchmark/indobert-large-p23.352 亿LargeIndo4B(23.43 GB 文本)
indobenchmark/indobert-lite-base-p10.117 亿BaseIndo4B(23.43 GB 文本)
indobenchmark/indobert-lite-base-p20.117 亿BaseIndo4B(23.43 GB 文本)
indobenchmark/indobert-lite-large-p10.177 亿LargeIndo4B(23.43 GB 文本)
indobenchmark/indobert-lite-large-p20.177 亿LargeIndo4B(23.43 GB 文本)

在 Openmind 中的使用

from openmind import AutoTokenizer, AutoModel, 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 time

# Mean Pooling - Take attention mask into account for correct averaging
def mean_pooling(model_output, attention_mask):
    token_embeddings = model_output[0]  # First element of model_output contains all token embeddings
    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="jeffding/indobert-large-p2-openmind",
    )
    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"
        
    # Load model from HuggingFace Hub
    tokenizer = AutoTokenizer.from_pretrained(model_path,trust_remote_code=True)
    model = AutoModel.from_pretrained(model_path, trust_remote_code=True).to(device)
    start_time = time.time()
    sentences = ['aku adalah anak']
    # Tokenize sentences
    encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt').to(device)

    # Compute token embeddings
    with torch.no_grad():
        model_output = model(**encoded_input)
    # Perform pooling. In this case, mean pooling.
    sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
    print("Sentence embeddings:")
    print(sentence_embeddings)
    
    end_time = time.time()
    print(f"硬件环境:{device},推理执行时间:{end_time - start_time}秒")
    
if __name__ == "__main__":
    main()

如何使用

加载模型和分词器

from transformers import BertTokenizer, AutoModel
tokenizer = BertTokenizer.from_pretrained("indobenchmark/indobert-large-p2")
model = AutoModel.from_pretrained("indobenchmark/indobert-large-p2")

提取上下文表征

x = torch.LongTensor(tokenizer.encode('aku adalah anak [MASK]')).view(1,-1)
print(x, model(x)[0].sum())

作者

IndoBERT 由 Bryan Wilie*、Karissa Vincentio*、Genta Indra Winata*、Samuel Cahyawijaya*、Xiaohong Li、Zhi Yuan Lim、Sidik Soleman、Rahmad Mahendra、Pascale Fung、Syafri Bahar、Ayu Purwarianti 进行训练和评估。

引用

如果您使用我们的研究成果,请引用:

@inproceedings{wilie2020indonlu,
  title={IndoNLU: Benchmark and Resources for Evaluating Indonesian Natural Language Understanding},
  author={Bryan Wilie and Karissa Vincentio and Genta Indra Winata and Samuel Cahyawijaya and X. Li and Zhi Yuan Lim and S. Soleman and R. Mahendra and Pascale Fung and Syafri Bahar and A. Purwarianti},
  booktitle={Proceedings of the 1st Conference of the Asia-Pacific Chapter of the Association for Computational Linguistics and the 10th International Joint Conference on Natural Language Processing},
  year={2020}
}