xenova / transformers.js

State-of-the-art Machine Learning for the web. Run 🤗 Transformers directly in your browser, with no need for a server!
https://huggingface.co/docs/transformers.js
Apache License 2.0
11.04k stars 678 forks source link

Using AutoModel, AutoTokenizer with distilbert models #785

Open MayuraRam opened 4 months ago

MayuraRam commented 4 months ago

Question

Does transformers.js have a function to get the label after getting the logits? How to get the labels from the inference output?

let tokenizer = await AutoTokenizer.from_pretrained('distilbert-base-uncased-finetuned-sst-2-english'); let model = await AutoModel.from_pretrained('distilbert-base-uncased-finetuned-sst-2-english');

let inputs = await tokenizer('I love transformers!'); let { logits } = await model(inputs);

xenova commented 4 months ago

You can use model.config.id2label or model.config.label2id. Also, note that you need to update your model id to: Xenova/distilbert-base-uncased-finetuned-sst-2-english which is a version of the model that contains transformers.js-compatible ONNX weights.