Buckets:

|
download
raw
15.2 kB

models

Definitions of all models available in Transformers.js.

Example: Load and run an AutoModel.

import { AutoModel, AutoTokenizer } from '@huggingface/transformers';

const tokenizer = await AutoTokenizer.from_pretrained('Xenova/bert-base-uncased');
const model = await AutoModel.from_pretrained('Xenova/bert-base-uncased');

const inputs = await tokenizer('I love transformers!');
const { logits } = await model(inputs);
// Tensor {
//     data: Float32Array(183132) [-7.117443084716797, -7.107812881469727, -7.092104911804199, ...]
//     dims: (3) [1, 6, 30522],
//     type: "float32",
//     size: 183132,
// }

We also provide other AutoModels (listed below), which you can use in the same way as the Python library. For example:

Example: Load and run an AutoModelForSeq2SeqLM.

import { AutoModelForSeq2SeqLM, AutoTokenizer } from '@huggingface/transformers';

const tokenizer = await AutoTokenizer.from_pretrained('Xenova/t5-small');
const model = await AutoModelForSeq2SeqLM.from_pretrained('Xenova/t5-small');

const { input_ids } = await tokenizer('translate English to German: I love transformers!');
const outputs = await model.generate(input_ids);
const decoded = tokenizer.decode(outputs[0], { skip_special_tokens: true });
// 'Ich liebe Transformatoren!'

models.AutoModel

Helper class which is used to instantiate pretrained models with the from_pretrained function. The chosen model class is determined by the type specified in the model config.

Kind: static class of models


new AutoModel()

Example

const model = await AutoModel.from_pretrained('Xenova/bert-base-uncased');

autoModel.MODEL_CLASS_MAPPINGS : Array.<Map>

Kind: instance property of AutoModel


models.AutoModelForSequenceClassification

Helper class which is used to instantiate pretrained sequence classification models with the from_pretrained function. The chosen model class is determined by the type specified in the model config.

Kind: static class of models


new AutoModelForSequenceClassification()

Example

const model = await AutoModelForSequenceClassification.from_pretrained('Xenova/distilbert-base-uncased-finetuned-sst-2-english');

models.AutoModelForTokenClassification

Helper class which is used to instantiate pretrained token classification models with the from_pretrained function. The chosen model class is determined by the type specified in the model config.

Kind: static class of models


new AutoModelForTokenClassification()

Example

const model = await AutoModelForTokenClassification.from_pretrained('Xenova/distilbert-base-multilingual-cased-ner-hrl');

models.AutoModelForSeq2SeqLM

Helper class which is used to instantiate pretrained sequence-to-sequence models with the from_pretrained function. The chosen model class is determined by the type specified in the model config.

Kind: static class of models


new AutoModelForSeq2SeqLM()

Example

const model = await AutoModelForSeq2SeqLM.from_pretrained('Xenova/t5-small');

models.AutoModelForSpeechSeq2Seq

Helper class which is used to instantiate pretrained sequence-to-sequence speech-to-text models with the from_pretrained function. The chosen model class is determined by the type specified in the model config.

Kind: static class of models


new AutoModelForSpeechSeq2Seq()

Example

const model = await AutoModelForSpeechSeq2Seq.from_pretrained('openai/whisper-tiny.en');

models.AutoModelForTextToSpectrogram

Helper class which is used to instantiate pretrained sequence-to-sequence text-to-spectrogram models with the from_pretrained function. The chosen model class is determined by the type specified in the model config.

Kind: static class of models


new AutoModelForTextToSpectrogram()

Example

const model = await AutoModelForTextToSpectrogram.from_pretrained('microsoft/speecht5_tts');

models.AutoModelForTextToWaveform

Helper class which is used to instantiate pretrained text-to-waveform models with the from_pretrained function. The chosen model class is determined by the type specified in the model config.

Kind: static class of models


new AutoModelForTextToWaveform()

Example

const model = await AutoModelForTextToSpectrogram.from_pretrained('facebook/mms-tts-eng');

models.AutoModelForCausalLM

Helper class which is used to instantiate pretrained causal language models with the from_pretrained function. The chosen model class is determined by the type specified in the model config.

Kind: static class of models


new AutoModelForCausalLM()

Example

const model = await AutoModelForCausalLM.from_pretrained('Xenova/gpt2');

