Transformers.js 文档
模型
并获得增强的文档体验
开始使用
模型
Transformers.js 中所有可用模型的定义。
示例: 加载并运行 AutoModel
。
import { AutoModel, AutoTokenizer } from '@huggingface/transformers';
let tokenizer = await AutoTokenizer.from_pretrained('Xenova/bert-base-uncased');
let model = await AutoModel.from_pretrained('Xenova/bert-base-uncased');
let inputs = await tokenizer('I love transformers!');
let { logits } = await model(inputs);
// Tensor {
// data: Float32Array(183132) [-7.117443084716797, -7.107812881469727, -7.092104911804199, ...]
// dims: (3) [1, 6, 30522],
// type: "float32",
// size: 183132,
// }
我们还提供了其他 AutoModel
(如下所列),您可以像在 Python 库中一样使用它们。例如
示例: 加载并运行 AutoModelForSeq2SeqLM
。
import { AutoModelForSeq2SeqLM, AutoTokenizer } from '@huggingface/transformers';
let tokenizer = await AutoTokenizer.from_pretrained('Xenova/t5-small');
let model = await AutoModelForSeq2SeqLM.from_pretrained('Xenova/t5-small');
let { input_ids } = await tokenizer('translate English to German: I love transformers!');
let outputs = await model.generate(input_ids);
let decoded = tokenizer.decode(outputs[0], { skip_special_tokens: true });
// 'Ich liebe Transformatoren!'
- 模型
- static
- .PreTrainedModel
new PreTrainedModel(config, sessions, configs)
- instance
.custom_config
:*
.generation_config
⇒GenerationConfig
|null
.dispose()
⇒Promise.<Array<unknown>>
._call(model_inputs)
⇒Promise.<Object>
.forward(model_inputs)
⇒Promise.<Object>
._get_logits_warper(generation_config)
⇒LogitsProcessorList
._prepare_generation_config(generation_config, kwargs)
⇒GenerationConfig
._get_stopping_criteria(generation_config, [stopping_criteria])
._validate_model_class()
._update_model_kwargs_for_generation(inputs)
⇒Object
._prepare_model_inputs(params)
⇒Object
._prepare_decoder_input_ids_for_generation(param0)
.generate(options)
⇒Promise.<(ModelOutput|Tensor)>
.getPastKeyValues(decoderResults, pastKeyValues)
⇒Object
.getAttentions(model_output)
⇒*
.addPastKeyValues(decoderFeeds, pastKeyValues)
- static
.from_pretrained(pretrained_model_name_or_path, options)
⇒Promise.<PreTrainedModel>
- .BaseModelOutput
- .BertForMaskedLM
._call(model_inputs)
⇒Promise.<MaskedLMOutput>
- .BertForSequenceClassification
._call(model_inputs)
⇒Promise.<SequenceClassifierOutput>
- .BertForTokenClassification
._call(model_inputs)
⇒Promise.<TokenClassifierOutput>
- .BertForQuestionAnswering
._call(model_inputs)
⇒Promise.<QuestionAnsweringModelOutput>
- .RoFormerModel
- .RoFormerForMaskedLM
._call(model_inputs)
⇒Promise.<MaskedLMOutput>
- .RoFormerForSequenceClassification
._call(model_inputs)
⇒Promise.<SequenceClassifierOutput>
- .RoFormerForTokenClassification
._call(model_inputs)
⇒Promise.<TokenClassifierOutput>
- .RoFormerForQuestionAnswering
._call(model_inputs)
⇒Promise.<QuestionAnsweringModelOutput>
- .ConvBertModel
- .ConvBertForMaskedLM
._call(model_inputs)
⇒Promise.<MaskedLMOutput>
- .ConvBertForSequenceClassification
._call(model_inputs)
⇒Promise.<SequenceClassifierOutput>
- .ConvBertForTokenClassification
._call(model_inputs)
⇒Promise.<TokenClassifierOutput>
- .ConvBertForQuestionAnswering
._call(model_inputs)
⇒Promise.<QuestionAnsweringModelOutput>
- .ElectraModel
- .ElectraForMaskedLM
._call(model_inputs)
⇒Promise.<MaskedLMOutput>
- .ElectraForSequenceClassification
._call(model_inputs)
⇒Promise.<SequenceClassifierOutput>
- .ElectraForTokenClassification
._call(model_inputs)
⇒Promise.<TokenClassifierOutput>
- .ElectraForQuestionAnswering
._call(model_inputs)
⇒Promise.<QuestionAnsweringModelOutput>
- .CamembertModel
- .CamembertForMaskedLM
._call(model_inputs)
⇒Promise.<MaskedLMOutput>
- .CamembertForSequenceClassification
._call(model_inputs)
⇒Promise.<SequenceClassifierOutput>
- .CamembertForTokenClassification
._call(model_inputs)
⇒Promise.<TokenClassifierOutput>
- .CamembertForQuestionAnswering
._call(model_inputs)
⇒Promise.<QuestionAnsweringModelOutput>
- .DebertaModel
- .DebertaForMaskedLM
._call(model_inputs)
⇒Promise.<MaskedLMOutput>
- .DebertaForSequenceClassification
._call(model_inputs)
⇒Promise.<SequenceClassifierOutput>
- .DebertaForTokenClassification
._call(model_inputs)
⇒Promise.<TokenClassifierOutput>
- .DebertaForQuestionAnswering
._call(model_inputs)
⇒Promise.<QuestionAnsweringModelOutput>
- .DebertaV2Model
- .DebertaV2ForMaskedLM
._call(model_inputs)
⇒Promise.<MaskedLMOutput>
- .DebertaV2ForSequenceClassification
._call(model_inputs)
⇒Promise.<SequenceClassifierOutput>
- .DebertaV2ForTokenClassification
._call(model_inputs)
⇒Promise.<TokenClassifierOutput>
- .DebertaV2ForQuestionAnswering
._call(model_inputs)
⇒Promise.<QuestionAnsweringModelOutput>
- .DistilBertForSequenceClassification
._call(model_inputs)
⇒Promise.<SequenceClassifierOutput>
- .DistilBertForTokenClassification
._call(model_inputs)
⇒Promise.<TokenClassifierOutput>
- .DistilBertForQuestionAnswering
._call(model_inputs)
⇒Promise.<QuestionAnsweringModelOutput>
- .DistilBertForMaskedLM
._call(model_inputs)
⇒Promise.<MaskedLMOutput>
- .EsmModel
- .EsmForMaskedLM
._call(model_inputs)
⇒Promise.<MaskedLMOutput>
- .EsmForSequenceClassification
._call(model_inputs)
⇒Promise.<SequenceClassifierOutput>
- .EsmForTokenClassification
._call(model_inputs)
⇒Promise.<TokenClassifierOutput>
- .MobileBertForMaskedLM
._call(model_inputs)
⇒Promise.<MaskedLMOutput>
- .MobileBertForSequenceClassification
._call(model_inputs)
⇒Promise.<SequenceClassifierOutput>
- .MobileBertForQuestionAnswering
._call(model_inputs)
⇒Promise.<QuestionAnsweringModelOutput>
- .MPNetModel
- .MPNetForMaskedLM
._call(model_inputs)
⇒Promise.<MaskedLMOutput>
- .MPNetForSequenceClassification
._call(model_inputs)
⇒Promise.<SequenceClassifierOutput>
- .MPNetForTokenClassification
._call(model_inputs)
⇒Promise.<TokenClassifierOutput>
- .MPNetForQuestionAnswering
._call(model_inputs)
⇒Promise.<QuestionAnsweringModelOutput>
- .T5ForConditionalGeneration
- .LongT5PreTrainedModel
- .LongT5Model
- .LongT5ForConditionalGeneration
- .MT5ForConditionalGeneration
- .BartModel
- .BartForConditionalGeneration
- .BartForSequenceClassification
._call(model_inputs)
⇒Promise.<SequenceClassifierOutput>
- .MBartModel
- .MBartForConditionalGeneration
- .MBartForSequenceClassification
._call(model_inputs)
⇒Promise.<SequenceClassifierOutput>
- .BlenderbotModel
- .BlenderbotForConditionalGeneration
- .BlenderbotSmallModel
- .BlenderbotSmallForConditionalGeneration
- .RobertaForMaskedLM
._call(model_inputs)
⇒Promise.<MaskedLMOutput>
- .RobertaForSequenceClassification
._call(model_inputs)
⇒Promise.<SequenceClassifierOutput>
- .RobertaForTokenClassification
._call(model_inputs)
⇒Promise.<TokenClassifierOutput>
- .RobertaForQuestionAnswering
._call(model_inputs)
⇒Promise.<QuestionAnsweringModelOutput>
- .XLMPreTrainedModel
- .XLMModel
- .XLMWithLMHeadModel
._call(model_inputs)
⇒Promise.<MaskedLMOutput>
- .XLMForSequenceClassification
._call(model_inputs)
⇒Promise.<SequenceClassifierOutput>
- .XLMForTokenClassification
._call(model_inputs)
⇒Promise.<TokenClassifierOutput>
- .XLMForQuestionAnswering
._call(model_inputs)
⇒Promise.<QuestionAnsweringModelOutput>
- .XLMRobertaForMaskedLM
._call(model_inputs)
⇒Promise.<MaskedLMOutput>
- .XLMRobertaForSequenceClassification
._call(model_inputs)
⇒Promise.<SequenceClassifierOutput>
- .XLMRobertaForTokenClassification
._call(model_inputs)
⇒Promise.<TokenClassifierOutput>
- .XLMRobertaForQuestionAnswering
._call(model_inputs)
⇒Promise.<QuestionAnsweringModelOutput>
- .ASTModel
- .ASTForAudioClassification
- .WhisperModel
- .WhisperForConditionalGeneration
- .MoonshineModel
- .VisionEncoderDecoderModel
- .LlavaForConditionalGeneration
- .Idefics3ForConditionalGeneration
- .SmolVLMForConditionalGeneration
- .CLIPModel
- .CLIPTextModel
- .CLIPTextModelWithProjection
- .CLIPVisionModel
- .CLIPVisionModelWithProjection
- .SiglipModel
- .SiglipTextModel
- .SiglipVisionModel
- .CLIPSegForImageSegmentation
- .GPT2LMHeadModel
- .JAISModel
- .JAISLMHeadModel
- .CodeGenModel
- .CodeGenForCausalLM
- .LlamaPreTrainedModel
- .LlamaModel
- .CoherePreTrainedModel
- .GemmaPreTrainedModel
- .GemmaModel
- .Gemma2PreTrainedModel
- .Gemma2Model
- .Gemma3PreTrainedModel
- .Gemma3Model
- .Qwen2PreTrainedModel
- .Qwen2Model
- .PhiModel
- .Phi3Model
- .BloomPreTrainedModel
- .BloomModel
- .BloomForCausalLM
- .MptModel
- .MptForCausalLM
- .OPTModel
- .OPTForCausalLM
- .VitPoseForPoseEstimation
- .VitMatteForImageMatting
- .DetrObjectDetectionOutput
- .DetrSegmentationOutput
- .RTDetrObjectDetectionOutput
- .TableTransformerModel
- .TableTransformerForObjectDetection
- .ResNetPreTrainedModel
- .ResNetModel
- .ResNetForImageClassification
- .Swin2SRModel
- .Swin2SRForImageSuperResolution
- .DPTModel
- .DPTForDepthEstimation
- .DepthAnythingForDepthEstimation
- .GLPNModel
- .GLPNForDepthEstimation
- .DonutSwinModel
- .ConvNextModel
- .ConvNextForImageClassification
- .ConvNextV2Model
- .ConvNextV2ForImageClassification
- .Dinov2Model
- .Dinov2ForImageClassification
- .Dinov2WithRegistersModel
- .Dinov2WithRegistersForImageClassification
- .YolosObjectDetectionOutput
- .SamModel
.get_image_embeddings(model_inputs)
⇒Promise.<{image_embeddings: Tensor, image_positional_embeddings: Tensor}>
.forward(model_inputs)
⇒Promise.<Object>
._call(model_inputs)
⇒Promise.<SamImageSegmentationOutput>
- .SamImageSegmentationOutput
- .Wav2Vec2Model
- .Wav2Vec2ForAudioFrameClassification
._call(model_inputs)
⇒Promise.<TokenClassifierOutput>
- .PyAnnoteModel
- .PyAnnoteForAudioFrameClassification
._call(model_inputs)
⇒Promise.<TokenClassifierOutput>
- .UniSpeechModel
- .UniSpeechForCTC
- .UniSpeechForSequenceClassification
._call(model_inputs)
⇒Promise.<SequenceClassifierOutput>
- .UniSpeechSatModel
- .UniSpeechSatForCTC
- .UniSpeechSatForSequenceClassification
._call(model_inputs)
⇒Promise.<SequenceClassifierOutput>
- .UniSpeechSatForAudioFrameClassification
._call(model_inputs)
⇒Promise.<TokenClassifierOutput>
- .Wav2Vec2BertModel
- .Wav2Vec2BertForCTC
- .Wav2Vec2BertForSequenceClassification
._call(model_inputs)
⇒Promise.<SequenceClassifierOutput>
- .HubertModel
- .HubertForCTC
- .HubertForSequenceClassification
._call(model_inputs)
⇒Promise.<SequenceClassifierOutput>
- .WavLMPreTrainedModel
- .WavLMModel
- .WavLMForCTC
- .WavLMForSequenceClassification
._call(model_inputs)
⇒Promise.<SequenceClassifierOutput>
- .WavLMForXVector
._call(model_inputs)
⇒Promise.<XVectorOutput>
- .WavLMForAudioFrameClassification
._call(model_inputs)
⇒Promise.<TokenClassifierOutput>
- .SpeechT5PreTrainedModel
- .SpeechT5Model
- .SpeechT5ForSpeechToText
- .SpeechT5ForTextToSpeech
.generate_speech(input_values, speaker_embeddings, options)
⇒Promise.<SpeechOutput>
- .SpeechT5HifiGan
- .TrOCRForCausalLM
- .MistralPreTrainedModel
- .Starcoder2PreTrainedModel
- .FalconPreTrainedModel
- .ClapTextModelWithProjection
- .ClapAudioModelWithProjection
- .VitsModel
._call(model_inputs)
⇒Promise.<VitsModelOutput>
- .SegformerModel
- .SegformerForImageClassification
- .SegformerForSemanticSegmentation
- .StableLmModel
- .StableLmForCausalLM
- .EfficientNetModel
- .EfficientNetForImageClassification
- .MusicgenModel
- .MusicgenForCausalLM
- .MusicgenForConditionalGeneration
._apply_and_filter_by_delay_pattern_mask(outputs)
⇒Tensor
.generate(options)
⇒Promise.<(ModelOutput|Tensor)>
- .MobileNetV1Model
- .MobileNetV1ForImageClassification
- .MobileNetV2Model
- .MobileNetV2ForImageClassification
- .MobileNetV3Model
- .MobileNetV3ForImageClassification
- .MobileNetV4Model
- .MobileNetV4ForImageClassification
- .DecisionTransformerModel
- .MultiModalityCausalLM
- .MgpstrForSceneTextRecognition
- .PatchTSTModel
- .PatchTSTForPrediction
- .PatchTSMixerModel
- .PatchTSMixerForPrediction
- .MimiEncoderOutput
- .MimiDecoderOutput
- .MimiModel
.encode(inputs)
⇒Promise.<MimiEncoderOutput>
.decode(inputs)
⇒Promise.<MimiDecoderOutput>
- .DacEncoderOutput
- .DacDecoderOutput
- .DacModel
.encode(inputs)
⇒Promise.<DacEncoderOutput>
.decode(inputs)
⇒Promise.<DacDecoderOutput>
- .SnacModel
.encode(inputs)
⇒Promise.<Record<string, Tensor>>
.decode(inputs)
⇒Promise.<{audio_values: Tensor}>
- .PretrainedMixin
- instance
- static
- .AutoModel
- .AutoModelForSequenceClassification
- .AutoModelForTokenClassification
- .AutoModelForSeq2SeqLM
- .AutoModelForSpeechSeq2Seq
- .AutoModelForTextToSpectrogram
- .AutoModelForTextToWaveform
- .AutoModelForCausalLM
- .AutoModelForMaskedLM
- .AutoModelForQuestionAnswering
- .AutoModelForVision2Seq
- .AutoModelForImageClassification
- .AutoModelForImageSegmentation
- .AutoModelForSemanticSegmentation
- .AutoModelForUniversalSegmentation
- .AutoModelForObjectDetection
- .AutoModelForMaskGeneration
- .Seq2SeqLMOutput
- .SequenceClassifierOutput
- .XVectorOutput
- .TokenClassifierOutput
- .MaskedLMOutput
- .QuestionAnsweringModelOutput
- .CausalLMOutput
- .CausalLMOutputWithPast
- .ImageMattingOutput
- .VitsModelOutput
- .PreTrainedModel
- inner
~cumsum_masked_fill(attention_mask)
⇒Object
~createPositionIds()
~SamModelInputs
:Object
~SpeechOutput
:Object
- static
models.PreTrainedModel
预训练模型的基础类,提供模型配置和 ONNX 会话。
Kind: models
的静态类 models
- .PreTrainedModel
new PreTrainedModel(config, sessions, configs)
- instance
.custom_config
:*
.generation_config
⇒GenerationConfig
|null
.dispose()
⇒Promise.<Array<unknown>>
._call(model_inputs)
⇒Promise.<Object>
.forward(model_inputs)
⇒Promise.<Object>
._get_logits_warper(generation_config)
⇒LogitsProcessorList
._prepare_generation_config(generation_config, kwargs)
⇒GenerationConfig
._get_stopping_criteria(generation_config, [stopping_criteria])
._validate_model_class()
._update_model_kwargs_for_generation(inputs)
⇒Object
._prepare_model_inputs(params)
⇒Object
._prepare_decoder_input_ids_for_generation(param0)
.generate(options)
⇒Promise.<(ModelOutput|Tensor)>
.getPastKeyValues(decoderResults, pastKeyValues)
⇒Object
.getAttentions(model_output)
⇒*
.addPastKeyValues(decoderFeeds, pastKeyValues)
- static
.from_pretrained(pretrained_model_name_or_path, options)
⇒Promise.<PreTrainedModel>
new PreTrainedModel(config, sessions, configs)
创建 PreTrainedModel
类的新实例。
参数 | 类型 | 描述 |
---|---|---|
config | * | 模型配置。 |
sessions | Record.<string, any> | 模型的推理会话。 |
configs | Record.<string, Object> | 其他配置文件(例如,generation_config.json)。 |
preTrainedModel.custom_config : <code> * </code>
Kind: PreTrainedModel
的实例属性
preTrainedModel.generation_config ⇒ <code> GenerationConfig </code> | <code> null </code>
获取模型的生成配置(如果存在)。
Kind: PreTrainedModel
的实例属性
Returns: GenerationConfig
| null
- 模型的生成配置(如果存在),否则为 null
。
preTrainedModel.dispose() ⇒ <code> Promise. < Array < unknown > > </code>
处置推理期间创建的所有 ONNX 会话。
Kind: PreTrainedModel
的实例方法
Returns: Promise.<Array<unknown>>
- Promise 数组,每个 Promise 对应一个正在处置的 ONNX 会话。
待办事项
preTrainedModel._call(model_inputs) ⇒ <code> Promise. < Object > </code>
使用提供的输入运行模型
Kind: PreTrainedModel
的实例方法
返回值: Promise.<Object>
- 包含输出张量的对象
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 包含输入张量的对象 |
preTrainedModel.forward(model_inputs) ⇒ <code> Promise. < Object > </code>
预训练模型的前向方法。如果子类没有重写,将根据模型类型选择正确的前向方法。
Kind: PreTrainedModel
的实例方法
返回值: Promise.<Object>
- 来自模型的输出数据,格式在 ONNX 模型中指定。
抛出:
Error
此方法必须在子类中实现。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入数据,格式在 ONNX 模型中指定。 |
preTrainedModel._get_logits_warper(generation_config) ⇒ <code> LogitsProcessorList </code>
此函数返回一个 [LogitsProcessorList
] 列表对象,其中包含用于多项式采样的所有相关 [LogitsWarper
] 实例。
Kind: PreTrainedModel
的实例方法
返回值: LogitsProcessorList
- generation_config
参数 | 类型 | 描述 |
---|---|---|
generation_config | GenerationConfig | 生成配置。 |
preTrainedModel._prepare_generation_config(generation_config, kwargs) ⇒ <code> GenerationConfig </code>
此函数将多个生成配置合并在一起,形成模型用于文本生成的最终生成配置。它首先创建一个空的 GenerationConfig
对象,然后将模型自身的 generation_config
属性应用于它。最后,如果在参数中传入了 generation_config
对象,它将使用传入的配置对象中的相应属性覆盖最终配置中的属性。
Kind: PreTrainedModel
的实例方法
返回值: GenerationConfig
- 模型用于文本生成的最终生成配置对象。
参数 | 类型 | 描述 |
---|---|---|
generation_config | GenerationConfig | null | 包含生成参数的 |
kwargs | Object(对象) | 要代替 |
preTrainedModel._get_stopping_criteria(generation_config, [stopping_criteria])
Kind: PreTrainedModel
的实例方法
参数 | 类型 | 默认值 |
---|---|---|
generation_config | GenerationConfig | |
[stopping_criteria](停止标准) | StoppingCriteriaList |
|
preTrainedModel._validate_model_class()
确认模型类与生成兼容。如果不兼容,则引发异常,指向要使用的正确类。
Kind: PreTrainedModel
的实例方法
preTrainedModel._update_model_kwargs_for_generation(inputs) ⇒ <code> Object </code>
Kind: PreTrainedModel
的实例方法
返回值: Object
- 下一代迭代的更新模型输入。
参数 | 类型 |
---|---|
inputs(输入) | Object(对象) |
inputs.generated_input_ids | Array.<Array<bigint>> |
inputs.outputs(输出) | Object(对象) |
inputs.model_inputs | Object(对象) |
inputs.is_encoder_decoder | boolean(布尔值) |
preTrainedModel._prepare_model_inputs(params) ⇒ <code> Object </code>
此函数提取用于生成的特定于模型的 inputs
。
Kind: PreTrainedModel
的实例方法
返回值: Object
- 用于生成的特定于模型的输入。
参数 | 类型 | 默认值 |
---|---|---|
params(参数) | Object(对象) | |
[params.inputs] | Tensor |
|
[params.bos_token_id] | number(数字) |
|
[params.model_kwargs] | Record.<string, (Tensor|Array<number>)> |
preTrainedModel._prepare_decoder_input_ids_for_generation(param0)
为编码器-解码器模型准备用于生成的 decoder_input_ids
Kind: PreTrainedModel
的实例方法
参数 | 类型 |
---|---|
param0 | * |
preTrainedModel.generate(options) ⇒ <code> Promise. < (ModelOutput|Tensor) > </code>
为带有语言建模头的模型生成 token id 序列。
Kind: PreTrainedModel
的实例方法
返回值: Promise.<(ModelOutput|Tensor)>
- 模型的输出,可以包含生成的 token id、attention 和 scores。
参数 | 类型 |
---|---|
options(选项) | * |
preTrainedModel.getPastKeyValues(decoderResults, pastKeyValues) ⇒ <code> Object </code>
返回一个对象,其中包含给定解码器结果对象中的 past key values。
Kind: PreTrainedModel
的实例方法
返回值: Object
- 包含 past key values 的对象。
参数 | 类型 | 描述 |
---|---|---|
decoderResults(解码器结果) | Object(对象) | 解码器结果对象。 |
pastKeyValues(过去的键值) | Object(对象) | 先前的 past key values。 |
preTrainedModel.getAttentions(model_output) ⇒ <code> * </code>
返回一个对象,其中包含给定模型输出对象中的 attention。
Kind: PreTrainedModel
的实例方法
返回值: *
- 包含 attention 的对象。
参数 | 类型 | 描述 |
---|---|---|
model_output(模型输出) | Object(对象) | 模型的输出。 |
preTrainedModel.addPastKeyValues(decoderFeeds, pastKeyValues)
将 past key values 添加到解码器 feeds 对象。如果 pastKeyValues 为 null,则为 past key values 创建新张量。
Kind: PreTrainedModel
的实例方法
参数 | 类型 | 描述 |
---|---|---|
decoderFeeds(解码器 Feeds) | Object(对象) | 要将 past key values 添加到的解码器 feeds 对象。 |
pastKeyValues(过去的键值) | Object(对象) | 一个包含 past key values 的对象。 |
PreTrainedModel.from_pretrained(pretrained_model_name_or_path, options) ⇒ <code> Promise. < PreTrainedModel > </code>
从预训练模型实例化库的模型类之一。
要实例化的模型类是根据配置对象的 model_type
属性选择的(可以作为参数传递,也可以从 pretrained_model_name_or_path
加载,如果可能)
类型: PreTrainedModel
的静态方法
返回值: Promise.<PreTrainedModel>
- PreTrainedModel
类的新实例。
参数 | 类型 | 描述 |
---|---|---|
pretrained_model_name_or_path(预训练模型名称或路径) | string(字符串) | 预训练模型的名称或路径。可以是
|
options(选项) | * | 用于加载模型的其他选项。 |
models.BaseModelOutput
模型输出的基类,具有潜在的 hidden states 和 attentions。
Kind: models
的静态类 models
new BaseModelOutput(output)
参数 | 类型 | 描述 |
---|---|---|
output(输出) | Object(对象) | 模型的输出。 |
output.last_hidden_state | Tensor | 模型最后一层输出的 hidden-states 序列。 |
[output.hidden_states] | Tensor | 模型在每一层输出的 Hidden-states 加上可选的初始 embedding 输出。 |
[output.attentions] | Tensor | attention softmax 之后的 attentions 权重,用于计算 self-attention 头中的加权平均值。 |
models.BertForMaskedLM
BertForMaskedLM 是一个类,表示用于 masked language modeling 的 BERT 模型。
Kind: models
的静态类 models
bertForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
类型: BertForMaskedLM
的实例方法
返回值: Promise.<MaskedLMOutput>
- 一个对象,其中包含用于 masked language modeling 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.BertForSequenceClassification
BertForSequenceClassification 是一个类,表示用于 sequence classification 的 BERT 模型。
Kind: models
的静态类 models
bertForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
类型: BertForSequenceClassification
的实例方法
返回值: Promise.<SequenceClassifierOutput>
- 一个对象,其中包含用于 sequence classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.BertForTokenClassification
BertForTokenClassification 是一个类,表示用于 token classification 的 BERT 模型。
Kind: models
的静态类 models
bertForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
类型: BertForTokenClassification
的实例方法
返回值: Promise.<TokenClassifierOutput>
- 一个对象,其中包含用于 token classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.BertForQuestionAnswering
BertForQuestionAnswering 是一个类,表示用于 question answering 的 BERT 模型。
Kind: models
的静态类 models
bertForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
类型: BertForQuestionAnswering
的实例方法
返回值: Promise.<QuestionAnsweringModelOutput>
- 一个对象,其中包含用于 question answering 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.RoFormerModel
裸 RoFormer Model transformer,输出原始 hidden-states,顶部没有任何特定的 head。
Kind: models
的静态类 models
models.RoFormerForMaskedLM
RoFormer Model 顶部带有 language modeling
head。
Kind: models
的静态类 models
roFormerForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
类型: RoFormerForMaskedLM
的实例方法
返回值: Promise.<MaskedLMOutput>
- 一个对象,其中包含用于 masked language modeling 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.RoFormerForSequenceClassification
RoFormer Model transformer,顶部带有 sequence classification/regression head(池化输出顶部的线性层)
Kind: models
的静态类 models
roFormerForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
类型: RoFormerForSequenceClassification
的实例方法
返回值: Promise.<SequenceClassifierOutput>
- 一个对象,其中包含用于 sequence classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.RoFormerForTokenClassification
RoFormer 模型,顶部带有一个 token 分类头(位于 hidden-states 输出之上的线性层),例如,用于命名实体识别 (NER) 任务。
Kind: models
的静态类 models
roFormerForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
Kind: RoFormerForTokenClassification
的实例方法
返回值: Promise.<TokenClassifierOutput>
- 一个对象,其中包含用于 token classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.RoFormerForQuestionAnswering
RoFormer 模型,顶部带有一个 span 分类头,用于抽取式问答任务,如 SQuAD(位于 hidden-states 输出之上的线性层,用于计算 span start logits
和 span end logits
)。
Kind: models
的静态类 models
roFormerForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
Kind: RoFormerForQuestionAnswering
的实例方法
返回值: Promise.<QuestionAnsweringModelOutput>
- 一个对象,其中包含用于 question answering 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.ConvBertModel
裸 ConvBERT 模型 Transformer,输出原始 hidden-states,顶部没有任何特定的 head。
Kind: models
的静态类 models
models.ConvBertForMaskedLM
ConvBERT 模型,顶部带有一个语言建模 head。
Kind: models
的静态类 models
convBertForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
Kind: ConvBertForMaskedLM
的实例方法
返回值: Promise.<MaskedLMOutput>
- 一个对象,其中包含用于 masked language modeling 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.ConvBertForSequenceClassification
ConvBERT 模型 Transformer,顶部带有一个序列分类/回归 head(位于 pooled 输出之上的线性层)
Kind: models
的静态类 models
convBertForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
Kind: ConvBertForSequenceClassification
的实例方法
返回值: Promise.<SequenceClassifierOutput>
- 一个对象,其中包含用于 sequence classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.ConvBertForTokenClassification
ConvBERT 模型,顶部带有一个 token 分类 head(位于 hidden-states 输出之上的线性层),例如,用于命名实体识别 (NER) 任务。
Kind: models
的静态类 models
convBertForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
Kind: ConvBertForTokenClassification
的实例方法
返回值: Promise.<TokenClassifierOutput>
- 一个对象,其中包含用于 token classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.ConvBertForQuestionAnswering
ConvBERT 模型,顶部带有一个 span 分类 head,用于抽取式问答任务,如 SQuAD(位于 hidden-states 输出之上的线性层,用于计算 span start logits
和 span end logits
)。
Kind: models
的静态类 models
convBertForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
Kind: ConvBertForQuestionAnswering
的实例方法
返回值: Promise.<QuestionAnsweringModelOutput>
- 一个对象,其中包含用于 question answering 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.ElectraModel
裸 Electra 模型 Transformer,输出原始 hidden-states,顶部没有任何特定的 head。与 BERT 模型相同,除了当 hidden size 和 embedding size 不同时,它在 embedding 层和 encoder 之间使用了一个额外的线性层。
Kind: models
的静态类 models
models.ElectraForMaskedLM
Electra 模型,顶部带有一个语言建模 head。
Kind: models
的静态类 models
electraForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
Kind: ElectraForMaskedLM
的实例方法
返回值: Promise.<MaskedLMOutput>
- 一个对象,其中包含用于 masked language modeling 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.ElectraForSequenceClassification
ELECTRA 模型 Transformer,顶部带有一个序列分类/回归 head(位于 pooled 输出之上的线性层)
Kind: models
的静态类 models
electraForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
Kind: ElectraForSequenceClassification
的实例方法
返回值: Promise.<SequenceClassifierOutput>
- 一个对象,其中包含用于 sequence classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.ElectraForTokenClassification
Electra 模型,顶部带有一个 token 分类 head。
Kind: models
的静态类 models
electraForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
Kind: ElectraForTokenClassification
的实例方法
返回值: Promise.<TokenClassifierOutput>
- 一个对象,其中包含用于 token classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.ElectraForQuestionAnswering
LECTRA 模型,顶部带有一个 span 分类 head,用于抽取式问答任务,如 SQuAD(位于 hidden-states 输出之上的线性层,用于计算 span start logits
和 span end logits
)。
Kind: models
的静态类 models
electraForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
Kind: ElectraForQuestionAnswering
的实例方法
返回值: Promise.<QuestionAnsweringModelOutput>
- 一个对象,其中包含用于 question answering 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.CamembertModel
裸 CamemBERT 模型 Transformer,输出原始 hidden-states,顶部没有任何特定的 head。
Kind: models
的静态类 models
models.CamembertForMaskedLM
CamemBERT 模型,顶部带有一个 language modeling
head。
Kind: models
的静态类 models
camembertForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
Kind: CamembertForMaskedLM
的实例方法
返回值: Promise.<MaskedLMOutput>
- 一个对象,其中包含用于 masked language modeling 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.CamembertForSequenceClassification
CamemBERT 模型 Transformer,顶部带有一个序列分类/回归 head(位于 pooled 输出之上的线性层),例如,用于 GLUE 任务。
Kind: models
的静态类 models
camembertForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
Kind: CamembertForSequenceClassification
的实例方法
返回值: Promise.<SequenceClassifierOutput>
- 一个对象,其中包含用于 sequence classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.CamembertForTokenClassification
CamemBERT 模型,顶部带有一个 token 分类 head(位于 hidden-states 输出之上的线性层),例如,用于命名实体识别 (NER) 任务。
Kind: models
的静态类 models
camembertForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
Kind: CamembertForTokenClassification
的实例方法
返回值: Promise.<TokenClassifierOutput>
- 一个对象,其中包含用于 token classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.CamembertForQuestionAnswering
CamemBERT 模型,顶部带有一个 span 分类 head,用于抽取式问答任务
Kind: models
的静态类 models
camembertForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
Kind: <0>CamembertForQuestionAnswering
0> 的实例方法
返回值: Promise.<QuestionAnsweringModelOutput>
- 一个对象,其中包含用于 question answering 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.DebertaModel
裸 DeBERTa 模型 Transformer,输出原始隐藏状态,顶部没有附加任何特定 head。
Kind: models
的静态类 models
models.DebertaForMaskedLM
DeBERTa 模型,顶部带有 language modeling
head。
Kind: models
的静态类 models
debertaForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
Kind: <0>DebertaForMaskedLM
0> 的实例方法
返回值: Promise.<MaskedLMOutput>
- 一个对象,其中包含用于 masked language modeling 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.DebertaForSequenceClassification
DeBERTa 模型 Transformer,顶部带有序列分类/回归 head (池化输出顶部的线性层)
Kind: models
的静态类 models
debertaForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
Kind: <0>DebertaForSequenceClassification
0> 的实例方法
返回值: Promise.<SequenceClassifierOutput>
- 一个对象,其中包含用于 sequence classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.DebertaForTokenClassification
DeBERTa 模型,顶部带有词元分类 head (隐藏状态输出顶部的线性层),例如用于命名实体识别 (NER) 任务。
Kind: models
的静态类 models
debertaForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
Kind: <0>DebertaForTokenClassification
0> 的实例方法
返回值: Promise.<TokenClassifierOutput>
- 一个对象,其中包含用于 token classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.DebertaForQuestionAnswering
DeBERTa 模型,顶部带有 span 分类 head,用于抽取式问答任务,如 SQuAD (隐藏状态输出顶部的线性层,用于计算 span start logits
和 span end logits
)。
Kind: models
的静态类 models
debertaForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
Kind: <0>DebertaForQuestionAnswering
0> 的实例方法
返回值: Promise.<QuestionAnsweringModelOutput>
- 一个对象,其中包含用于 question answering 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.DebertaV2Model
裸 DeBERTa-V2 模型 Transformer,输出原始隐藏状态,顶部没有附加任何特定 head。
Kind: models
的静态类 models
models.DebertaV2ForMaskedLM
DeBERTa-V2 模型,顶部带有 language modeling
head。
Kind: models
的静态类 models
debertaV2ForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
Kind: <0>DebertaV2ForMaskedLM
0> 的实例方法
返回值: Promise.<MaskedLMOutput>
- 一个对象,其中包含用于 masked language modeling 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.DebertaV2ForSequenceClassification
DeBERTa-V2 模型 Transformer,顶部带有序列分类/回归 head (池化输出顶部的线性层)
Kind: models
的静态类 models
debertaV2ForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
Kind: <0>DebertaV2ForSequenceClassification
0> 的实例方法
返回值: Promise.<SequenceClassifierOutput>
- 一个对象,其中包含用于 sequence classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.DebertaV2ForTokenClassification
DeBERTa-V2 模型,顶部带有词元分类 head (隐藏状态输出顶部的线性层),例如用于命名实体识别 (NER) 任务。
Kind: models
的静态类 models
debertaV2ForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
Kind: <0>DebertaV2ForTokenClassification
0> 的实例方法
返回值: Promise.<TokenClassifierOutput>
- 一个对象,其中包含用于 token classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.DebertaV2ForQuestionAnswering
DeBERTa-V2 模型,顶部带有 span 分类 head,用于抽取式问答任务,如 SQuAD (隐藏状态输出顶部的线性层,用于计算 span start logits
和 span end logits
)。
Kind: models
的静态类 models
debertaV2ForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
Kind: <0>DebertaV2ForQuestionAnswering
0> 的实例方法
返回值: Promise.<QuestionAnsweringModelOutput>
- 一个对象,其中包含用于 question answering 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.DistilBertForSequenceClassification
DistilBertForSequenceClassification 是一个类,表示用于序列分类的 DistilBERT 模型。
Kind: models
的静态类 models
distilBertForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
Kind: <0>DistilBertForSequenceClassification
0> 的实例方法
返回值: Promise.<SequenceClassifierOutput>
- 一个对象,其中包含用于 sequence classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.DistilBertForTokenClassification
DistilBertForTokenClassification 是一个类,表示用于词元分类的 DistilBERT 模型。
Kind: models
的静态类 models
distilBertForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
Kind: <0>DistilBertForTokenClassification
0> 的实例方法
返回值: Promise.<TokenClassifierOutput>
- 一个对象,其中包含用于 token classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.DistilBertForQuestionAnswering
DistilBertForQuestionAnswering 是一个类,表示用于问答的 DistilBERT 模型。
Kind: models
的静态类 models
distilBertForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
Kind: <0>DistilBertForQuestionAnswering
0> 的实例方法
返回值: Promise.<QuestionAnsweringModelOutput>
- 一个对象,其中包含用于 question answering 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.DistilBertForMaskedLM
DistilBertForMaskedLM 是一个类,表示用于掩码任务的 DistilBERT 模型。
Kind: models
的静态类 models
distilBertForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
Kind: <0>DistilBertForMaskedLM
0> 的实例方法
Returns: Promise.<MaskedLMOutput>
- 返回的对象
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.EsmModel
裸 ESM 模型 Transformer,输出原始隐藏状态,顶部没有附加任何特定 head。
Kind: models
的静态类 models
models.EsmForMaskedLM
ESM 模型,顶部带有 language modeling
head。
Kind: models
的静态类 models
esmForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
Kind: <0>EsmForMaskedLM
0> 的实例方法
返回值: Promise.<MaskedLMOutput>
- 一个对象,其中包含用于 masked language modeling 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.EsmForSequenceClassification
ESM 模型 Transformer,顶部带有序列分类/回归 head (池化输出顶部的线性层)
Kind: models
的静态类 models
esmForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
Kind: <0>EsmForSequenceClassification
0> 的实例方法
返回值: Promise.<SequenceClassifierOutput>
- 一个对象,其中包含用于 sequence classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.EsmForTokenClassification
ESM 模型,顶部带有一个 token 分类头(隐藏状态输出顶部的线性层),例如用于命名实体识别 (NER) 任务。
Kind: models
的静态类 models
esmForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
Kind: instance method of EsmForTokenClassification
返回值: Promise.<TokenClassifierOutput>
- 一个对象,其中包含用于 token classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.MobileBertForMaskedLM
MobileBertForMaskedLM 是一个类,表示用于掩码任务的 MobileBERT 模型。
Kind: models
的静态类 models
mobileBertForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
Kind: instance method of MobileBertForMaskedLM
Returns: Promise.<MaskedLMOutput>
- 返回的对象
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.MobileBertForSequenceClassification
MobileBert 模型转换器,顶部带有一个序列分类/回归头(池化输出顶部的线性层)。
Kind: models
的静态类 models
mobileBertForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
Kind: instance method of MobileBertForSequenceClassification
Returns: Promise.<SequenceClassifierOutput>
- 返回的对象
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.MobileBertForQuestionAnswering
MobileBert 模型,顶部带有一个跨度分类头,用于抽取式问答任务。
Kind: models
的静态类 models
mobileBertForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
Kind: instance method of MobileBertForQuestionAnswering
Returns: Promise.<QuestionAnsweringModelOutput>
- 返回的对象
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.MPNetModel
裸 MPNet 模型转换器,输出原始隐藏状态,顶部没有任何特定的头。
Kind: models
的静态类 models
models.MPNetForMaskedLM
MPNetForMaskedLM 是一个类,表示用于掩码语言建模的 MPNet 模型。
Kind: models
的静态类 models
mpNetForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
Kind: instance method of MPNetForMaskedLM
返回值: Promise.<MaskedLMOutput>
- 一个对象,其中包含用于 masked language modeling 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.MPNetForSequenceClassification
MPNetForSequenceClassification 是一个类,表示用于序列分类的 MPNet 模型。
Kind: models
的静态类 models
mpNetForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
Kind: instance method of MPNetForSequenceClassification
返回值: Promise.<SequenceClassifierOutput>
- 一个对象,其中包含用于 sequence classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.MPNetForTokenClassification
MPNetForTokenClassification 是一个类,表示用于 token 分类的 MPNet 模型。
Kind: models
的静态类 models
mpNetForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
Kind: instance method of MPNetForTokenClassification
返回值: Promise.<TokenClassifierOutput>
- 一个对象,其中包含用于 token classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.MPNetForQuestionAnswering
MPNetForQuestionAnswering 是一个类,表示用于问答的 MPNet 模型。
Kind: models
的静态类 models
mpNetForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
Kind: instance method of MPNetForQuestionAnswering
返回值: Promise.<QuestionAnsweringModelOutput>
- 一个对象,其中包含用于 question answering 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.T5ForConditionalGeneration
T5Model 是一个类,表示用于条件生成的 T5 模型。
Kind: models
的静态类 models
models.LongT5PreTrainedModel
一个抽象类,用于处理权重初始化以及用于下载和加载预训练模型的简单接口。
Kind: models
的静态类 models
models.LongT5Model
裸 LONGT5 模型转换器,输出原始隐藏状态,顶部没有任何特定的头。
Kind: models
的静态类 models
models.LongT5ForConditionalGeneration
LONGT5 模型,顶部带有一个 language modeling
头。
Kind: models
的静态类 models
models.MT5ForConditionalGeneration
一个类,表示基于 MT5 架构的条件序列到序列模型。
Kind: models
的静态类 models
models.BartModel
裸 BART 模型,输出原始隐藏状态,顶部没有任何特定的头。
Kind: models
的静态类 models
models.BartForConditionalGeneration
带有语言建模头的 BART 模型。可用于摘要。
Kind: models
的静态类 models
models.BartForSequenceClassification
带有序列分类/头的 Bart 模型(池化输出顶部的线性层)。
Kind: models
的静态类 models
bartForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
Kind: instance method of BartForSequenceClassification
返回值: Promise.<SequenceClassifierOutput>
- 一个对象,其中包含用于 sequence classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.MBartModel
裸 MBART 模型,输出原始隐藏状态,顶部没有任何特定的头。
Kind: models
的静态类 models
models.MBartForConditionalGeneration
带有语言建模头的 MBART 模型。在微调预训练模型后,可用于摘要。
Kind: models
的静态类 models
models.MBartForSequenceClassification
带有序列分类/头的 MBart 模型(池化输出顶部的线性层)。
Kind: models
的静态类 models
mBartForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
Kind: instance method of MBartForSequenceClassification
返回值: Promise.<SequenceClassifierOutput>
- 一个对象,其中包含用于 sequence classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.BlenderbotModel
裸 Blenderbot 模型,输出原始隐藏状态,顶部没有任何特定的头。
Kind: models
的静态类 models
models.BlenderbotForConditionalGeneration
带有语言建模头的 Blenderbot 模型。可用于摘要。
Kind: models
的静态类 models
models.BlenderbotSmallModel
裸露的 BlenderbotSmall 模型,输出原始隐藏状态,顶部没有任何特定的头。
Kind: models
的静态类 models
models.BlenderbotSmallForConditionalGeneration
带有语言建模头的 BlenderbotSmall 模型。可用于摘要。
Kind: models
的静态类 models
models.RobertaForMaskedLM
用于在 Roberta 模型上执行掩码语言建模的 RobertaForMaskedLM 类。
Kind: models
的静态类 models
robertaForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
Kind: RobertaForMaskedLM
的实例方法
Returns: Promise.<MaskedLMOutput>
- 返回的对象
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.RobertaForSequenceClassification
用于在 Roberta 模型上执行序列分类的 RobertaForSequenceClassification 类。
Kind: models
的静态类 models
robertaForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
Kind: RobertaForSequenceClassification
的实例方法
Returns: Promise.<SequenceClassifierOutput>
- 返回的对象
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.RobertaForTokenClassification
用于在 Roberta 模型上执行分词分类的 RobertaForTokenClassification 类。
Kind: models
的静态类 models
robertaForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
Kind: RobertaForTokenClassification
的实例方法
返回值: Promise.<TokenClassifierOutput>
- 一个对象,其中包含用于 token classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.RobertaForQuestionAnswering
用于在 Roberta 模型上执行问答的 RobertaForQuestionAnswering 类。
Kind: models
的静态类 models
robertaForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
Kind: RobertaForQuestionAnswering
的实例方法
Returns: Promise.<QuestionAnsweringModelOutput>
- 返回的对象
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.XLMPreTrainedModel
一个抽象类,用于处理权重初始化以及用于下载和加载预训练模型的简单接口。
Kind: models
的静态类 models
models.XLMModel
裸露的 XLM 模型转换器,输出原始隐藏状态,顶部没有任何特定的头。
Kind: models
的静态类 models
models.XLMWithLMHeadModel
XLM 模型转换器,顶部带有语言建模头(线性层,权重与输入嵌入绑定)。
Kind: models
的静态类 models
xlmWithLMHeadModel._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
Kind: XLMWithLMHeadModel
的实例方法
Returns: Promise.<MaskedLMOutput>
- 返回的对象
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.XLMForSequenceClassification
XLM 模型,顶部带有序列分类/回归头(池化输出顶部的线性层)
Kind: models
的静态类 models
xlmForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
Kind: XLMForSequenceClassification
的实例方法
Returns: Promise.<SequenceClassifierOutput>
- 返回的对象
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.XLMForTokenClassification
XLM 模型,顶部带有分词分类头(隐藏状态输出顶部的线性层)
Kind: models
的静态类 models
xlmForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
Kind: XLMForTokenClassification
的实例方法
返回值: Promise.<TokenClassifierOutput>
- 一个对象,其中包含用于 token classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.XLMForQuestionAnswering
XLM 模型,顶部带有跨度分类头,用于抽取式问答任务
Kind: models
的静态类 models
xlmForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
Kind: XLMForQuestionAnswering
的实例方法
Returns: Promise.<QuestionAnsweringModelOutput>
- 返回的对象
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.XLMRobertaForMaskedLM
用于在 XLMRoberta 模型上执行掩码语言建模的 XLMRobertaForMaskedLM 类。
Kind: models
的静态类 models
xlmRobertaForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
Kind: XLMRobertaForMaskedLM
的实例方法
Returns: Promise.<MaskedLMOutput>
- 返回的对象
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.XLMRobertaForSequenceClassification
用于在 XLMRoberta 模型上执行序列分类的 XLMRobertaForSequenceClassification 类。
Kind: models
的静态类 models
xlmRobertaForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
Kind: XLMRobertaForSequenceClassification
的实例方法
Returns: Promise.<SequenceClassifierOutput>
- 返回的对象
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.XLMRobertaForTokenClassification
用于在 XLMRoberta 模型上执行分词分类的 XLMRobertaForTokenClassification 类。
Kind: models
的静态类 models
xlmRobertaForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
Kind: XLMRobertaForTokenClassification
的实例方法
返回值: Promise.<TokenClassifierOutput>
- 一个对象,其中包含用于 token classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.XLMRobertaForQuestionAnswering
用于在 XLMRoberta 模型上执行问答的 XLMRobertaForQuestionAnswering 类。
Kind: models
的静态类 models
xlmRobertaForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
Kind: XLMRobertaForQuestionAnswering
的实例方法
Returns: Promise.<QuestionAnsweringModelOutput>
- 返回的对象
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.ASTModel
输出原始隐藏状态且顶部没有任何特定头的裸 AST 模型 Transformer。
Kind: models
的静态类 models
models.ASTForAudioClassification
音频频谱图 Transformer 模型,顶部带有音频分类头(池化输出顶部的线性层),例如用于 AudioSet、Speech Commands v2 等数据集。
Kind: models
的静态类 models
models.WhisperModel
用于训练不带语言模型头的 Whisper 模型的 WhisperModel 类。
Kind: models
的静态类 models
models.WhisperForConditionalGeneration
用于从 Whisper 模型生成条件输出的 WhisperForConditionalGeneration 类。
Kind: models
的静态类 models
whisperForConditionalGeneration._retrieve_init_tokens(generation_config)
类型:WhisperForConditionalGeneration
的实例方法
参数 | 类型 |
---|---|
generation_config | WhisperGenerationConfig |
whisperForConditionalGeneration.generate(options) ⇒ <code> Promise. < (ModelOutput|Tensor) > </code>
将 log-mel 输入特征转录或翻译成自回归生成的 token id 序列。
类型:WhisperForConditionalGeneration
的实例方法
返回值: Promise.<(ModelOutput|Tensor)>
- 模型的输出,可以包含生成的 token id、attention 和 scores。
参数 | 类型 |
---|---|
options(选项) | * |
whisperForConditionalGeneration._extract_token_timestamps(generate_outputs, alignment_heads, [num_frames], [time_precision]) ⇒ <code> Tensor </code>
使用编码器-解码器交叉注意力机制和动态时间规整 (DTW) 计算 token 级别的时间戳,以将每个输出 token 映射到输入音频中的位置。如果指定了 `num_frames`,则在应用 DTW 之前将裁剪编码器-解码器交叉注意力机制。
类型:WhisperForConditionalGeneration
的实例方法
返回:Tensor
- 包含每个预测 token 的秒级时间戳的 tensor
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
generate_outputs | Object(对象) | 模型生成的输出 | |
generate_outputs.cross_attentions | Array.<Array<Tensor>> | 模型输出的交叉注意力 | |
generate_outputs.sequences | Tensor | 模型输出的序列 | |
alignment_heads | Array.<Array<number>> | 模型的对齐头 | |
[num_frames] | number(数字) |
| 输入音频中的帧数。 |
[time_precision] | number(数字) | 0.02 | 时间戳的精度,以秒为单位 |
models.MoonshineModel
用于训练不带语言模型头的 Moonshine 模型的 MoonshineModel 类。
Kind: models
的静态类 models
models.VisionEncoderDecoderModel
基于 OpenAI 的 GPT 架构的视觉编码器-解码器模型,用于图像描述和其他视觉任务
Kind: models
的静态类 models
models.LlavaForConditionalGeneration
LLAVA 模型,由视觉骨干网络和语言模型组成。
Kind: models
的静态类 models
models.Idefics3ForConditionalGeneration
Idefics3 模型,由视觉骨干网络和语言模型组成。
Kind: models
的静态类 models
models.SmolVLMForConditionalGeneration
带有语言建模头的 SmolVLM 模型。它由 SigLIP 视觉编码器和顶部的语言建模头组成。
Kind: models
的静态类 models
models.CLIPModel
CLIP 文本和视觉模型,顶部带有投影层
示例:使用 CLIPModel
执行零样本图像分类。
import { AutoTokenizer, AutoProcessor, CLIPModel, RawImage } from '@huggingface/transformers';
// Load tokenizer, processor, and model
let tokenizer = await AutoTokenizer.from_pretrained('Xenova/clip-vit-base-patch16');
let processor = await AutoProcessor.from_pretrained('Xenova/clip-vit-base-patch16');
let model = await CLIPModel.from_pretrained('Xenova/clip-vit-base-patch16');
// Run tokenization
let texts = ['a photo of a car', 'a photo of a football match']
let text_inputs = tokenizer(texts, { padding: true, truncation: true });
// Read image and run processor
let image = await RawImage.read('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/football-match.jpg');
let image_inputs = await processor(image);
// Run model with both text and pixel inputs
let output = await model({ ...text_inputs, ...image_inputs });
// {
// logits_per_image: Tensor {
// dims: [ 1, 2 ],
// data: Float32Array(2) [ 18.579734802246094, 24.31830596923828 ],
// },
// logits_per_text: Tensor {
// dims: [ 2, 1 ],
// data: Float32Array(2) [ 18.579734802246094, 24.31830596923828 ],
// },
// text_embeds: Tensor {
// dims: [ 2, 512 ],
// data: Float32Array(1024) [ ... ],
// },
// image_embeds: Tensor {
// dims: [ 1, 512 ],
// data: Float32Array(512) [ ... ],
// }
// }
Kind: models
的静态类 models
models.CLIPTextModel
来自 CLIP 的文本模型,顶部没有任何头或投影。
Kind: models
的静态类 models
CLIPTextModel.from_pretrained() : <code> * </code>
类型:CLIPTextModel
的静态方法
models.CLIPTextModelWithProjection
CLIP 文本模型,顶部带有投影层(池化输出顶部的线性层)
示例:使用 CLIPTextModelWithProjection
计算文本嵌入。
import { AutoTokenizer, CLIPTextModelWithProjection } from '@huggingface/transformers';
// Load tokenizer and text model
const tokenizer = await AutoTokenizer.from_pretrained('Xenova/clip-vit-base-patch16');
const text_model = await CLIPTextModelWithProjection.from_pretrained('Xenova/clip-vit-base-patch16');
// Run tokenization
let texts = ['a photo of a car', 'a photo of a football match'];
let text_inputs = tokenizer(texts, { padding: true, truncation: true });
// Compute embeddings
const { text_embeds } = await text_model(text_inputs);
// Tensor {
// dims: [ 2, 512 ],
// type: 'float32',
// data: Float32Array(1024) [ ... ],
// size: 1024
// }
Kind: models
的静态类 models
CLIPTextModelWithProjection.from_pretrained() : <code> * </code>
类型:CLIPTextModelWithProjection
的静态方法
models.CLIPVisionModel
来自 CLIP 的视觉模型,顶部没有任何头或投影。
Kind: models
的静态类 models
CLIPVisionModel.from_pretrained() : <code> * </code>
类型:CLIPVisionModel
的静态方法
models.CLIPVisionModelWithProjection
CLIP 视觉模型,顶部带有投影层(池化输出顶部的线性层)
示例:使用 CLIPVisionModelWithProjection
计算视觉嵌入。
import { AutoProcessor, CLIPVisionModelWithProjection, RawImage} from '@huggingface/transformers';
// Load processor and vision model
const processor = await AutoProcessor.from_pretrained('Xenova/clip-vit-base-patch16');
const vision_model = await CLIPVisionModelWithProjection.from_pretrained('Xenova/clip-vit-base-patch16');
// Read image and run processor
let image = await RawImage.read('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/football-match.jpg');
let image_inputs = await processor(image);
// Compute embeddings
const { image_embeds } = await vision_model(image_inputs);
// Tensor {
// dims: [ 1, 512 ],
// type: 'float32',
// data: Float32Array(512) [ ... ],
// size: 512
// }
Kind: models
的静态类 models
CLIPVisionModelWithProjection.from_pretrained() : <code> * </code>
类型:CLIPVisionModelWithProjection
的静态方法
models.SiglipModel
SigLIP 文本和视觉模型,顶部带有投影层
示例:使用 SiglipModel
执行零样本图像分类。
import { AutoTokenizer, AutoProcessor, SiglipModel, RawImage } from '@huggingface/transformers';
// Load tokenizer, processor, and model
const tokenizer = await AutoTokenizer.from_pretrained('Xenova/siglip-base-patch16-224');
const processor = await AutoProcessor.from_pretrained('Xenova/siglip-base-patch16-224');
const model = await SiglipModel.from_pretrained('Xenova/siglip-base-patch16-224');
// Run tokenization
const texts = ['a photo of 2 cats', 'a photo of 2 dogs'];
const text_inputs = tokenizer(texts, { padding: 'max_length', truncation: true });
// Read image and run processor
const image = await RawImage.read('http://images.cocodataset.org/val2017/000000039769.jpg');
const image_inputs = await processor(image);
// Run model with both text and pixel inputs
const output = await model({ ...text_inputs, ...image_inputs });
// {
// logits_per_image: Tensor {
// dims: [ 1, 2 ],
// data: Float32Array(2) [ -1.6019744873046875, -10.720091819763184 ],
// },
// logits_per_text: Tensor {
// dims: [ 2, 1 ],
// data: Float32Array(2) [ -1.6019744873046875, -10.720091819763184 ],
// },
// text_embeds: Tensor {
// dims: [ 2, 768 ],
// data: Float32Array(1536) [ ... ],
// },
// image_embeds: Tensor {
// dims: [ 1, 768 ],
// data: Float32Array(768) [ ... ],
// }
// }
Kind: models
的静态类 models
models.SiglipTextModel
来自 SigLIP 的文本模型,顶部没有任何头或投影。
示例:使用 SiglipTextModel
计算文本嵌入。
import { AutoTokenizer, SiglipTextModel } from '@huggingface/transformers';
// Load tokenizer and text model
const tokenizer = await AutoTokenizer.from_pretrained('Xenova/siglip-base-patch16-224');
const text_model = await SiglipTextModel.from_pretrained('Xenova/siglip-base-patch16-224');
// Run tokenization
const texts = ['a photo of 2 cats', 'a photo of 2 dogs'];
const text_inputs = tokenizer(texts, { padding: 'max_length', truncation: true });
// Compute embeddings
const { pooler_output } = await text_model(text_inputs);
// Tensor {
// dims: [ 2, 768 ],
// type: 'float32',
// data: Float32Array(1536) [ ... ],
// size: 1536
// }
Kind: models
的静态类 models
SiglipTextModel.from_pretrained() : <code> * </code>
类型:SiglipTextModel
的静态方法
models.SiglipVisionModel
来自 SigLIP 的视觉模型,顶部没有任何头或投影。
示例:使用 SiglipVisionModel
计算视觉嵌入。
import { AutoProcessor, SiglipVisionModel, RawImage} from '@huggingface/transformers';
// Load processor and vision model
const processor = await AutoProcessor.from_pretrained('Xenova/siglip-base-patch16-224');
const vision_model = await SiglipVisionModel.from_pretrained('Xenova/siglip-base-patch16-224');
// Read image and run processor
const image = await RawImage.read('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/football-match.jpg');
const image_inputs = await processor(image);
// Compute embeddings
const { pooler_output } = await vision_model(image_inputs);
// Tensor {
// dims: [ 1, 768 ],
// type: 'float32',
// data: Float32Array(768) [ ... ],
// size: 768
// }
Kind: models
的静态类 models
SiglipVisionModel.from_pretrained() : <code> * </code>
类型:SiglipVisionModel
的静态方法
models.CLIPSegForImageSegmentation
CLIPSeg 模型,顶部带有基于 Transformer 的解码器,用于零样本和一次样本图像分割。
示例:使用 CLIPSegForImageSegmentation
模型执行零样本图像分割。
import { AutoTokenizer, AutoProcessor, CLIPSegForImageSegmentation, RawImage } from '@huggingface/transformers';
// Load tokenizer, processor, and model
const tokenizer = await AutoTokenizer.from_pretrained('Xenova/clipseg-rd64-refined');
const processor = await AutoProcessor.from_pretrained('Xenova/clipseg-rd64-refined');
const model = await CLIPSegForImageSegmentation.from_pretrained('Xenova/clipseg-rd64-refined');
// Run tokenization
const texts = ['a glass', 'something to fill', 'wood', 'a jar'];
const text_inputs = tokenizer(texts, { padding: true, truncation: true });
// Read image and run processor
const image = await RawImage.read('https://github.com/timojl/clipseg/blob/master/example_image.jpg?raw=true');
const image_inputs = await processor(image);
// Run model with both text and pixel inputs
const { logits } = await model({ ...text_inputs, ...image_inputs });
// logits: Tensor {
// dims: [4, 352, 352],
// type: 'float32',
// data: Float32Array(495616) [ ... ],
// size: 495616
// }
您可以按如下方式可视化预测结果
const preds = logits
.unsqueeze_(1)
.sigmoid_()
.mul_(255)
.round_()
.to('uint8');
for (let i = 0; i < preds.dims[0]; ++i) {
const img = RawImage.fromTensor(preds[i]);
img.save(`prediction_${i}.png`);
}
Kind: models
的静态类 models
models.GPT2LMHeadModel
GPT-2 语言模型头,位于 GPT-2 基础模型之上。此模型适用于文本生成任务。
Kind: models
的静态类 models
models.JAISModel
输出原始隐藏状态且顶部没有任何特定头的裸 JAIS 模型 Transformer。
Kind: models
的静态类 models
models.JAISLMHeadModel
JAIS 模型 Transformer,顶部带有语言建模头(权重与输入嵌入绑定的线性层)。
Kind: models
的静态类 models
models.CodeGenModel
CodeGenModel 是一个类,表示不带语言模型头的代码生成模型。
Kind: models
的静态类 models
models.CodeGenForCausalLM
CodeGenForCausalLM 是一个基于 GPT-2 架构的代码生成模型类。它扩展了 CodeGenPreTrainedModel
类。
Kind: models
的静态类 models
models.LlamaPreTrainedModel
裸模型 LLama 输出原始隐藏状态,顶部没有任何特定的头部。
Kind: models
的静态类 models
models.LlamaModel
裸模型 LLaMA 输出原始隐藏状态,顶部没有任何特定的头部。
Kind: models
的静态类 models
models.CoherePreTrainedModel
裸模型 Cohere 输出原始隐藏状态,顶部没有任何特定的头部。
Kind: models
的静态类 models
models.GemmaPreTrainedModel
裸模型 Gemma 输出原始隐藏状态,顶部没有任何特定的头部。
Kind: models
的静态类 models
models.GemmaModel
裸模型 Gemma 输出原始隐藏状态,顶部没有任何特定的头部。
Kind: models
的静态类 models
models.Gemma2PreTrainedModel
裸模型 Gemma2 输出原始隐藏状态,顶部没有任何特定的头部。
Kind: models
的静态类 models
models.Gemma2Model
裸模型 Gemma2 输出原始隐藏状态,顶部没有任何特定的头部。
Kind: models
的静态类 models
models.Gemma3PreTrainedModel
裸模型 Gemma3 输出原始隐藏状态,顶部没有任何特定的头部。
Kind: models
的静态类 models
models.Gemma3Model
裸模型 Gemma3 输出原始隐藏状态,顶部没有任何特定的头部。
Kind: models
的静态类 models
models.Qwen2PreTrainedModel
裸模型 Qwen2 输出原始隐藏状态,顶部没有任何特定的头部。
Kind: models
的静态类 models
models.Qwen2Model
裸模型 Qwen2 输出原始隐藏状态,顶部没有任何特定的头部。
Kind: models
的静态类 models
models.PhiModel
裸模型 Phi 输出原始隐藏状态,顶部没有任何特定的头部。
Kind: models
的静态类 models
models.Phi3Model
裸模型 Phi3 输出原始隐藏状态,顶部没有任何特定的头部。
Kind: models
的静态类 models
models.BloomPreTrainedModel
Bloom 模型转换器,顶部带有一个语言建模头(线性层,权重与输入嵌入层绑定)。
Kind: models
的静态类 models
models.BloomModel
裸模型 Bloom 转换器输出原始隐藏状态,顶部没有任何特定的头部。
Kind: models
的静态类 models
models.BloomForCausalLM
Bloom 模型转换器,顶部带有一个语言建模头(线性层,权重与输入嵌入层绑定)。
Kind: models
的静态类 models
models.MptModel
裸模型 Mpt 转换器输出原始隐藏状态,顶部没有任何特定的头部。
Kind: models
的静态类 models
models.MptForCausalLM
MPT 模型转换器,顶部带有一个语言建模头(线性层,权重与输入嵌入层绑定)。
Kind: models
的静态类 models
models.OPTModel
裸模型 OPT 输出原始隐藏状态,顶部没有任何特定的头部。
Kind: models
的静态类 models
models.OPTForCausalLM
OPT 模型转换器,顶部带有一个语言建模头(线性层,权重与输入嵌入层绑定)。
Kind: models
的静态类 models
models.VitPoseForPoseEstimation
VitPose 模型,顶部带有一个姿势估计头。
Kind: models
的静态类 models
models.VitMatteForImageMatting
ViTMatte 框架利用任何视觉骨干网络,例如用于 ADE20k、CityScapes。
示例: 使用 VitMatteForImageMatting
模型执行图像抠图。
import { AutoProcessor, VitMatteForImageMatting, RawImage } from '@huggingface/transformers';
// Load processor and model
const processor = await AutoProcessor.from_pretrained('Xenova/vitmatte-small-distinctions-646');
const model = await VitMatteForImageMatting.from_pretrained('Xenova/vitmatte-small-distinctions-646');
// Load image and trimap
const image = await RawImage.fromURL('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/vitmatte_image.png');
const trimap = await RawImage.fromURL('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/vitmatte_trimap.png');
// Prepare image + trimap for the model
const inputs = await processor(image, trimap);
// Predict alpha matte
const { alphas } = await model(inputs);
// Tensor {
// dims: [ 1, 1, 640, 960 ],
// type: 'float32',
// size: 614400,
// data: Float32Array(614400) [ 0.9894027709960938, 0.9970508813858032, ... ]
// }
您可以按如下方式可视化 Alpha 蒙版
import { Tensor, cat } from '@huggingface/transformers';
// Visualize predicted alpha matte
const imageTensor = image.toTensor();
// Convert float (0-1) alpha matte to uint8 (0-255)
const alphaChannel = alphas
.squeeze(0)
.mul_(255)
.clamp_(0, 255)
.round_()
.to('uint8');
// Concatenate original image with predicted alpha
const imageData = cat([imageTensor, alphaChannel], 0);
// Save output image
const outputImage = RawImage.fromTensor(imageData);
outputImage.save('output.png');
Kind: models
的静态类 models
vitMatteForImageMatting._call(model_inputs)
类型: VitMatteForImageMatting
的实例方法
参数 | 类型 |
---|---|
model_inputs | 任意 |
models.DetrObjectDetectionOutput
Kind: models
的静态类 models
new DetrObjectDetectionOutput(output)
参数 | 类型 | 描述 |
---|---|---|
output(输出) | Object(对象) | 模型的输出。 |
output.logits | Tensor | 所有查询的分类 logits(包括无对象)。 |
output.pred_boxes | Tensor | 所有查询的标准化框坐标,表示为(center_x,center_y,width,height)。这些值在 [0, 1] 范围内标准化,相对于批次中每个单独图像的大小(忽略可能的填充)。 |
models.DetrSegmentationOutput
Kind: models
的静态类 models
new DetrSegmentationOutput(output)
参数 | 类型 | 描述 |
---|---|---|
output(输出) | Object(对象) | 模型的输出。 |
output.logits | Tensor | 模型的输出 logits。 |
output.pred_boxes | Tensor | 预测框。 |
output.pred_masks | Tensor | 预测蒙版。 |
models.RTDetrObjectDetectionOutput
Kind: models
的静态类 models
new RTDetrObjectDetectionOutput(output)
参数 | 类型 | 描述 |
---|---|---|
output(输出) | Object(对象) | 模型的输出。 |
output.logits | Tensor | 所有查询的分类 logits(包括无对象)。 |
output.pred_boxes | Tensor | 所有查询的标准化框坐标,表示为(center_x,center_y,width,height)。这些值在 [0, 1] 范围内标准化,相对于批次中每个单独图像的大小(忽略可能的填充)。 |
models.TableTransformerModel
裸模型 Table Transformer 模型(由骨干网络和编码器-解码器 Transformer 组成)输出原始隐藏状态,顶部没有任何特定的头部。
Kind: models
的静态类 models
models.TableTransformerForObjectDetection
Table Transformer 模型(由骨干网络和编码器-解码器 Transformer 组成),顶部带有对象检测头,用于诸如 COCO 检测之类的任务。
Kind: models
的静态类 models
tableTransformerForObjectDetection._call(model_inputs)
类型: TableTransformerForObjectDetection
的实例方法
参数 | 类型 |
---|---|
model_inputs | 任意 |
models.ResNetPreTrainedModel
一个抽象类,用于处理权重初始化以及用于下载和加载预训练模型的简单接口。
Kind: models
的静态类 models
models.ResNetModel
裸模型 ResNet 输出原始特征,顶部没有任何特定的头部。
Kind: models
的静态类 models
models.ResNetForImageClassification
ResNet 模型,顶部带有一个图像分类头(池化特征顶部的线性层),例如用于 ImageNet。
Kind: models
的静态类 models
resNetForImageClassification._call(model_inputs)
Kind: instance method of ResNetForImageClassification
参数 | 类型 |
---|---|
model_inputs | 任意 |
models.Swin2SRModel
裸 Swin2SR 模型 Transformer,输出原始隐藏状态,顶部没有任何特定的 head。
Kind: models
的静态类 models
models.Swin2SRForImageSuperResolution
带有顶部上采样器 head 的 Swin2SR 模型 Transformer,用于图像超分辨率和恢复。
Example: 超分辨率,使用 Xenova/swin2SR-classical-sr-x2-64
。
import { AutoProcessor, Swin2SRForImageSuperResolution, RawImage } from '@huggingface/transformers';
// Load processor and model
const model_id = 'Xenova/swin2SR-classical-sr-x2-64';
const processor = await AutoProcessor.from_pretrained(model_id);
const model = await Swin2SRForImageSuperResolution.from_pretrained(model_id);
// Prepare model inputs
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/butterfly.jpg';
const image = await RawImage.fromURL(url);
const inputs = await processor(image);
// Run model
const outputs = await model(inputs);
// Convert Tensor to RawImage
const output = outputs.reconstruction.squeeze().clamp_(0, 1).mul_(255).round_().to('uint8');
const outputImage = RawImage.fromTensor(output);
// RawImage {
// data: Uint8Array(786432) [ 41, 31, 24, ... ],
// width: 512,
// height: 512,
// channels: 3
// }
Kind: models
的静态类 models
models.DPTModel
裸 DPT 模型 Transformer,输出原始隐藏状态,顶部没有任何特定的 head。
Kind: models
的静态类 models
models.DPTForDepthEstimation
带有深度估计 head(由 3 个卷积层组成)的 DPT 模型,例如用于 KITTI、NYUv2。
Example: 深度估计,使用 Xenova/dpt-hybrid-midas
。
import { DPTForDepthEstimation, AutoProcessor, RawImage, interpolate_4d } from '@huggingface/transformers';
// Load model and processor
const model_id = 'Xenova/dpt-hybrid-midas';
const model = await DPTForDepthEstimation.from_pretrained(model_id);
const processor = await AutoProcessor.from_pretrained(model_id);
// Load image from URL
const url = 'http://images.cocodataset.org/val2017/000000039769.jpg';
const image = await RawImage.read(url);
// Prepare image for the model
const inputs = await processor(image);
// Run model
const { predicted_depth } = await model(inputs);
// Interpolate to original size
const prediction = (await interpolate_4d(predicted_depth.unsqueeze(1), {
size: image.size.reverse(),
mode: 'bilinear',
})).squeeze(1);
// Visualize the prediction
const min = prediction.min().item();
const max = prediction.max().item();
const formatted = prediction.sub_(min).div_(max - min).mul_(255).to('uint8');
const depth = RawImage.fromTensor(formatted);
// RawImage {
// data: Uint8Array(307200) [ 85, 85, 84, ... ],
// width: 640,
// height: 480,
// channels: 1
// }
Kind: models
的静态类 models
models.DepthAnythingForDepthEstimation
带有深度估计 head(由 3 个卷积层组成)的 Depth Anything 模型,例如用于 KITTI、NYUv2。
Kind: models
的静态类 models
models.GLPNModel
裸 GLPN 编码器 (Mix-Transformer),输出原始隐藏状态,顶部没有任何特定的 head。
Kind: models
的静态类 models
models.GLPNForDepthEstimation
import { GLPNForDepthEstimation, AutoProcessor, RawImage, interpolate_4d } from ‘@huggingface/transformers’;
// 加载模型和处理器 const model_id = ‘Xenova/glpn-kitti’; const model = await GLPNForDepthEstimation.from_pretrained(model_id); const processor = await AutoProcessor.from_pretrained(model_id);
// 从 URL 加载图像 const url = ’http://images.cocodataset.org/val2017/000000039769.jpg’; const image = await RawImage.read(url);
// 为模型准备图像 const inputs = await processor(image);
// 运行模型 const { predicted_depth } = await model(inputs);
// 插值到原始大小 const prediction = (await interpolate_4d(predicted_depth.unsqueeze(1), { size: image.size.reverse(), mode: ‘bilinear’, })).squeeze(1);
// 可视化预测 const min = prediction.min().item(); const max = prediction.max().item(); const formatted = prediction.sub(min).div(max - min).mul_(255).to(‘uint8’); const depth = RawImage.fromTensor(formatted); // RawImage { // data: Uint8Array(307200) [ 85, 85, 84, … ], // width: 640, // height: 480, // channels: 1 // }
**Kind**: static class of [<code>models</code>](#module_models)
* * *
<a id="module_models.DonutSwinModel" class="group"></a>
## models.DonutSwinModel
The bare Donut Swin Model transformer outputting raw hidden-states without any specific head on top.
**Example:** Step-by-step Document Parsing.
```javascript
import { AutoProcessor, AutoTokenizer, AutoModelForVision2Seq, RawImage } from '@huggingface/transformers';
// Choose model to use
const model_id = 'Xenova/donut-base-finetuned-cord-v2';
// Prepare image inputs
const processor = await AutoProcessor.from_pretrained(model_id);
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/receipt.png';
const image = await RawImage.read(url);
const image_inputs = await processor(image);
// Prepare decoder inputs
const tokenizer = await AutoTokenizer.from_pretrained(model_id);
const task_prompt = '<s_cord-v2>';
const decoder_input_ids = tokenizer(task_prompt, {
add_special_tokens: false,
}).input_ids;
// Create the model
const model = await AutoModelForVision2Seq.from_pretrained(model_id);
// Run inference
const output = await model.generate(image_inputs.pixel_values, {
decoder_input_ids,
max_length: model.config.decoder.max_position_embeddings,
});
// Decode output
const decoded = tokenizer.batch_decode(output)[0];
// <s_cord-v2><s_menu><s_nm> CINNAMON SUGAR</s_nm><s_unitprice> 17,000</s_unitprice><s_cnt> 1 x</s_cnt><s_price> 17,000</s_price></s_menu><s_sub_total><s_subtotal_price> 17,000</s_subtotal_price></s_sub_total><s_total><s_total_price> 17,000</s_total_price><s_cashprice> 20,000</s_cashprice><s_changeprice> 3,000</s_changeprice></s_total></s>
Example: 逐步文档视觉问答 (DocVQA)
import { AutoProcessor, AutoTokenizer, AutoModelForVision2Seq, RawImage } from '@huggingface/transformers';
// Choose model to use
const model_id = 'Xenova/donut-base-finetuned-docvqa';
// Prepare image inputs
const processor = await AutoProcessor.from_pretrained(model_id);
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/invoice.png';
const image = await RawImage.read(url);
const image_inputs = await processor(image);
// Prepare decoder inputs
const tokenizer = await AutoTokenizer.from_pretrained(model_id);
const question = 'What is the invoice number?';
const task_prompt = `<s_docvqa><s_question>${question}</s_question><s_answer>`;
const decoder_input_ids = tokenizer(task_prompt, {
add_special_tokens: false,
}).input_ids;
// Create the model
const model = await AutoModelForVision2Seq.from_pretrained(model_id);
// Run inference
const output = await model.generate(image_inputs.pixel_values, {
decoder_input_ids,
max_length: model.config.decoder.max_position_embeddings,
});
// Decode output
const decoded = tokenizer.batch_decode(output)[0];
// <s_docvqa><s_question> What is the invoice number?</s_question><s_answer> us-001</s_answer></s>
Kind: models
的静态类 models
models.ConvNextModel
裸 ConvNext 模型,输出原始特征,顶部没有任何特定的 head。
Kind: models
的静态类 models
models.ConvNextForImageClassification
带有图像分类 head(池化特征顶部的线性层)的 ConvNext 模型,例如用于 ImageNet。
Kind: models
的静态类 models
convNextForImageClassification._call(model_inputs)
Kind: instance method of ConvNextForImageClassification
参数 | 类型 |
---|---|
model_inputs | 任意 |
models.ConvNextV2Model
裸 ConvNextV2 模型,输出原始特征,顶部没有任何特定的 head。
Kind: models
的静态类 models
models.ConvNextV2ForImageClassification
带有图像分类 head(池化特征顶部的线性层)的 ConvNextV2 模型,例如用于 ImageNet。
Kind: models
的静态类 models
convNextV2ForImageClassification._call(model_inputs)
Kind: instance method of ConvNextV2ForImageClassification
参数 | 类型 |
---|---|
model_inputs | 任意 |
models.Dinov2Model
裸 DINOv2 模型 Transformer,输出原始隐藏状态,顶部没有任何特定的 head。
Kind: models
的静态类 models
models.Dinov2ForImageClassification
带有图像分类 head 的 Dinov2 模型 Transformer([CLS] 标记的最终隐藏状态顶部的线性层),例如用于 ImageNet。
Kind: models
的静态类 models
dinov2ForImageClassification._call(model_inputs)
Kind: instance method of Dinov2ForImageClassification
参数 | 类型 |
---|---|
model_inputs | 任意 |
models.Dinov2WithRegistersModel
裸 Dinov2WithRegisters 模型 Transformer,输出原始隐藏状态,顶部没有任何特定的 head。
Kind: models
的静态类 models
models.Dinov2WithRegistersForImageClassification
带有图像分类 head 的 Dinov2WithRegisters 模型 Transformer([CLS] 标记的最终隐藏状态顶部的线性层),例如用于 ImageNet。
Kind: models
的静态类 models
dinov2WithRegistersForImageClassification._call(model_inputs)
Kind: instance method of Dinov2WithRegistersForImageClassification
参数 | 类型 |
---|---|
model_inputs | 任意 |
models.YolosObjectDetectionOutput
Kind: models
的静态类 models
new YolosObjectDetectionOutput(output)
参数 | 类型 | 描述 |
---|---|---|
output(输出) | Object(对象) | 模型的输出。 |
output.logits | Tensor | 所有查询的分类 logits(包括无对象)。 |
output.pred_boxes | Tensor | 所有查询的标准化框坐标,表示为(center_x,center_y,width,height)。这些值在 [0, 1] 范围内标准化,相对于批次中每个单独图像的大小(忽略可能的填充)。 |
models.SamModel
Segment Anything Model (SAM),用于生成分割掩码,给定输入图像和可选的 2D 位置和边界框。
Example: 执行掩码生成,使用 Xenova/sam-vit-base
。
import { SamModel, AutoProcessor, RawImage } from '@huggingface/transformers';
const model = await SamModel.from_pretrained('Xenova/sam-vit-base');
const processor = await AutoProcessor.from_pretrained('Xenova/sam-vit-base');
const img_url = 'https://huggingface.co/ybelkada/segment-anything/resolve/main/assets/car.png';
const raw_image = await RawImage.read(img_url);
const input_points = [[[450, 600]]] // 2D localization of a window
const inputs = await processor(raw_image, { input_points });
const outputs = await model(inputs);
const masks = await processor.post_process_masks(outputs.pred_masks, inputs.original_sizes, inputs.reshaped_input_sizes);
// [
// Tensor {
// dims: [ 1, 3, 1764, 2646 ],
// type: 'bool',
// data: Uint8Array(14002632) [ ... ],
// size: 14002632
// }
// ]
const scores = outputs.iou_scores;
// Tensor {
// dims: [ 1, 1, 3 ],
// type: 'float32',
// data: Float32Array(3) [
// 0.8892380595207214,
// 0.9311248064041138,
// 0.983696699142456
// ],
// size: 3
// }
Kind: models
的静态类 models
- .SamModel
.get_image_embeddings(model_inputs)
⇒Promise.<{image_embeddings: Tensor, image_positional_embeddings: Tensor}>
.forward(model_inputs)
⇒Promise.<Object>
._call(model_inputs)
⇒Promise.<SamImageSegmentationOutput>
samModel.get_image_embeddings(model_inputs) ⇒ <code> Promise. < {image_embeddings: Tensor, image_positional_embeddings: Tensor} > </code>
计算图像嵌入和位置图像嵌入,给定图像的像素值。
Kind: instance method of SamModel
Returns: Promise.<{image_embeddings: Tensor, image_positional_embeddings: Tensor}>
- 图像嵌入和位置图像嵌入。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 包含模型输入的对象。 |
model_inputs.pixel_values | Tensor | 使用 |
samModel.forward(model_inputs) ⇒ <code> Promise. < Object > </code>
Kind: instance method of SamModel
Returns: Promise.<Object>
- 模型的输出。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | SamModelInputs | 包含模型输入的对象。 |
samModel._call(model_inputs) ⇒ <code> Promise. < SamImageSegmentationOutput > </code>
使用提供的输入运行模型
Kind: instance method of SamModel
Returns: Promise.<SamImageSegmentationOutput>
- 包含分割输出的对象
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型输入 |
models.SamImageSegmentationOutput
Segment-Anything 模型输出的基类。
Kind: models
的静态类 models
new SamImageSegmentationOutput(output)
参数 | 类型 | 描述 |
---|---|---|
output(输出) | Object(对象) | 模型的输出。 |
output.iou_scores | Tensor | 模型的输出 logits。 |
output.pred_masks | Tensor | 预测框。 |
models.Wav2Vec2Model
裸 Wav2Vec2 模型 Transformer,输出原始隐藏状态,顶部没有任何特定的 head。
Example: 加载并运行 Wav2Vec2Model
以进行特征提取。
import { AutoProcessor, AutoModel, read_audio } from '@huggingface/transformers';
// Read and preprocess audio
const processor = await AutoProcessor.from_pretrained('Xenova/mms-300m');
const audio = await read_audio('https://huggingface.co/datasets/Narsil/asr_dummy/resolve/main/mlk.flac', 16000);
const inputs = await processor(audio);
// Run model with inputs
const model = await AutoModel.from_pretrained('Xenova/mms-300m');
const output = await model(inputs);
// {
// last_hidden_state: Tensor {
// dims: [ 1, 1144, 1024 ],
// type: 'float32',
// data: Float32Array(1171456) [ ... ],
// size: 1171456
// }
// }
Kind: models
的静态类 models
models.Wav2Vec2ForAudioFrameClassification
带有帧分类 head 的 Wav2Vec2 模型,用于诸如说话人日志之类的任务。
Kind: models
的静态类 models
wav2Vec2ForAudioFrameClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
Kind: instance method of Wav2Vec2ForAudioFrameClassification
Returns: Promise.<TokenClassifierOutput>
- An object containing the model’s output logits for sequence classification.
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.PyAnnoteModel
裸 PyAnnote 模型 Transformer,输出原始的隐藏状态,顶部没有任何特定的 head。
Kind: models
的静态类 models
models.PyAnnoteForAudioFrameClassification
PyAnnote 模型,顶部带有帧分类 head,用于诸如说话人日志等任务。
Example: 加载并运行一个 PyAnnoteForAudioFrameClassification
模型用于说话人日志。
import { AutoProcessor, AutoModelForAudioFrameClassification, read_audio } from '@huggingface/transformers';
// Load model and processor
const model_id = 'onnx-community/pyannote-segmentation-3.0';
const model = await AutoModelForAudioFrameClassification.from_pretrained(model_id);
const processor = await AutoProcessor.from_pretrained(model_id);
// Read and preprocess audio
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/mlk.wav';
const audio = await read_audio(url, processor.feature_extractor.config.sampling_rate);
const inputs = await processor(audio);
// Run model with inputs
const { logits } = await model(inputs);
// {
// logits: Tensor {
// dims: [ 1, 767, 7 ], // [batch_size, num_frames, num_classes]
// type: 'float32',
// data: Float32Array(5369) [ ... ],
// size: 5369
// }
// }
const result = processor.post_process_speaker_diarization(logits, audio.length);
// [
// [
// { id: 0, start: 0, end: 1.0512535626298245, confidence: 0.8220156481664611 },
// { id: 2, start: 1.0512535626298245, end: 2.3398869619825127, confidence: 0.9008811707860472 },
// ...
// ]
// ]
// Display result
console.table(result[0], ['start', 'end', 'id', 'confidence']);
// ┌─────────┬────────────────────┬────────────────────┬────┬─────────────────────┐
// │ (index) │ start │ end │ id │ confidence │
// ├─────────┼────────────────────┼────────────────────┼────┼─────────────────────┤
// │ 0 │ 0 │ 1.0512535626298245 │ 0 │ 0.8220156481664611 │
// │ 1 │ 1.0512535626298245 │ 2.3398869619825127 │ 2 │ 0.9008811707860472 │
// │ 2 │ 2.3398869619825127 │ 3.5946089560890773 │ 0 │ 0.7521651315796233 │
// │ 3 │ 3.5946089560890773 │ 4.578039708226655 │ 2 │ 0.8491978128022479 │
// │ 4 │ 4.578039708226655 │ 4.594995410849717 │ 0 │ 0.2935352600416393 │
// │ 5 │ 4.594995410849717 │ 6.121008646925269 │ 3 │ 0.6788051309866024 │
// │ 6 │ 6.121008646925269 │ 6.256654267909762 │ 0 │ 0.37125512393851134 │
// │ 7 │ 6.256654267909762 │ 8.630452635138397 │ 2 │ 0.7467035186353542 │
// │ 8 │ 8.630452635138397 │ 10.088643060721703 │ 0 │ 0.7689364814666032 │
// │ 9 │ 10.088643060721703 │ 12.58113134631177 │ 2 │ 0.9123324509131324 │
// │ 10 │ 12.58113134631177 │ 13.005023911888312 │ 0 │ 0.4828358177572041 │
// └─────────┴────────────────────┴────────────────────┴────┴─────────────────────┘
Kind: models
的静态类 models
pyAnnoteForAudioFrameClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
Kind: instance method of PyAnnoteForAudioFrameClassification
Returns: Promise.<TokenClassifierOutput>
- An object containing the model’s output logits for sequence classification.
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.UniSpeechModel
裸 UniSpeech 模型 Transformer,输出原始的隐藏状态,顶部没有任何特定的 head。
Kind: models
的静态类 models
models.UniSpeechForCTC
UniSpeech 模型,顶部带有 语言建模
head,用于连接时序分类 (CTC)。
Kind: models
的静态类 models
uniSpeechForCTC._call(model_inputs)
Kind: instance method of UniSpeechForCTC
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | |
model_inputs.input_values | Tensor | 输入原始语音波形的浮点数值。 |
model_inputs.attention_mask | Tensor | 用于避免在 padding token 索引上执行卷积和注意力的掩码。掩码值在 [0, 1] 中选择。 |
models.UniSpeechForSequenceClassification
UniSpeech 模型,顶部带有序列分类 head(池化输出上的线性层)。
Kind: models
的静态类 models
uniSpeechForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
Kind: instance method of UniSpeechForSequenceClassification
返回值: Promise.<SequenceClassifierOutput>
- 一个对象,其中包含用于 sequence classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.UniSpeechSatModel
裸 UniSpeechSat 模型 Transformer,输出原始的隐藏状态,顶部没有任何特定的 head。
Kind: models
的静态类 models
models.UniSpeechSatForCTC
UniSpeechSat 模型,顶部带有 语言建模
head,用于连接时序分类 (CTC)。
Kind: models
的静态类 models
uniSpeechSatForCTC._call(model_inputs)
Kind: instance method of UniSpeechSatForCTC
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | |
model_inputs.input_values | Tensor | 输入原始语音波形的浮点数值。 |
model_inputs.attention_mask | Tensor | 用于避免在 padding token 索引上执行卷积和注意力的掩码。掩码值在 [0, 1] 中选择。 |
models.UniSpeechSatForSequenceClassification
UniSpeechSat 模型,顶部带有序列分类 head(池化输出上的线性层)。
Kind: models
的静态类 models
uniSpeechSatForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
Kind: instance method of UniSpeechSatForSequenceClassification
返回值: Promise.<SequenceClassifierOutput>
- 一个对象,其中包含用于 sequence classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.UniSpeechSatForAudioFrameClassification
UniSpeechSat 模型,顶部带有帧分类 head,用于诸如说话人日志等任务。
Kind: models
的静态类 models
uniSpeechSatForAudioFrameClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
Kind: instance method of UniSpeechSatForAudioFrameClassification
Returns: Promise.<TokenClassifierOutput>
- An object containing the model’s output logits for sequence classification.
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.Wav2Vec2BertModel
裸 Wav2Vec2Bert 模型 Transformer,输出原始的隐藏状态,顶部没有任何特定的 head。
Kind: models
的静态类 models
models.Wav2Vec2BertForCTC
Wav2Vec2Bert 模型,顶部带有 语言建模
head,用于连接时序分类 (CTC)。
Kind: models
的静态类 models
wav2Vec2BertForCTC._call(model_inputs)
Kind: instance method of Wav2Vec2BertForCTC
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | |
model_inputs.input_features | Tensor | 输入 mel 频谱图的浮点数值。 |
model_inputs.attention_mask | Tensor | 用于避免在 padding token 索引上执行卷积和注意力的掩码。掩码值在 [0, 1] 中选择。 |
models.Wav2Vec2BertForSequenceClassification
Wav2Vec2Bert 模型,顶部带有序列分类 head(池化输出上的线性层)。
Kind: models
的静态类 models
wav2Vec2BertForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
Kind: instance method of Wav2Vec2BertForSequenceClassification
返回值: Promise.<SequenceClassifierOutput>
- 一个对象,其中包含用于 sequence classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.HubertModel
裸 Hubert 模型 Transformer,输出原始的隐藏状态,顶部没有任何特定的 head。
Example: 加载并运行一个 HubertModel
模型用于特征提取。
import { AutoProcessor, AutoModel, read_audio } from '@huggingface/transformers';
// Read and preprocess audio
const processor = await AutoProcessor.from_pretrained('Xenova/hubert-base-ls960');
const audio = await read_audio('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav', 16000);
const inputs = await processor(audio);
// Load and run model with inputs
const model = await AutoModel.from_pretrained('Xenova/hubert-base-ls960');
const output = await model(inputs);
// {
// last_hidden_state: Tensor {
// dims: [ 1, 549, 768 ],
// type: 'float32',
// data: Float32Array(421632) [0.0682469978928566, 0.08104046434164047, -0.4975186586380005, ...],
// size: 421632
// }
// }
Kind: models
的静态类 models
models.HubertForCTC
Hubert 模型,顶部带有 语言建模
head,用于连接时序分类 (CTC)。
Kind: models
的静态类 models
hubertForCTC._call(model_inputs)
Kind: instance method of HubertForCTC
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | |
model_inputs.input_values | Tensor | 输入原始语音波形的浮点数值。 |
model_inputs.attention_mask | Tensor | 用于避免在 padding token 索引上执行卷积和注意力的掩码。掩码值在 [0, 1] 中选择。 |
models.HubertForSequenceClassification
Hubert 模型,顶部带有序列分类 head(池化输出上的线性层),用于诸如 SUPERB 关键词识别等任务。
Kind: models
的静态类 models
hubertForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
Kind: instance method of HubertForSequenceClassification
返回值: Promise.<SequenceClassifierOutput>
- 一个对象,其中包含用于 sequence classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.WavLMPreTrainedModel
一个抽象类,用于处理权重初始化以及用于下载和加载预训练模型的简单接口。
Kind: models
的静态类 models
models.WavLMModel
裸 WavLM 模型 Transformer,输出原始的隐藏状态,顶部没有任何特定的 head。
Example: 加载并运行一个 WavLMModel
模型用于特征提取。
import { AutoProcessor, AutoModel, read_audio } from '@huggingface/transformers';
// Read and preprocess audio
const processor = await AutoProcessor.from_pretrained('Xenova/wavlm-base');
const audio = await read_audio('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav', 16000);
const inputs = await processor(audio);
// Run model with inputs
const model = await AutoModel.from_pretrained('Xenova/wavlm-base');
const output = await model(inputs);
// {
// last_hidden_state: Tensor {
// dims: [ 1, 549, 768 ],
// type: 'float32',
// data: Float32Array(421632) [-0.349443256855011, -0.39341306686401367, 0.022836603224277496, ...],
// size: 421632
// }
// }
Kind: models
的静态类 models
models.WavLMForCTC
带有用于连接时序分类 (CTC) 的 language modeling
头的 WavLM 模型。
Kind: models
的静态类 models
wavLMForCTC._call(model_inputs)
类型:WavLMForCTC
的实例方法
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | |
model_inputs.input_values | Tensor | 输入原始语音波形的浮点数值。 |
model_inputs.attention_mask | Tensor | 用于避免在 padding token 索引上执行卷积和注意力的掩码。掩码值在 [0, 1] 中选择。 |
models.WavLMForSequenceClassification
带有序列分类头的 WavLM 模型(池化输出之上的线性层)。
Kind: models
的静态类 models
wavLMForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
类型:WavLMForSequenceClassification
的实例方法
返回值: Promise.<SequenceClassifierOutput>
- 一个对象,其中包含用于 sequence classification 的模型的输出 logits。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.WavLMForXVector
带有用于说话人验证等任务的 XVector 特征提取头的 WavLM 模型。
示例: 使用 WavLMForXVector
提取说话人嵌入。
import { AutoProcessor, AutoModel, read_audio } from '@huggingface/transformers';
// Read and preprocess audio
const processor = await AutoProcessor.from_pretrained('Xenova/wavlm-base-plus-sv');
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav';
const audio = await read_audio(url, 16000);
const inputs = await processor(audio);
// Run model with inputs
const model = await AutoModel.from_pretrained('Xenova/wavlm-base-plus-sv');
const outputs = await model(inputs);
// {
// logits: Tensor {
// dims: [ 1, 512 ],
// type: 'float32',
// data: Float32Array(512) [0.5847219228744507, ...],
// size: 512
// },
// embeddings: Tensor {
// dims: [ 1, 512 ],
// type: 'float32',
// data: Float32Array(512) [-0.09079201519489288, ...],
// size: 512
// }
// }
Kind: models
的静态类 models
wavLMForXVector._call(model_inputs) ⇒ <code> Promise. < XVectorOutput > </code>
在新输入上调用模型。
类型:WavLMForXVector
的实例方法
返回值:Promise.<XVectorOutput>
- 包含模型输出 logits 和说话人嵌入的对象。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.WavLMForAudioFrameClassification
带有用于说话人日志等任务的帧分类头的 WavLM 模型。
示例: 使用 WavLMForAudioFrameClassification
执行说话人日志。
import { AutoProcessor, AutoModelForAudioFrameClassification, read_audio } from '@huggingface/transformers';
// Read and preprocess audio
const processor = await AutoProcessor.from_pretrained('Xenova/wavlm-base-plus-sd');
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav';
const audio = await read_audio(url, 16000);
const inputs = await processor(audio);
// Run model with inputs
const model = await AutoModelForAudioFrameClassification.from_pretrained('Xenova/wavlm-base-plus-sd');
const { logits } = await model(inputs);
// {
// logits: Tensor {
// dims: [ 1, 549, 2 ], // [batch_size, num_frames, num_speakers]
// type: 'float32',
// data: Float32Array(1098) [-3.5301010608673096, ...],
// size: 1098
// }
// }
const labels = logits[0].sigmoid().tolist().map(
frames => frames.map(speaker => speaker > 0.5 ? 1 : 0)
);
console.log(labels); // labels is a one-hot array of shape (num_frames, num_speakers)
// [
// [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0],
// [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0],
// [0, 0], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1],
// ...
// ]
Kind: models
的静态类 models
wavLMForAudioFrameClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
类型:WavLMForAudioFrameClassification
的实例方法
Returns: Promise.<TokenClassifierOutput>
- An object containing the model’s output logits for sequence classification.
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.SpeechT5PreTrainedModel
一个抽象类,用于处理权重初始化以及用于下载和加载预训练模型的简单接口。
Kind: models
的静态类 models
models.SpeechT5Model
裸 SpeechT5 编码器-解码器模型,输出原始隐藏状态,没有任何特定的前置或后置网络。
Kind: models
的静态类 models
models.SpeechT5ForSpeechToText
带有语音编码器和文本解码器的 SpeechT5 模型。
示例: 使用 SpeechT5ForSpeechToText
从文本生成语音。
import { AutoTokenizer, AutoProcessor, SpeechT5ForTextToSpeech, SpeechT5HifiGan, Tensor } from '@huggingface/transformers';
// Load the tokenizer and processor
const tokenizer = await AutoTokenizer.from_pretrained('Xenova/speecht5_tts');
const processor = await AutoProcessor.from_pretrained('Xenova/speecht5_tts');
// Load the models
// NOTE: We use the full-precision versions as they are more accurate
const model = await SpeechT5ForTextToSpeech.from_pretrained('Xenova/speecht5_tts', { dtype: 'fp32' });
const vocoder = await SpeechT5HifiGan.from_pretrained('Xenova/speecht5_hifigan', { dtype: 'fp32' });
// Load speaker embeddings from URL
const speaker_embeddings_data = new Float32Array(
await (await fetch('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/speaker_embeddings.bin')).arrayBuffer()
);
const speaker_embeddings = new Tensor(
'float32',
speaker_embeddings_data,
[1, speaker_embeddings_data.length]
)
// Run tokenization
const { input_ids } = tokenizer('Hello, my dog is cute');
// Generate waveform
const { waveform } = await model.generate_speech(input_ids, speaker_embeddings, { vocoder });
console.log(waveform)
// Tensor {
// dims: [ 26112 ],
// type: 'float32',
// size: 26112,
// data: Float32Array(26112) [ -0.00043630177970044315, -0.00018082228780258447, ... ],
// }
Kind: models
的静态类 models
models.SpeechT5ForTextToSpeech
带有文本编码器和语音解码器的 SpeechT5 模型。
Kind: models
的静态类 models
speechT5ForTextToSpeech.generate_speech(input_values, speaker_embeddings, options) ⇒ <code> Promise. < SpeechOutput > </code>
将输入 token 序列转换为 mel 频谱图序列,随后使用声码器将其转换为语音波形。
类型:SpeechT5ForTextToSpeech
的实例方法
返回值:Promise.<SpeechOutput>
- 一个 Promise,它解析为一个包含频谱图、波形和交叉注意力张量的对象。
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
input_values | Tensor | 词汇表中输入序列 token 的索引。 | |
speaker_embeddings | Tensor | 包含说话人嵌入的张量。 | |
options(选项) | Object(对象) | 用于生成语音的可选参数。 | |
[options.threshold] | number(数字) | 0.5 | 当预测的停止 token 概率超过此值时,生成的序列结束。 |
[options.minlenratio] | number(数字) | 0.0 | 用于计算输出序列所需的最小长度。 |
[options.maxlenratio] | number(数字) | 20.0 | 用于计算输出序列允许的最大长度。 |
[options.vocoder] | Object(对象) |
| 将 mel 频谱图转换为语音波形的声码器。如果为 |
[options.output_cross_attentions] | boolean(布尔值) | false | 是否返回解码器交叉注意力层的注意力张量。 |
models.SpeechT5HifiGan
HiFi-GAN 声码器。
有关示例用法,请参阅 SpeechT5ForSpeechToText。
Kind: models
的静态类 models
models.TrOCRForCausalLM
带有语言建模头的 TrOCR 解码器。
Kind: models
的静态类 models
models.MistralPreTrainedModel
裸 Mistral 模型,输出原始隐藏状态,没有任何特定的头部。
Kind: models
的静态类 models
models.Starcoder2PreTrainedModel
裸 Starcoder2 模型,输出原始隐藏状态,没有任何特定的头部。
Kind: models
的静态类 models
models.FalconPreTrainedModel
裸 Falcon 模型,输出原始隐藏状态,没有任何特定的头部。
Kind: models
的静态类 models
models.ClapTextModelWithProjection
带有投影层的 CLAP 文本模型(池化输出之上的线性层)。
示例: 使用 ClapTextModelWithProjection
计算文本嵌入。
import { AutoTokenizer, ClapTextModelWithProjection } from '@huggingface/transformers';
// Load tokenizer and text model
const tokenizer = await AutoTokenizer.from_pretrained('Xenova/clap-htsat-unfused');
const text_model = await ClapTextModelWithProjection.from_pretrained('Xenova/clap-htsat-unfused');
// Run tokenization
const texts = ['a sound of a cat', 'a sound of a dog'];
const text_inputs = tokenizer(texts, { padding: true, truncation: true });
// Compute embeddings
const { text_embeds } = await text_model(text_inputs);
// Tensor {
// dims: [ 2, 512 ],
// type: 'float32',
// data: Float32Array(1024) [ ... ],
// size: 1024
// }
Kind: models
的静态类 models
ClapTextModelWithProjection.from_pretrained() : <code> * </code>
类型:ClapTextModelWithProjection
的静态方法
models.ClapAudioModelWithProjection
带有投影层的 CLAP 音频模型(池化输出之上的线性层)。
示例: 使用 ClapAudioModelWithProjection
计算音频嵌入。
import { AutoProcessor, ClapAudioModelWithProjection, read_audio } from '@huggingface/transformers';
// Load processor and audio model
const processor = await AutoProcessor.from_pretrained('Xenova/clap-htsat-unfused');
const audio_model = await ClapAudioModelWithProjection.from_pretrained('Xenova/clap-htsat-unfused');
// Read audio and run processor
const audio = await read_audio('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cat_meow.wav');
const audio_inputs = await processor(audio);
// Compute embeddings
const { audio_embeds } = await audio_model(audio_inputs);
// Tensor {
// dims: [ 1, 512 ],
// type: 'float32',
// data: Float32Array(512) [ ... ],
// size: 512
// }
Kind: models
的静态类 models
ClapAudioModelWithProjection.from_pretrained() : <code> * </code>
类型:ClapAudioModelWithProjection
的静态方法
models.VitsModel
完整的 VITS 模型,用于文本到语音合成。
示例: 使用 VitsModel
从文本生成语音。
import { AutoTokenizer, VitsModel } from '@huggingface/transformers';
// Load the tokenizer and model
const tokenizer = await AutoTokenizer.from_pretrained('Xenova/mms-tts-eng');
const model = await VitsModel.from_pretrained('Xenova/mms-tts-eng');
// Run tokenization
const inputs = tokenizer('I love transformers');
// Generate waveform
const { waveform } = await model(inputs);
// Tensor {
// dims: [ 1, 35328 ],
// type: 'float32',
// data: Float32Array(35328) [ ... ],
// size: 35328,
// }
Kind: models
的静态类 models
vitsModel._call(model_inputs) ⇒ <code> Promise. < VitsModelOutput > </code>
在新输入上调用模型。
类型:VitsModel
的实例方法
返回值:Promise.<VitsModelOutput>
- VITS 模型的输出。
参数 | 类型 | 描述 |
---|---|---|
model_inputs | Object(对象) | 模型的输入。 |
models.SegformerModel
裸 SegFormer 编码器 (Mix-Transformer),输出原始隐藏状态,没有任何特定的头部。
Kind: models
的静态类 models
models.SegformerForImageClassification
带有图像分类头的 SegFormer 模型 transformer(最终隐藏状态之上的线性层),例如用于 ImageNet。
Kind: models
的静态类 models
models.SegformerForSemanticSegmentation
带有全 MLP 解码头的 SegFormer 模型 transformer,例如用于 ADE20k、CityScapes。
Kind: models
的静态类 models
models.StableLmModel
裸 StableLm 模型 transformer,输出原始隐藏状态,没有任何特定的头部。
Kind: models
的静态类 models
models.StableLmForCausalLM
带有用于因果语言建模 (带过去信息) 的 language modeling
头的 StableLm 模型。
Kind: models
的静态类 models
models.EfficientNetModel
裸 EfficientNet 模型,输出原始特征,没有任何特定的头部。
Kind: models
的静态类 models
models.EfficientNetForImageClassification
带有图像分类头的 EfficientNet 模型(池化特征之上的线性层)。
Kind: models
的静态类 models
efficientNetForImageClassification._call(model_inputs)
类型:EfficientNetForImageClassification
的实例方法
参数 | 类型 |
---|---|
model_inputs | 任意 |
models.MusicgenModel
裸 Musicgen 解码器模型,输出原始隐藏状态,没有任何特定的头部。
Kind: models
的静态类 models
models.MusicgenForCausalLM
带有语言建模头的 MusicGen 解码器模型。
Kind: models
的静态类 models
models.MusicgenForConditionalGeneration
带有文本编码器、音频编码器和 Musicgen 解码器的复合 MusicGen 模型,用于执行带有一个或两个文本和音频提示的音乐生成任务。
示例: 使用 Xenova/musicgen-small
从文本生成音乐。
import { AutoTokenizer, MusicgenForConditionalGeneration } from '@huggingface/transformers';
// Load tokenizer and model
const tokenizer = await AutoTokenizer.from_pretrained('Xenova/musicgen-small');
const model = await MusicgenForConditionalGeneration.from_pretrained(
'Xenova/musicgen-small', { dtype: 'fp32' }
);
// Prepare text input
const prompt = '80s pop track with bassy drums and synth';
const inputs = tokenizer(prompt);
// Generate audio
const audio_values = await model.generate({
...inputs,
max_new_tokens: 512,
do_sample: true,
guidance_scale: 3,
});
// (Optional) Write the output to a WAV file
import wavefile from 'wavefile';
import fs from 'fs';
const wav = new wavefile.WaveFile();
wav.fromScratch(1, model.config.audio_encoder.sampling_rate, '32f', audio_values.data);
fs.writeFileSync('musicgen_out.wav', wav.toBuffer());
Kind: models
的静态类 models
- .MusicgenForConditionalGeneration
._apply_and_filter_by_delay_pattern_mask(outputs)
⇒Tensor
.generate(options)
⇒Promise.<(ModelOutput|Tensor)>
musicgenForConditionalGeneration._apply_and_filter_by_delay_pattern_mask(outputs) ⇒ <code> Tensor </code>
将模式掩码应用于最终 ID,然后在单个步骤中通过过滤 pad token id 来恢复模式延迟掩码。
类型:MusicgenForConditionalGeneration
的实例方法
返回:Tensor
- 已过滤的输出张量。
参数 | 类型 | 描述 |
---|---|---|
outputs | Tensor | 来自模型的输出张量。 |
musicgenForConditionalGeneration.generate(options) ⇒ <code> Promise. < (ModelOutput|Tensor) > </code>
为带有语言建模头的模型生成 token id 序列。
类型:MusicgenForConditionalGeneration
的实例方法
返回值: Promise.<(ModelOutput|Tensor)>
- 模型的输出,可以包含生成的 token id、attention 和 scores。
参数 | 类型 |
---|---|
options(选项) | * |
models.MobileNetV1Model
裸 MobileNetV1 模型,输出原始隐藏状态,顶部没有任何特定的头。
Kind: models
的静态类 models
models.MobileNetV1ForImageClassification
带有图像分类头的 MobileNetV1 模型(池化特征顶部的线性层),例如用于 ImageNet。
Kind: models
的静态类 models
mobileNetV1ForImageClassification._call(model_inputs)
类型:MobileNetV1ForImageClassification
的实例方法
参数 | 类型 |
---|---|
model_inputs | 任意 |
models.MobileNetV2Model
裸 MobileNetV2 模型,输出原始隐藏状态,顶部没有任何特定的头。
Kind: models
的静态类 models
models.MobileNetV2ForImageClassification
带有图像分类头的 MobileNetV2 模型(池化特征顶部的线性层),例如用于 ImageNet。
Kind: models
的静态类 models
mobileNetV2ForImageClassification._call(model_inputs)
类型:MobileNetV2ForImageClassification
的实例方法
参数 | 类型 |
---|---|
model_inputs | 任意 |
models.MobileNetV3Model
裸 MobileNetV3 模型,输出原始隐藏状态,顶部没有任何特定的头。
Kind: models
的静态类 models
models.MobileNetV3ForImageClassification
带有图像分类头的 MobileNetV3 模型(池化特征顶部的线性层),例如用于 ImageNet。
Kind: models
的静态类 models
mobileNetV3ForImageClassification._call(model_inputs)
类型:MobileNetV3ForImageClassification
的实例方法
参数 | 类型 |
---|---|
model_inputs | 任意 |
models.MobileNetV4Model
裸 MobileNetV4 模型,输出原始隐藏状态,顶部没有任何特定的头。
Kind: models
的静态类 models
models.MobileNetV4ForImageClassification
带有图像分类头的 MobileNetV4 模型(池化特征顶部的线性层),例如用于 ImageNet。
Kind: models
的静态类 models
mobileNetV4ForImageClassification._call(model_inputs)
类型:MobileNetV4ForImageClassification
的实例方法
参数 | 类型 |
---|---|
model_inputs | 任意 |
models.DecisionTransformerModel
该模型构建于 GPT2 架构之上,用于在离线 RL 设置中执行动作的自回归预测。更多细节请参考论文:https://arxiv.org/abs/2106.01345
Kind: models
的静态类 models
models.MultiModalityCausalLM
Kind: models
的静态类 models
new MultiModalityCausalLM(...args)
参数 | 类型 |
---|---|
...args | * |
multiModalityCausalLM.generate(options)
类型:MultiModalityCausalLM
的实例方法
参数 | 类型 |
---|---|
options(选项) | * |
multiModalityCausalLM.generate_images(options)
类型:MultiModalityCausalLM
的实例方法
参数 | 类型 |
---|---|
options(选项) | * |
models.MgpstrForSceneTextRecognition
MGP-STR 模型转换器,顶部带有三个分类头(三个 A^3 模块和变压器编码器输出顶部的三个线性层),用于场景文本识别 (STR)。
Kind: models
的静态类 models
mgpstrForSceneTextRecognition._call(model_inputs)
类型:MgpstrForSceneTextRecognition
的实例方法
参数 | 类型 |
---|---|
model_inputs | 任意 |
models.PatchTSTModel
裸 PatchTST 模型,输出原始隐藏状态,没有任何特定的头。
Kind: models
的静态类 models
models.PatchTSTForPrediction
用于预测的 PatchTST 模型。
Kind: models
的静态类 models
models.PatchTSMixerModel
裸 PatchTSMixer 模型,输出原始隐藏状态,没有任何特定的头。
Kind: models
的静态类 models
models.PatchTSMixerForPrediction
用于预测的 PatchTSMixer 模型。
Kind: models
的静态类 models
models.MimiEncoderOutput
Kind: models
的静态类 models
new MimiEncoderOutput(output)
参数 | 类型 | 描述 |
---|---|---|
output(输出) | Object(对象) | 模型的输出。 |
output.audio_codes | Tensor | 离散代码嵌入,形状为 |
models.MimiDecoderOutput
Kind: models
的静态类 models
new MimiDecoderOutput(output)
参数 | 类型 | 描述 |
---|---|---|
output(输出) | Object(对象) | 模型的输出。 |
output.audio_values | Tensor | 解码后的音频值,形状为 |
models.MimiModel
Mimi 神经音频编解码模型。
Kind: models
的静态类 models
- .MimiModel
.encode(inputs)
⇒Promise.<MimiEncoderOutput>
.decode(inputs)
⇒Promise.<MimiDecoderOutput>
mimiModel.encode(inputs) ⇒ <code> Promise. < MimiEncoderOutput > </code>
将输入的音频波形编码为离散代码。
类型:MimiModel
的实例方法
返回值:Promise.<MimiEncoderOutput>
- 形状为 (batch_size, num_codebooks, sequence_length)
的输出张量。
参数 | 类型 | 描述 |
---|---|---|
inputs(输入) | Object(对象) | 模型输入 |
[inputs.input_values] | Tensor | 输入音频波形的浮点数值,形状为 |
mimiModel.decode(inputs) ⇒ <code> Promise. < MimiDecoderOutput > </code>
将给定的帧解码为输出音频波形。
类型:MimiModel
的实例方法
返回值:Promise.<MimiDecoderOutput>
- 形状为 (batch_size, num_channels, sequence_length)
的输出张量。
参数 | 类型 | 描述 |
---|---|---|
inputs(输入) | MimiEncoderOutput | 编码后的音频代码。 |
models.DacEncoderOutput
Kind: models
的静态类 models
new DacEncoderOutput(output)
参数 | 类型 | 描述 |
---|---|---|
output(输出) | Object(对象) | 模型的输出。 |
output.audio_codes | Tensor | 离散代码嵌入,形状为 |
models.DacDecoderOutput
Kind: models
的静态类 models
new DacDecoderOutput(output)
参数 | 类型 | 描述 |
---|---|---|
output(输出) | Object(对象) | 模型的输出。 |
output.audio_values | Tensor | 解码后的音频值,形状为 |
models.DacModel
DAC (Descript Audio Codec) 模型。
Kind: models
的静态类 models
- .DacModel
.encode(inputs)
⇒Promise.<DacEncoderOutput>
.decode(inputs)
⇒Promise.<DacDecoderOutput>
dacModel.encode(inputs) ⇒ <code> Promise. < DacEncoderOutput > </code>
将输入的音频波形编码为离散代码。
类型:DacModel
的实例方法
返回值:Promise.<DacEncoderOutput>
- 形状为 (batch_size, num_codebooks, sequence_length)
的输出张量。
参数 | 类型 | 描述 |
---|---|---|
inputs(输入) | Object(对象) | 模型输入 |
[inputs.input_values] | Tensor | 输入音频波形的浮点数值,形状为 |
dacModel.decode(inputs) ⇒ <code> Promise. < DacDecoderOutput > </code>
将给定的帧解码为输出音频波形。
类型:DacModel
的实例方法
返回值:Promise.<DacDecoderOutput>
- 形状为 (batch_size, num_channels, sequence_length)
的输出张量。
参数 | 类型 | 描述 |
---|---|---|
inputs(输入) | DacEncoderOutput | 编码后的音频代码。 |
models.SnacModel
SNAC (多尺度神经音频编解码器) 模型。
Kind: models
的静态类 models
- .SnacModel
.encode(inputs)
⇒Promise.<Record<string, Tensor>>
.decode(inputs)
⇒Promise.<{audio_values: Tensor}>
snacModel.encode(inputs) ⇒ <code> Promise. < Record < string, Tensor > > </code>
将输入的音频波形编码为离散代码。
类型:SnacModel
的实例方法
返回值:Promise.<Record<string, Tensor>>
- 形状为 (batch_size, num_codebooks, sequence_length)
的输出张量。
参数 | 类型 | 描述 |
---|---|---|
inputs(输入) | Object(对象) | 模型输入 |
[inputs.input_values] | Tensor | 输入音频波形的浮点数值,形状为 |
snacModel.decode(inputs) ⇒ <code> Promise. < {audio_values: Tensor} > </code>
将给定的帧解码为输出音频波形。
类型:SnacModel
的实例方法
返回值:Promise.<{audio_values: Tensor}>
- 形状为 (batch_size, num_channels, sequence_length)
的输出张量。
参数 | 类型 | 描述 |
---|---|---|
inputs(输入) | Record.<string, Tensor> | 编码后的音频代码。 |
models.PretrainedMixin
所有 AutoModel 的基类。包含 from_pretrained
函数,用于实例化预训练模型。
Kind: models
的静态类 models
- .PretrainedMixin
- instance
- static
pretrainedMixin.MODEL_CLASS_MAPPINGS : <code> * </code>
从模型类型到模型类的映射。
类型:PretrainedMixin
的实例属性
pretrainedMixin.BASE_IF_FAIL
如果模型类型在映射中未找到,是否尝试实例化基类 (PretrainedModel
)。
类型:PretrainedMixin
的实例属性
PretrainedMixin.from_pretrained() : <code> * </code>
类型:PretrainedMixin
的静态方法
models.AutoModel
辅助类,用于使用 from_pretrained
函数实例化预训练模型。所选模型类由模型配置中指定的类型决定。
Kind: models
的静态类 models
new AutoModel()
示例
let model = await AutoModel.from_pretrained('Xenova/bert-base-uncased');
autoModel.MODEL_CLASS_MAPPINGS : <code> * </code>
类型:AutoModel
的实例属性
models.AutoModelForSequenceClassification
辅助类,用于使用 from_pretrained
函数实例化预训练序列分类模型。所选模型类由模型配置中指定的类型决定。
Kind: models
的静态类 models
new AutoModelForSequenceClassification()
示例
let model = await AutoModelForSequenceClassification.from_pretrained('Xenova/distilbert-base-uncased-finetuned-sst-2-english');
models.AutoModelForTokenClassification
辅助类,用于使用 from_pretrained
函数实例化预训练 token 分类模型。所选模型类由模型配置中指定的类型决定。
Kind: models
的静态类 models
new AutoModelForTokenClassification()
示例
let model = await AutoModelForTokenClassification.from_pretrained('Xenova/distilbert-base-multilingual-cased-ner-hrl');
models.AutoModelForSeq2SeqLM
辅助类,用于使用 from_pretrained
函数实例化预训练序列到序列模型。所选模型类由模型配置中指定的类型决定。
Kind: models
的静态类 models
new AutoModelForSeq2SeqLM()
示例
let model = await AutoModelForSeq2SeqLM.from_pretrained('Xenova/t5-small');
models.AutoModelForSpeechSeq2Seq
辅助类,用于使用 from_pretrained
函数实例化预训练序列到序列语音转文本模型。所选模型类由模型配置中指定的类型决定。
Kind: models
的静态类 models
new AutoModelForSpeechSeq2Seq()
示例
let model = await AutoModelForSpeechSeq2Seq.from_pretrained('openai/whisper-tiny.en');
models.AutoModelForTextToSpectrogram
用于实例化带有 from_pretrained
函数的预训练序列到序列文本到频谱图模型的辅助类。所选模型类由模型配置中指定的类型确定。
Kind: models
的静态类 models
new AutoModelForTextToSpectrogram()
示例
let model = await AutoModelForTextToSpectrogram.from_pretrained('microsoft/speecht5_tts');
models.AutoModelForTextToWaveform
用于实例化带有 from_pretrained
函数的预训练文本到波形模型的辅助类。所选模型类由模型配置中指定的类型确定。
Kind: models
的静态类 models
new AutoModelForTextToWaveform()
示例
let model = await AutoModelForTextToSpectrogram.from_pretrained('facebook/mms-tts-eng');
models.AutoModelForCausalLM
用于实例化带有 from_pretrained
函数的预训练因果语言模型的辅助类。所选模型类由模型配置中指定的类型确定。
Kind: models
的静态类 models
new AutoModelForCausalLM()
示例
let model = await AutoModelForCausalLM.from_pretrained('Xenova/gpt2');
models.AutoModelForMaskedLM
用于实例化带有 from_pretrained
函数的预训练掩码语言模型的辅助类。所选模型类由模型配置中指定的类型确定。
Kind: models
的静态类 models
new AutoModelForMaskedLM()
示例
let model = await AutoModelForMaskedLM.from_pretrained('Xenova/bert-base-uncased');
models.AutoModelForQuestionAnswering
用于实例化带有 from_pretrained
函数的预训练问答模型的辅助类。所选模型类由模型配置中指定的类型确定。
Kind: models
的静态类 models
new AutoModelForQuestionAnswering()
示例
let model = await AutoModelForQuestionAnswering.from_pretrained('Xenova/distilbert-base-cased-distilled-squad');
models.AutoModelForVision2Seq
用于实例化带有 from_pretrained
函数的预训练视觉到序列模型的辅助类。所选模型类由模型配置中指定的类型确定。
Kind: models
的静态类 models
new AutoModelForVision2Seq()
示例
let model = await AutoModelForVision2Seq.from_pretrained('Xenova/vit-gpt2-image-captioning');
models.AutoModelForImageClassification
用于实例化带有 from_pretrained
函数的预训练图像分类模型的辅助类。所选模型类由模型配置中指定的类型确定。
Kind: models
的静态类 models
new AutoModelForImageClassification()
示例
let model = await AutoModelForImageClassification.from_pretrained('Xenova/vit-base-patch16-224');
models.AutoModelForImageSegmentation
用于实例化带有 from_pretrained
函数的预训练图像分割模型的辅助类。所选模型类由模型配置中指定的类型确定。
Kind: models
的静态类 models
new AutoModelForImageSegmentation()
示例
let model = await AutoModelForImageSegmentation.from_pretrained('Xenova/detr-resnet-50-panoptic');
models.AutoModelForSemanticSegmentation
用于实例化带有 from_pretrained
函数的预训练图像分割模型的辅助类。所选模型类由模型配置中指定的类型确定。
Kind: models
的静态类 models
new AutoModelForSemanticSegmentation()
示例
let model = await AutoModelForSemanticSegmentation.from_pretrained('nvidia/segformer-b3-finetuned-cityscapes-1024-1024');
models.AutoModelForUniversalSegmentation
用于实例化带有 from_pretrained
函数的预训练通用图像分割模型的辅助类。所选模型类由模型配置中指定的类型确定。
Kind: models
的静态类 models
new AutoModelForUniversalSegmentation()
示例
let model = await AutoModelForUniversalSegmentation.from_pretrained('hf-internal-testing/tiny-random-MaskFormerForInstanceSegmentation');
models.AutoModelForObjectDetection
用于实例化带有 from_pretrained
函数的预训练目标检测模型的辅助类。所选模型类由模型配置中指定的类型确定。
Kind: models
的静态类 models
new AutoModelForObjectDetection()
示例
let model = await AutoModelForObjectDetection.from_pretrained('Xenova/detr-resnet-50');
models.AutoModelForMaskGeneration
用于实例化带有 from_pretrained
函数的预训练掩码生成模型的辅助类。所选模型类由模型配置中指定的类型确定。
Kind: models
的静态类 models
new AutoModelForMaskGeneration()
示例
let model = await AutoModelForMaskGeneration.from_pretrained('Xenova/sam-vit-base');
models.Seq2SeqLMOutput
Kind: models
的静态类 models
new Seq2SeqLMOutput(output)
参数 | 类型 | 描述 |
---|---|---|
output(输出) | Object(对象) | 模型的输出。 |
output.logits | Tensor | 模型的输出 logits。 |
output.past_key_values | Tensor | 表示模型先前状态的键/值对张量。 |
output.encoder_outputs | Tensor | 序列到序列模型中编码器的输出。 |
[output.decoder_attentions] | Tensor | 解码器的注意力权重,在注意力 softmax 之后,用于计算自注意力头中的加权平均值。 |
[output.cross_attentions] | Tensor | 解码器交叉注意力层的注意力权重,在注意力 softmax 之后,用于计算交叉注意力头中的加权平均值。 |
models.SequenceClassifierOutput
句子分类模型输出的基类。
Kind: models
的静态类 models
new SequenceClassifierOutput(output)
参数 | 类型 | 描述 |
---|---|---|
output(输出) | Object(对象) | 模型的输出。 |
output.logits | Tensor | 分类(或回归,如果 config.num_labels==1)得分(在 SoftMax 之前)。 |
[output.attentions] | Record.<string, Tensor> | `torch.FloatTensor` 对象(每层一个),形状为 `(batch_size, num_heads, sequence_length, sequence_length)`。注意力 softmax 之后的注意力权重,用于计算自注意力头中的加权平均值。 |
models.XVectorOutput
XVector 模型输出的基类。
Kind: models
的静态类 models
new XVectorOutput(output)
参数 | 类型 | 描述 |
---|---|---|
output(输出) | Object(对象) | 模型的输出。 |
output.logits | Tensor | AMSoftmax 之前的分类隐藏状态,形状为 |
output.embeddings | Tensor | 用于基于向量相似度检索的语句嵌入,形状为 |
models.TokenClassifierOutput
token 分类模型输出的基类。
Kind: models
的静态类 models
new TokenClassifierOutput(output)
参数 | 类型 | 描述 |
---|---|---|
output(输出) | Object(对象) | 模型的输出。 |
output.logits | Tensor | 分类分数(SoftMax 之前)。 |
models.MaskedLMOutput
masked language model 输出的基类。
Kind: models
的静态类 models
new MaskedLMOutput(output)
参数 | 类型 | 描述 |
---|---|---|
output(输出) | Object(对象) | 模型的输出。 |
output.logits | Tensor | 语言建模头的预测分数(每个词汇标记在 SoftMax 之前的分数)。 |
models.QuestionAnsweringModelOutput
问题回答模型输出的基类。
Kind: models
的静态类 models
new QuestionAnsweringModelOutput(output)
参数 | 类型 | 描述 |
---|---|---|
output(输出) | Object(对象) | 模型的输出。 |
output.start_logits | Tensor | 跨度开始分数(SoftMax 之前)。 |
output.end_logits | Tensor | 跨度结束分数(SoftMax 之前)。 |
models.CausalLMOutput
因果语言模型(或自回归)输出的基类。
Kind: models
的静态类 models
new CausalLMOutput(output)
参数 | 类型 | 描述 |
---|---|---|
output(输出) | Object(对象) | 模型的输出。 |
output.logits | Tensor | 语言建模头的预测分数(每个词汇标记在 softmax 之前的分数)。 |
models.CausalLMOutputWithPast
因果语言模型(或自回归)输出的基类。
Kind: models
的静态类 models
new CausalLMOutputWithPast(output)
参数 | 类型 | 描述 |
---|---|---|
output(输出) | Object(对象) | 模型的输出。 |
output.logits | Tensor | 语言建模头的预测分数(每个词汇标记在 softmax 之前的分数)。 |
output.past_key_values | Tensor | 包含预先计算的隐藏状态(自注意力模块中的键和值),可以用于(参见 |
models.ImageMattingOutput
Kind: models
的静态类 models
new ImageMattingOutput(output)
参数 | 类型 | 描述 |
---|---|---|
output(输出) | Object(对象) | 模型的输出。 |
output.alphas | Tensor | 估计的 alpha 值,形状为 |
models.VitsModelOutput
描述 VITS 模型的输出。
Kind: models
的静态类 models
new VitsModelOutput(output)
参数 | 类型 | 描述 |
---|---|---|
output(输出) | Object(对象) | 模型的输出。 |
output.waveform | Tensor | 模型预测的最终音频波形,形状为 |
output.spectrogram | Tensor | 在 flow 模型输出端预测的 log-mel 频谱图。此频谱图被传递到 Hi-Fi GAN 解码器模型以获得最终音频波形。 |
models~cumsum_masked_fill(attention_mask) ⇒ <code> Object </code>
执行以下操作的辅助函数
x = attention_mask.long().cumsum(-1) - 1
x.masked_fill_(attention_mask == 0, 1)
类型:models
的内部方法
参数 | 类型 |
---|---|
attention_mask | Tensor |
models~createPositionIds()
如果模型支持提供 position_ids,我们会为批次生成动态创建 position_ids,方法是计算注意力掩码沿序列长度维度的累积和。
等效于
position_ids = attention_mask.long().cumsum(-1) - 1
position_ids.masked_fill_(attention_mask == 0, 1)
if past_key_values:
position_ids = position_ids[:, -input_ids.shape[1] :]
类型:models
的内部方法
models~SamModelInputs : <code> Object </code>
包含模型输入的对象。
类型:models
的内部类型定义
属性
名称 | 类型 | 描述 |
---|---|---|
pixel_values | Tensor | 像素值,作为形状为 |
[input_points] | Tensor | 输入 2D 空间点,形状为 |
[input_labels] | Tensor | 点的输入标签,作为形状为
|
[input_boxes] | Tensor | 输入边界框,形状为 |
[image_embeddings] | Tensor | mask 解码器使用的图像嵌入。 |
[image_positional_embeddings] | Tensor | mask 解码器使用的图像位置嵌入。 |
models~SpeechOutput : <code> Object </code>
类型:models
的内部类型定义
属性
名称 | 类型 | 描述 |
---|---|---|
[spectrogram] | Tensor | 预测的 log-mel 频谱图,形状为 |
[waveform] | Tensor | 预测的波形,形状为 |
[cross_attentions] | Tensor | 解码器的交叉注意力层的输出,形状为 |
< > 在 GitHub 上更新