OSError: jplu/tf-xlm-r-ner-40-lang does not appear to have a file named pytorch_model.bin or model.safetensors.

#2
by Innovator2K - opened

When I use a code example from the model card:

from transformers import pipeline

nlp_ner = pipeline(
    "ner",
    model="jplu/tf-xlm-r-ner-40-lang",
    tokenizer=(
        'jplu/tf-xlm-r-ner-40-lang',  
        {"use_fast": True}),
    framework="tf"
)

I get the error from the title. How to fix this?

I've fixed the error by downgrading transformers (pip install "transformers<5.0.0" tf-keras) and by using appropriate classes explicitly:

from transformers import pipeline, TFAutoModelForTokenClassification, AutoTokenizer

model_id = "jplu/tf-xlm-r-ner-40-lang"

model = TFAutoModelForTokenClassification.from_pretrained(model_id)
tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=True)

nlp_ner = pipeline(
    "ner",
    model=model,
    tokenizer=tokenizer,
    framework="tf"
)

but I'm not sure if this is correct since print(nlp_ner("My name is Wolfgang and I live in Berlin")) outputs

[{'entity': 'ORG', 'score': np.float32(0.88247555), 'index': 1, 'word': '▁My', 'start': np.int32(0), 'end': np.int32(2)}, {'entity': 'ORG', 'score': np.float32(0.89197344), 'index': 2, 'word': '▁name', 'start': np.int32(2), 'end': np.int32(7)}, {'entity': 'ORG', 'score': np.float32(0.89584696), 'index': 3, 'word': '▁is', 'start': np.int32(7), 'end': np.int32(10)}, {'entity': 'ORG', 'score': np.float32(0.94686174), 'index': 4, 'word': '▁Wolfgang', 'start': np.int32(10), 'end': np.int32(19)}, {'entity': 'ORG', 'score': np.float32(0.8547713), 'index': 5, 'word': '▁and', 'start': np.int32(19), 'end': np.int32(23)}, {'entity': 'ORG', 'score': np.float32(0.89959824), 'index': 6, 'word': '▁I', 'start': np.int32(23), 'end': np.int32(25)}, {'entity': 'ORG', 'score': np.float32(0.75958645), 'index': 7, 'word': '▁live', 'start': np.int32(25), 'end': np.int32(30)}, {'entity': 'ORG', 'score': np.float32(0.63853705), 'index': 8, 'word': '▁in', 'start': np.int32(30), 'end': np.int32(33)}, {'entity': 'ORG', 'score': np.float32(0.7321577), 'index': 9, 'word': '▁Berlin', 'start': np.int32(33), 'end': np.int32(40)}]

😢

Sign up or log in to comment