models.AutoModelForMaskedLM

Helper class which is used to instantiate pretrained masked language models with the from_pretrained function. The chosen model class is determined by the type specified in the model config.

Kind: static class of models


new AutoModelForMaskedLM()

Example

const model = await AutoModelForMaskedLM.from_pretrained('Xenova/bert-base-uncased');

models.AutoModelForQuestionAnswering

Helper class which is used to instantiate pretrained question answering models with the from_pretrained function. The chosen model class is determined by the type specified in the model config.

Kind: static class of models


new AutoModelForQuestionAnswering()

Example

const model = await AutoModelForQuestionAnswering.from_pretrained('Xenova/distilbert-base-cased-distilled-squad');

models.AutoModelForVision2Seq

Helper class which is used to instantiate pretrained vision-to-sequence models with the from_pretrained function. The chosen model class is determined by the type specified in the model config.

Kind: static class of models


new AutoModelForVision2Seq()

Example

const model = await AutoModelForVision2Seq.from_pretrained('Xenova/vit-gpt2-image-captioning');

models.AutoModelForImageClassification

Helper class which is used to instantiate pretrained image classification models with the from_pretrained function. The chosen model class is determined by the type specified in the model config.

Kind: static class of models


new AutoModelForImageClassification()

Example

const model = await AutoModelForImageClassification.from_pretrained('Xenova/vit-base-patch16-224');

models.AutoModelForImageSegmentation

Helper class which is used to instantiate pretrained image segmentation models with the from_pretrained function. The chosen model class is determined by the type specified in the model config.

Kind: static class of models


new AutoModelForImageSegmentation()

Example

const model = await AutoModelForImageSegmentation.from_pretrained('Xenova/detr-resnet-50-panoptic');

models.AutoModelForSemanticSegmentation

Helper class which is used to instantiate pretrained image segmentation models with the from_pretrained function. The chosen model class is determined by the type specified in the model config.

Kind: static class of models


new AutoModelForSemanticSegmentation()

Example

const model = await AutoModelForSemanticSegmentation.from_pretrained('nvidia/segformer-b3-finetuned-cityscapes-1024-1024');

models.AutoModelForUniversalSegmentation

Helper class which is used to instantiate pretrained universal image segmentation models with the from_pretrained function. The chosen model class is determined by the type specified in the model config.

Kind: static class of models


new AutoModelForUniversalSegmentation()

Example

const model = await AutoModelForUniversalSegmentation.from_pretrained('hf-internal-testing/tiny-random-MaskFormerForInstanceSegmentation');

models.AutoModelForObjectDetection

Helper class which is used to instantiate pretrained object detection models with the from_pretrained function. The chosen model class is determined by the type specified in the model config.

Kind: static class of models


new AutoModelForObjectDetection()

Example

const model = await AutoModelForObjectDetection.from_pretrained('Xenova/detr-resnet-50');

models.AutoModelForMaskGeneration

Helper class which is used to instantiate pretrained mask generation models with the from_pretrained function. The chosen model class is determined by the type specified in the model config.

Kind: static class of models


new AutoModelForMaskGeneration()

Example

const model = await AutoModelForMaskGeneration.from_pretrained('Xenova/sam-vit-base');

models~PretrainedMixin

Base class of all AutoModels. Contains the from_pretrained function which is used to instantiate pretrained models.

Kind: inner class of models


pretrainedMixin.MODEL_CLASS_MAPPINGS : Array.<Map>

Mapping from model type to model class.

Kind: instance property of PretrainedMixin


pretrainedMixin.BASE_IF_FAIL

Whether to attempt to instantiate the base class (PretrainedModel) if the model type is not found in the mapping.

Kind: instance property of PretrainedMixin


PretrainedMixin.supports(model_type) ⇒ boolean

Check whether this AutoModel class supports a given model type.

Kind: static method of PretrainedMixin
Returns: boolean - Whether this class can handle the given model type.

  ParamTypeDescription




model_typestringThe model type from config (e.g., &#39;bert&#39;, &#39;whisper&#39;).

  

PretrainedMixin.from_pretrained() : Object.from_pretrained

Kind: static method of PretrainedMixin


Xet Storage Details

Size:
15.2 kB
·
Xet hash:
40088f4ff6e31205838169681edb4e9224cd09ddb1e74fc3544f83b431f239c0

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.