Skip to content

text.split is not a function #525

@Maxzurek

Description

@Maxzurek

System Info

transformer.js version: 2.14.0
Framework: React (18.2.0)
Browser: Chrome (120.0.6099.218)
Node.js version: 20.2.0

Environment/Platform

  • Website/web-app
  • Browser extension
  • Server-side (e.g., Node.js, Deno, Bun)
  • Desktop app (e.g., Electron)
  • Other (e.g., VSCode extension)

Description

I am attempting to use the crossencoder-distilcamembert-mmarcoFR model as a re-ranker in React, following the provided model card and inference code. The original Python code using the transformers library functions as expected, but when translating it to React using transformer.js, I encounter a TypeError related to the PreTrainedTokenizer constructor.

Model Information

Python code from the model card

from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

model = AutoModelForSequenceClassification.from_pretrained('antoinelouis/crossencoder-distilcamembert-mmarcoFR')
tokenizer = AutoTokenizer.from_pretrained('antoinelouis/crossencoder-distilcamembert-mmarcoFR')

pairs = [('Query', 'Paragraph1'), ('Query', 'Paragraph2') , ('Query', 'Paragraph3')]
features = tokenizer(pairs, padding=True, truncation=True, return_tensors='pt')

model.eval()
with torch.no_grad():
    scores = model(**features).logits
print(scores)

Reproduction

  1. Use the provided React code to load the model and tokenizer.
  2. Attempt to tokenize a nested array as shown in the code snippet.
  3. Observe the encountered error.

Code Snippet

useEffect(() => {
    const classifySequence = async () => {
        const modelName = "Oblix/crossencoder-camembert-base-mmarcoFR_ONNX";
        const model = await AutoModelForSequenceClassification.from_pretrained(modelName);
        const tokenizer = await AutoTokenizer.from_pretrained(modelName);
        const pairs = [
            ["Quelle est la capitale de la France?", "La capitale de la France est Paris"]
        ];
        try {
            const input = await tokenizer(pairs, {
                padding: true,
                truncation: true
            });
            const output = await model(input);
            console.log(output);
        } catch (error) {
            console.error("Error:", error);
        }
    };

    classifySequence();
}, []);

Error
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions