Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown model class "nomic_bert", attempting to construct from base class. #562

Closed
1 of 5 tasks
jimlloyd opened this issue Feb 4, 2024 · 2 comments
Closed
1 of 5 tasks
Labels
bug Something isn't working

Comments

@jimlloyd
Copy link

jimlloyd commented Feb 4, 2024

System Info

I am trying to load Xenova/nomic-embed-text-v1. It fails with an error and asks that I report the error here.
I am running this on an M2 MacBook Pro running Sonoma 14.2.1 using node.js v21.5:
I downloaded the model with huggingface-cli download Xenova/nomic-embed-text-v1 before running the script.

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

Unknown model class "nomic_bert", attempting to construct from base class.
Model type for 'undefined' not found, assuming encoder-only architecture. 

Full error below.

Reproduction

Run the attached script by doing node test.js. The content of test.js is:

import { Pipeline, AutoTokenizer, AutoModel } from "@xenova/transformers";

// Load tokenizer and model
const tokenizer = await AutoTokenizer.from_pretrained("Xenova/nomic-embed-text-v1");
const model = await AutoModel.from_pretrained("Xenova/nomic-embed-text-v1");

// Prepare text for embedding
const texts = "Your text here";
const inputs = tokenizer.encode(texts);

// Generate embeddings
const pipeline = new Pipeline({ model, tokenizer });
const outputs = pipeline(inputs);
console.log(outputs);

The error I get is:

% node test.js 
Unknown model class "nomic_bert", attempting to construct from base class.
Model type for 'undefined' not found, assuming encoder-only architecture. Please report this at https://github.com/xenova/transformers.js/issues/new/choose.
file:///Users/jim.lloyd/nomic/node_modules/@xenova/transformers/src/utils/core.js:75
        throw Error('Must implement _call method in subclass')
              ^

Error: Must implement _call method in subclass
    at Function._call (file:///Users/jim.lloyd/nomic/node_modules/@xenova/transformers/src/utils/core.js:75:15)
    at closure (file:///Users/jim.lloyd/nomic/node_modules/@xenova/transformers/src/utils/core.js:62:28)
    at file:///Users/jim.lloyd/nomic/test.js:13:17
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v21.5.0
@jimlloyd jimlloyd added the bug Something isn't working label Feb 4, 2024
@jimlloyd
Copy link
Author

jimlloyd commented Feb 4, 2024

Looking through other issues I saw this: oven-sh/bun#7877, which seemed like it might be related. In that issue @sroussey found a fix which me made available in the package @sroussey/transformers. Switching to that package did NOT fix my error here.

@jimlloyd
Copy link
Author

jimlloyd commented Feb 4, 2024

My bad. I somehow was not using the recommended script for transformers.js on the model card. After switching to the recommended script the pipeline works. That script is:

import { pipeline } from '@xenova/transformers';

// Create a feature extraction pipeline
const extractor = await pipeline('feature-extraction', 'nomic-ai/nomic-embed-text-v1', {
    quantized: false, // Comment out this line to use the quantized version
});

// Compute sentence embeddings
const texts = ['What is TSNE?', 'Who is Laurens van der Maaten?'];
const embeddings = await extractor(texts, { pooling: 'mean', normalize: true });
console.log(embeddings);

@jimlloyd jimlloyd closed this as completed Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant