huggingface / 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
12.18k stars 771 forks source link

Using AutoModel, AutoTokenizer with distilbert models #785

Open mram0509 opened 5 months ago

mram0509 commented 5 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 5 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.