hf_mirrors/xglm-564M-openmind
Model Introduction
Files & versions
Analysis

XGLM-564M

XGLM-564M is a multilingual autoregressive language model (with 564 million parameters) trained on a balanced corpus of a diverse set of 30 languages totaling 500 billion sub-tokens. It was introduced in the paper Few-shot Learning with Multilingual Language Models by Xi Victoria Lin*, Todor Mihaylov, Mikel Artetxe, Tianlu Wang, Shuohui Chen, Daniel Simig, Myle Ott, Naman Goyal, Shruti Bhosale, Jingfei Du, Ramakanth Pasunuru, Sam Shleifer, Punit Singh Koura, Vishrav Chaudhary, Brian O'Horo, Jeff Wang, Luke Zettlemoyer, Zornitsa Kozareva, Mona Diab, Veselin Stoyanov, Xian Li* (*Equal Contribution). The original implementation was released in this repository.

Training Data Statistics

The training data statistics of XGLM-564M is shown in the table below.

ISO-639-1familyname# tokensratioratio w/ lowRes upsampling
enIndo-EuropeanEnglish8035267361240.4899060.3259
ruIndo-EuropeanRussian1477918980980.09010790.0602
zhSino-TibetanChinese1327704946300.08094940.0483
deIndo-EuropeanGerman892237078560.05439920.0363
esIndo-EuropeanSpanish873030831050.05322820.0353
frIndo-EuropeanFrench774196397750.04720230.0313
jaJaponicJapanese660543645130.0402730.0269
itIndo-EuropeanItalian419304653380.02556480.0171
ptIndo-EuropeanPortuguese365860324440.02230630.0297
elIndo-EuropeanGreek (modern)287621661590.01753610.0233
koKoreanicKorean200022445350.01219530.0811
fiUralicFinnish168043097220.01024550.0681
idAustronesianIndonesian154235419530.009403650.0125
trTurkicTurkish124131660650.007568240.0101
arAfro-AsiaticArabic122486073450.007467910.0099
viAustroasiaticVietnamese111991218690.006828040.0091
thTai–KadaiThai108421728070.006610410.044
bgIndo-EuropeanBulgarian97037978690.005916350.0393
caIndo-EuropeanCatalan70758347750.00431410.0287
hiIndo-EuropeanHindi34483901100.002102460.014
etUralicEstonian32868738510.002003990.0133
bnIndo-EuropeanBengali, Bangla16274474500.0009922450.0066
taDravidianTamil14769733970.0009005020.006
urIndo-EuropeanUrdu13518919690.0008242410.0055
swNiger–CongoSwahili9075161390.0005533070.0037
teDravidianTelugu6893164850.0004202720.0028
euLanguage isolateBasque1053044236.42035e-050.0043
mySino-TibetanBurmese1013583316.17976e-050.003
htCreoleHaitian, Haitian Creole865846975.27902e-050.0035
quQuechuanQuechua32361081.97304e-060.0001

Model card

For intended usage of the model, please refer to the model card released by the XGLM-564M development team.

Example (COPA)

The following snippet shows how to evaluate our models (GPT-3 style, zero-shot) on the Choice of Plausible Alternatives (COPA) task, using examples in English, Chinese and Hindi.

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

def get_logprobs(prompt):
        inputs = tokenizer(prompt, return_tensors="pt")
        input_ids, output_ids = inputs["input_ids"], inputs["input_ids"][:, 1:]
        outputs = model(**inputs, labels=input_ids)
        logits = outputs.logits
        logprobs = torch.gather(F.log_softmax(logits, dim=2), 2, output_ids.unsqueeze(2))
        return logprobs

# Zero-shot evaluation for the Choice of Plausible Alternatives (COPA) task.
# A return value of 0 indicates that the first alternative is more plausible,
# while 1 indicates that the second alternative is more plausible.
def COPA_eval(prompt, alternative1, alternative2):
    lprob1 = get_logprobs(prompt + "\n" + alternative1).sum()
    lprob2 = get_logprobs(prompt + "\n" + alternative2).sum()
    return 0 if lprob1 > lprob2 else 1

def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--model_name_or_path",
        type=str,
        help="Path to model",
        default="jeffding/xglm-564M-openmind",
    )
    args = parser.parse_args()
    return args


args = parse_args()
model_path = args.model_name_or_path

if is_torch_npu_available():
    device = "npu:0"
else:
    device = "cpu"
        
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(model_path)

data_samples = {
    'en': [
        {
            "premise": "I wanted to conserve energy.",
            "choice1": "I swept the floor in the unoccupied room.",
            "choice2": "I shut off the light in the unoccupied room.",
            "question": "effect",
            "label": "1"
        },
        {
            "premise": "The flame on the candle went out.",
            "choice1": "I blew on the wick.",
            "choice2": "I put a match to the wick.",
            "question": "cause",
            "label": "0"
        }
    ],
    'zh': [
        {
            "premise": "我想节约能源。",
            "choice1": "我在空着的房间里扫了地板。",
            "choice2": "我把空房间里的灯关了。",
            "question": "effect",
            "label": "1"
        },
        {
            "premise": "蜡烛上的火焰熄灭了。",
            "choice1": "我吹灭了灯芯。",
            "choice2": "我把一根火柴放在灯芯上。",
            "question": "cause",
            "label": "0"
        }
    ],
    'hi': [
        {
            "premise": "M te vle konsève enèji.",
            "choice1": "Mwen te fin baleye chanm lib la.",
            "choice2": "Mwen te femen limyè nan chanm lib la.",
            "question": "effect",
            "label": "1"
        },
        {
            "premise": "Flam bouji a te etenn.",
            "choice1": "Mwen te soufle bouji a.",
            "choice2": "Mwen te limen mèch bouji a.",
            "question": "cause",
            "label": "0"
        }
    ]
}



for lang in data_samples:
    for idx, example in enumerate(data_samples[lang]):
        predict = COPA_eval(example["premise"], example["choice1"], example["choice2"])
        print(f'{lang}-{idx}', predict, example['label'])