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!'
- 模型
- 静态
- .PreTrainedModel
new PreTrainedModel(config, sessions, configs)
- 实例
.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)
- 静态
.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
- .Qwen3PreTrainedModel
- .Qwen3Model
- .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
- 实例
- 静态
- .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
- 内部
~cumsum_masked_fill(attention_mask)
⇒Object
~createPositionIds()
~SamModelInputs
:Object
~SpeechOutput
:Object
- 静态
models.PreTrainedModel
预训练模型的基类,提供模型配置和 ONNX 会话。
类型: models
的静态类
- .PreTrainedModel
new PreTrainedModel(config, sessions, configs)
- 实例
.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)
- 静态
.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>
类型: PreTrainedModel
的实例属性
preTrainedModel.generation_config ⇒ <code> GenerationConfig </code> | <code> null </code>
获取模型的生成配置,如果存在。
类型: PreTrainedModel
的实例属性
返回: GenerationConfig
| null
- 如果存在,则为模型的生成配置;否则为 null
。
preTrainedModel.dispose() ⇒ <code> Promise. < Array < unknown > > </code>
释放所有在推理过程中创建的 ONNX 会话。
类型: PreTrainedModel
的实例方法
返回: Promise.<Array<unknown>>
- 一个 Promise 数组,每个 Promise 对应一个正在被释放的 ONNX 会话。
待办
preTrainedModel._call(model_inputs) ⇒ <code> Promise. < Object > </code>
使用提供的输入运行模型
类型: PreTrainedModel
的实例方法
返回: Promise.<Object>
- 包含输出张量的对象
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 包含输入张量的对象 |
preTrainedModel.forward(model_inputs) ⇒ <code> Promise. < Object > </code>
预训练模型的前向方法。如果子类未重写,将根据模型类型选择正确的前向方法。
类型: PreTrainedModel
的实例方法
返回: Promise.<Object>
- 来自模型的输出数据,其格式在 ONNX 模型中指定。
抛出:
Error
此方法必须在子类中实现。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入数据,其格式在 ONNX 模型中指定。 |
preTrainedModel._get_logits_warper(generation_config) ⇒ <code> LogitsProcessorList </code>
此函数返回一个 [LogitsProcessorList
] 列表对象,其中包含用于多项式采样的所有相关 [LogitsWarper
] 实例。
类型: PreTrainedModel
的实例方法
返回: LogitsProcessorList
- generation_config
参数量 | 类型 | 描述 |
---|---|---|
generation_config | GenerationConfig | 生成配置。 |
preTrainedModel._prepare_generation_config(generation_config, kwargs) ⇒ <code> GenerationConfig </code>
此函数将多个生成配置合并在一起,形成一个最终的生成配置,供模型用于文本生成。它首先创建一个空的 GenerationConfig
对象,然后将模型自身的 generation_config
属性应用到它上面。最后,如果在参数中传入了一个 generation_config
对象,它会用传入的配置对象中的属性覆盖最终配置中相应的属性。
类型: PreTrainedModel
的实例方法
返回: GenerationConfig
- 用于模型文本生成的最终生成配置对象。
参数量 | 类型 | 描述 |
---|---|---|
generation_config | GenerationConfig | null | 一个包含生成参数的 |
kwargs | Object | 用于替代 |
preTrainedModel._get_stopping_criteria(generation_config, [stopping_criteria])
类型: PreTrainedModel
的实例方法
参数量 | 类型 | 默认 |
---|---|---|
generation_config | GenerationConfig | |
[stopping_criteria] | StoppingCriteriaList |
|
preTrainedModel._validate_model_class()
确认模型类与生成兼容。如果不兼容,则抛出一个指向正确使用类的异常。
类型: PreTrainedModel
的实例方法
preTrainedModel._update_model_kwargs_for_generation(inputs) ⇒ <code> Object </code>
类型: PreTrainedModel
的实例方法
返回: Object
- 用于下一次生成迭代的更新后的模型输入。
参数量 | 类型 |
---|---|
输入 | Object |
inputs.generated_input_ids | 数组.<数组<大整数>> |
inputs.outputs | Object |
inputs.model_inputs | Object |
inputs.is_encoder_decoder | boolean |
preTrainedModel._prepare_model_inputs(params) ⇒ <code> Object </code>
此函数提取用于生成的模型特定 inputs
。
类型: PreTrainedModel
的实例方法
返回: Object
- 用于生成的模型特定输入。
参数量 | 类型 | 默认 |
---|---|---|
params | Object | |
[params.inputs] | 张量 |
|
[params.bos_token_id] | 数字 |
|
[params.model_kwargs] | Record.<string, (Tensor|Array<number>)> |
preTrainedModel._prepare_decoder_input_ids_for_generation(param0)
为编码器-解码器模型的生成准备 decoder_input_ids
类型: PreTrainedModel
的实例方法
参数量 | 类型 |
---|---|
param0 | * |
preTrainedModel.generate(options) ⇒ <code> Promise. < (ModelOutput|Tensor) > </code>
为具有语言建模头的模型生成词元 ID 序列。
类型: PreTrainedModel
的实例方法
返回: Promise.<(ModelOutput|Tensor)>
- 模型的输出,可以包含生成的词元 ID、注意力分数和得分。
参数量 | 类型 |
---|---|
选项 | * |
preTrainedModel.getPastKeyValues(decoderResults, pastKeyValues) ⇒ <code> Object </code>
从给定的解码器结果对象中返回一个包含过去键值的对象。
类型: PreTrainedModel
的实例方法
返回: Object
- 一个包含过去键值的对象。
参数量 | 类型 | 描述 |
---|---|---|
decoderResults | Object | 解码器结果对象。 |
pastKeyValues | Object | 先前的过去键值。 |
preTrainedModel.getAttentions(model_output) ⇒ <code> * </code>
从给定的模型输出对象中返回一个包含注意力的对象。
类型: PreTrainedModel
的实例方法
返回: *
- 一个包含注意力的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_output | Object | 模型的输出。 |
preTrainedModel.addPastKeyValues(decoderFeeds, pastKeyValues)
将过去键值添加到解码器输入对象。如果 pastKeyValues 为 null,则为过去键值创建新的张量。
类型: PreTrainedModel
的实例方法
参数量 | 类型 | 描述 |
---|---|---|
decoderFeeds | Object | 要添加过去键值的解码器输入对象。 |
pastKeyValues | Object | 一个包含过去键值的对象。 |
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 | 字符串 | 预训练模型的名称或路径。可以是
|
选项 | * | 加载模型的附加选项。 |
models.BaseModelOutput
模型输出的基类,可能包含隐藏状态和注意力。
类型: models
的静态类
new BaseModelOutput(output)
参数量 | 类型 | 描述 |
---|---|---|
输出 | Object | 模型的输出。 |
output.last_hidden_state | 张量 | 模型最后一层输出的隐藏状态序列。 |
[output.hidden_states] | 张量 | 模型在每个层输出的隐藏状态以及可选的初始嵌入输出。 |
[output.attentions] | 张量 | 注意力 softmax 后的注意力权重,用于计算自注意力头中的加权平均值。 |
models.BertForMaskedLM
BertForMaskedLM 是一个表示用于掩码语言建模的 BERT 模型的类。
类型: models
的静态类
bertForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
类型: BertForMaskedLM
的实例方法
返回: Promise.<MaskedLMOutput>
- 一个包含模型掩码语言建模输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.BertForSequenceClassification
BertForSequenceClassification 是一个表示用于序列分类的 BERT 模型的类。
类型: models
的静态类
bertForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
类型: BertForSequenceClassification
的实例方法
返回: Promise.<SequenceClassifierOutput>
- 一个包含模型序列分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.BertForTokenClassification
BertForTokenClassification 是一个表示用于词元分类的 BERT 模型的类。
类型: models
的静态类
bertForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
类型: BertForTokenClassification
的实例方法
返回: Promise.<TokenClassifierOutput>
- 一个包含模型词元分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.BertForQuestionAnswering
BertForQuestionAnswering 是一个表示用于问答的 BERT 模型的类。
类型: models
的静态类
bertForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
种类: BertForQuestionAnswering
的实例方法
返回: Promise.<QuestionAnsweringModelOutput>
- 包含模型问答任务输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.RoFormerModel
基础的 RoFormer 模型 Transformer,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.RoFormerForMaskedLM
顶部带有一个语言建模
头的 RoFormer 模型。
类型: models
的静态类
roFormerForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
种类: RoFormerForMaskedLM
的实例方法
返回: Promise.<MaskedLMOutput>
- 一个包含模型掩码语言建模输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.RoFormerForSequenceClassification
顶部带有序列分类/回归头的 RoFormer Transformer 模型(在池化输出之上有一个线性层)
类型: models
的静态类
roFormerForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
种类: RoFormerForSequenceClassification
的实例方法
返回: Promise.<SequenceClassifierOutput>
- 一个包含模型序列分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.RoFormerForTokenClassification
顶部带有词元分类头的 RoFormer 模型(在隐藏状态输出之上有一个线性层),例如用于命名实体识别(NER)任务。
类型: models
的静态类
roFormerForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
种类: RoFormerForTokenClassification
的实例方法
返回: Promise.<TokenClassifierOutput>
- 一个包含模型词元分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.RoFormerForQuestionAnswering
顶部带有片段分类头的 RoFormer 模型,用于像 SQuAD 这样的抽取式问答任务(在隐藏状态输出之上有一系列线性层,用于计算片段开始 logits
和片段结束 logits
)。
类型: models
的静态类
roFormerForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
种类: RoFormerForQuestionAnswering
的实例方法
返回: Promise.<QuestionAnsweringModelOutput>
- 包含模型问答任务输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.ConvBertModel
基础的 ConvBERT 模型 Transformer,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.ConvBertForMaskedLM
顶部带有语言建模头的 ConvBERT 模型。
类型: models
的静态类
convBertForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
种类: ConvBertForMaskedLM
的实例方法
返回: Promise.<MaskedLMOutput>
- 一个包含模型掩码语言建模输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.ConvBertForSequenceClassification
顶部带有序列分类/回归头的 ConvBERT Transformer 模型(在池化输出之上有一个线性层)
类型: models
的静态类
convBertForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
种类: ConvBertForSequenceClassification
的实例方法
返回: Promise.<SequenceClassifierOutput>
- 一个包含模型序列分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.ConvBertForTokenClassification
顶部带有词元分类头的 ConvBERT 模型(在隐藏状态输出之上有一个线性层),例如用于命名实体识别(NER)任务。
类型: models
的静态类
convBertForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
种类: ConvBertForTokenClassification
的实例方法
返回: Promise.<TokenClassifierOutput>
- 一个包含模型词元分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.ConvBertForQuestionAnswering
顶部带有片段分类头的 ConvBERT 模型,用于像 SQuAD 这样的抽取式问答任务(在隐藏状态输出之上有一系列线性层,用于计算片段开始 logits
和片段结束 logits
)
类型: models
的静态类
convBertForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
种类: ConvBertForQuestionAnswering
的实例方法
返回: Promise.<QuestionAnsweringModelOutput>
- 包含模型问答任务输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.ElectraModel
基础的 Electra 模型 Transformer,输出原始的隐藏状态,顶部没有任何特定的头。与 BERT 模型相同,但如果隐藏大小和嵌入大小不同,则在嵌入层和编码器之间使用一个额外的线性层。
类型: models
的静态类
models.ElectraForMaskedLM
顶部带有语言建模头的 Electra 模型。
类型: models
的静态类
electraForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
种类: ElectraForMaskedLM
的实例方法
返回: Promise.<MaskedLMOutput>
- 一个包含模型掩码语言建模输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.ElectraForSequenceClassification
顶部带有序列分类/回归头的 ELECTRA Transformer 模型(在池化输出之上有一个线性层)
类型: models
的静态类
electraForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
种类: ElectraForSequenceClassification
的实例方法
返回: Promise.<SequenceClassifierOutput>
- 一个包含模型序列分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.ElectraForTokenClassification
顶部带有词元分类头的 Electra 模型。
类型: models
的静态类
electraForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
种类: ElectraForTokenClassification
的实例方法
返回: Promise.<TokenClassifierOutput>
- 一个包含模型词元分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.ElectraForQuestionAnswering
顶部带有片段分类头的 LECTRA 模型,用于像 SQuAD 这样的抽取式问答任务(在隐藏状态输出之上有一系列线性层,用于计算片段开始 logits
和片段结束 logits
)。
类型: models
的静态类
electraForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
种类: ElectraForQuestionAnswering
的实例方法
返回: Promise.<QuestionAnsweringModelOutput>
- 包含模型问答任务输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.CamembertModel
基础的 CamemBERT 模型 Transformer,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.CamembertForMaskedLM
顶部带有一个语言建模
头的 CamemBERT 模型。
类型: models
的静态类
camembertForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
种类: CamembertForMaskedLM
的实例方法
返回: Promise.<MaskedLMOutput>
- 一个包含模型掩码语言建模输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.CamembertForSequenceClassification
顶部带有序列分类/回归头的 CamemBERT Transformer 模型(在池化输出之上有一个线性层),例如用于 GLUE 任务。
类型: models
的静态类
camembertForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
种类: CamembertForSequenceClassification
的实例方法
返回: Promise.<SequenceClassifierOutput>
- 一个包含模型序列分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.CamembertForTokenClassification
顶部带有词元分类头的 CamemBERT 模型(在隐藏状态输出之上有一个线性层),例如用于命名实体识别(NER)任务。
类型: models
的静态类
camembertForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
种类: CamembertForTokenClassification
的实例方法
返回: Promise.<TokenClassifierOutput>
- 一个包含模型词元分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.CamembertForQuestionAnswering
顶部带有片段分类头的 CamemBERT 模型,用于抽取式问答任务
类型: models
的静态类
camembertForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
种类: CamembertForQuestionAnswering
的实例方法
返回: Promise.<QuestionAnsweringModelOutput>
- 包含模型问答任务输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.DebertaModel
基础的 DeBERTa 模型 Transformer,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.DebertaForMaskedLM
顶部带有一个语言建模
头的 DeBERTa 模型。
类型: models
的静态类
debertaForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
种类: DebertaForMaskedLM
的实例方法
返回: Promise.<MaskedLMOutput>
- 一个包含模型掩码语言建模输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.DebertaForSequenceClassification
顶部带有序列分类/回归头的 DeBERTa Transformer 模型(在池化输出之上有一个线性层)
类型: models
的静态类
debertaForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
种类: DebertaForSequenceClassification
的实例方法
返回: Promise.<SequenceClassifierOutput>
- 一个包含模型序列分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.DebertaForTokenClassification
顶部带有词元分类头的 DeBERTa 模型(在隐藏状态输出之上有一个线性层),例如用于命名实体识别(NER)任务。
类型: models
的静态类
debertaForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
种类: DebertaForTokenClassification
的实例方法
返回: Promise.<TokenClassifierOutput>
- 一个包含模型词元分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.DebertaForQuestionAnswering
顶部带有片段分类头的 DeBERTa 模型,用于像 SQuAD 这样的抽取式问答任务(在隐藏状态输出之上有一系列线性层,用于计算片段开始 logits
和片段结束 logits
)。
类型: models
的静态类
debertaForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
种类: DebertaForQuestionAnswering
的实例方法
返回: Promise.<QuestionAnsweringModelOutput>
- 包含模型问答任务输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.DebertaV2Model
基础的 DeBERTa-V2 模型 Transformer,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.DebertaV2ForMaskedLM
顶部带有一个语言建模
头的 DeBERTa-V2 模型。
类型: models
的静态类
debertaV2ForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
种类: DebertaV2ForMaskedLM
的实例方法
返回: Promise.<MaskedLMOutput>
- 一个包含模型掩码语言建模输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.DebertaV2ForSequenceClassification
顶部带有序列分类/回归头的 DeBERTa-V2 Transformer 模型(在池化输出之上有一个线性层)
类型: models
的静态类
debertaV2ForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
种类: DebertaV2ForSequenceClassification
的实例方法
返回: Promise.<SequenceClassifierOutput>
- 一个包含模型序列分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.DebertaV2ForTokenClassification
顶部带有词元分类头的 DeBERTa-V2 模型(在隐藏状态输出之上有一个线性层),例如用于命名实体识别(NER)任务。
类型: models
的静态类
debertaV2ForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
种类: DebertaV2ForTokenClassification
的实例方法
返回: Promise.<TokenClassifierOutput>
- 一个包含模型词元分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.DebertaV2ForQuestionAnswering
顶部带有片段分类头的 DeBERTa-V2 模型,用于像 SQuAD 这样的抽取式问答任务(在隐藏状态输出之上有一系列线性层,用于计算片段开始 logits
和片段结束 logits
)。
类型: models
的静态类
debertaV2ForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
种类: DebertaV2ForQuestionAnswering
的实例方法
返回: Promise.<QuestionAnsweringModelOutput>
- 包含模型问答任务输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.DistilBertForSequenceClassification
DistilBertForSequenceClassification 是一个表示用于序列分类的 DistilBERT 模型的类。
类型: models
的静态类
distilBertForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
种类: DistilBertForSequenceClassification
的实例方法
返回: Promise.<SequenceClassifierOutput>
- 一个包含模型序列分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.DistilBertForTokenClassification
DistilBertForTokenClassification 是一个表示用于词元分类的 DistilBERT 模型的类。
类型: models
的静态类
distilBertForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
种类: DistilBertForTokenClassification
的实例方法
返回: Promise.<TokenClassifierOutput>
- 一个包含模型词元分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.DistilBertForQuestionAnswering
DistilBertForQuestionAnswering 是一个表示用于问答任务的 DistilBERT 模型的类。
类型: models
的静态类
distilBertForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
种类: DistilBertForQuestionAnswering
的实例方法
返回: Promise.<QuestionAnsweringModelOutput>
- 包含模型问答任务输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.DistilBertForMaskedLM
DistilBertForMaskedLM 是一个表示用于掩码任务的 DistilBERT 模型的类。
类型: models
的静态类
distilBertForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
种类:DistilBertForMaskedLM
的实例方法
返回:Promise.<MaskedLMOutput>
- 返回的对象
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.EsmModel
基础的 ESM 模型转换器,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.EsmForMaskedLM
顶部带有语言建模
头的 ESM 模型。
类型: models
的静态类
esmForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
种类:EsmForMaskedLM
的实例方法
返回: Promise.<MaskedLMOutput>
- 一个包含模型掩码语言建模输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.EsmForSequenceClassification
ESM 模型转换器,顶部带有一个序列分类/回归头(在池化输出之上有一个线性层)
类型: models
的静态类
esmForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
种类:EsmForSequenceClassification
的实例方法
返回: Promise.<SequenceClassifierOutput>
- 一个包含模型序列分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.EsmForTokenClassification
顶部带有一个标记分类头的 ESM 模型(在隐藏状态输出之上有一个线性层),例如用于命名实体识别(NER)任务。
类型: models
的静态类
esmForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
种类:EsmForTokenClassification
的实例方法
返回: Promise.<TokenClassifierOutput>
- 一个包含模型词元分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.MobileBertForMaskedLM
MobileBertForMaskedLM 是一个表示用于掩码任务的 MobileBERT 模型的类。
类型: models
的静态类
mobileBertForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
种类:MobileBertForMaskedLM
的实例方法
返回:Promise.<MaskedLMOutput>
- 返回的对象
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.MobileBertForSequenceClassification
MobileBert 模型转换器,顶部带有一个序列分类/回归头(在池化输出之上有一个线性层)
类型: models
的静态类
mobileBertForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
种类:MobileBertForSequenceClassification
的实例方法
返回:Promise.<SequenceClassifierOutput>
- 返回的对象
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.MobileBertForQuestionAnswering
MobileBert 模型,顶部带有一个用于抽取式问答任务的跨度分类头
类型: models
的静态类
mobileBertForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
种类:MobileBertForQuestionAnswering
的实例方法
返回:Promise.<QuestionAnsweringModelOutput>
- 返回的对象
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.MPNetModel
基础的 MPNet 模型转换器,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.MPNetForMaskedLM
MPNetForMaskedLM 是一个表示用于掩码语言建模的 MPNet 模型的类。
类型: models
的静态类
mpNetForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
种类:MPNetForMaskedLM
的实例方法
返回: Promise.<MaskedLMOutput>
- 一个包含模型掩码语言建模输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.MPNetForSequenceClassification
MPNetForSequenceClassification 是一个表示用于序列分类的 MPNet 模型的类。
类型: models
的静态类
mpNetForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
种类:MPNetForSequenceClassification
的实例方法
返回: Promise.<SequenceClassifierOutput>
- 一个包含模型序列分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.MPNetForTokenClassification
MPNetForTokenClassification 是一个表示用于标记分类的 MPNet 模型的类。
类型: models
的静态类
mpNetForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
种类:MPNetForTokenClassification
的实例方法
返回: Promise.<TokenClassifierOutput>
- 一个包含模型词元分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.MPNetForQuestionAnswering
MPNetForQuestionAnswering 是一个表示用于问答任务的 MPNet 模型的类。
类型: models
的静态类
mpNetForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
种类:MPNetForQuestionAnswering
的实例方法
返回: Promise.<QuestionAnsweringModelOutput>
- 包含模型问答任务输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.T5ForConditionalGeneration
T5Model 是一个表示用于条件生成的 T5 模型的类。
类型: models
的静态类
models.LongT5PreTrainedModel
一个用于处理权重初始化以及提供下载和加载预训练模型的简单接口的抽象类。
类型: models
的静态类
models.LongT5Model
基础的 LONGT5 模型转换器,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.LongT5ForConditionalGeneration
顶部带有语言建模
头的 LONGT5 模型。
类型: models
的静态类
models.MT5ForConditionalGeneration
一个基于 MT5 架构的条件序列到序列模型的类。
类型: models
的静态类
models.BartModel
基础的 BART 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.BartForConditionalGeneration
带有语言建模头的 BART 模型。可用于摘要生成。
类型: models
的静态类
models.BartForSequenceClassification
顶部带有一个序列分类头的 Bart 模型(在池化输出之上有一个线性层)
类型: models
的静态类
bartForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
种类:BartForSequenceClassification
的实例方法
返回: Promise.<SequenceClassifierOutput>
- 一个包含模型序列分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.MBartModel
基础的 MBART 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.MBartForConditionalGeneration
带有语言建模头的 MBART 模型。在对预训练模型进行微调后,可用于摘要生成。
类型: models
的静态类
models.MBartForSequenceClassification
顶部带有一个序列分类头的 MBart 模型(在池化输出之上有一个线性层)。
类型: models
的静态类
mBartForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
种类:MBartForSequenceClassification
的实例方法
返回: Promise.<SequenceClassifierOutput>
- 一个包含模型序列分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.BlenderbotModel
基础的 Blenderbot 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.BlenderbotForConditionalGeneration
带有语言建模头的 Blenderbot 模型。可用于摘要生成。
类型: models
的静态类
models.BlenderbotSmallModel
基础的 BlenderbotSmall 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.BlenderbotSmallForConditionalGeneration
带有语言建模头的 BlenderbotSmall 模型。可用于摘要生成。
类型: models
的静态类
models.RobertaForMaskedLM
用于在 Roberta 模型上执行掩码语言建模的 RobertaForMaskedLM 类。
类型: models
的静态类
robertaForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
种类:RobertaForMaskedLM
的实例方法
返回:Promise.<MaskedLMOutput>
- 返回的对象
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.RobertaForSequenceClassification
用于在 Roberta 模型上执行序列分类的 RobertaForSequenceClassification 类。
类型: models
的静态类
robertaForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
种类:RobertaForSequenceClassification
的实例方法
返回:Promise.<SequenceClassifierOutput>
- 返回的对象
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.RobertaForTokenClassification
用于在 Roberta 模型上执行标记分类的 RobertaForTokenClassification 类。
类型: models
的静态类
robertaForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
种类:RobertaForTokenClassification
的实例方法
返回: Promise.<TokenClassifierOutput>
- 一个包含模型词元分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.RobertaForQuestionAnswering
用于在 Roberta 模型上执行问答任务的 RobertaForQuestionAnswering 类。
类型: models
的静态类
robertaForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
种类:RobertaForQuestionAnswering
的实例方法
返回:Promise.<QuestionAnsweringModelOutput>
- 返回的对象
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.XLMPreTrainedModel
一个用于处理权重初始化以及提供下载和加载预训练模型的简单接口的抽象类。
类型: models
的静态类
models.XLMModel
基础的 XLM 模型转换器,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.XLMWithLMHeadModel
顶部带有语言建模头的 XLM 模型转换器(线性层权重与输入嵌入绑定)。
类型: models
的静态类
xlmWithLMHeadModel._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
种类:XLMWithLMHeadModel
的实例方法
返回:Promise.<MaskedLMOutput>
- 返回的对象
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.XLMForSequenceClassification
XLM 模型,顶部带有一个序列分类/回归头(在池化输出之上有一个线性层)
类型: models
的静态类
xlmForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
种类:XLMForSequenceClassification
的实例方法
返回:Promise.<SequenceClassifierOutput>
- 返回的对象
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.XLMForTokenClassification
XLM 模型,顶部带有一个标记分类头(在隐藏状态输出之上有一个线性层)
类型: models
的静态类
xlmForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
种类:XLMForTokenClassification
的实例方法
返回: Promise.<TokenClassifierOutput>
- 一个包含模型词元分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.XLMForQuestionAnswering
XLM 模型,顶部带有一个用于抽取式问答任务的跨度分类头
类型: models
的静态类
xlmForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
种类:XLMForQuestionAnswering
的实例方法
返回:Promise.<QuestionAnsweringModelOutput>
- 返回的对象
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.XLMRobertaForMaskedLM
用于对 XLMRoberta 模型执行掩码语言建模的 XLMRobertaForMaskedLM 类。
类型: models
的静态类
xlmRobertaForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>
在新输入上调用模型。
类型: XLMRobertaForMaskedLM
的实例方法
返回:Promise.<MaskedLMOutput>
- 返回的对象
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.XLMRobertaForSequenceClassification
用于对 XLMRoberta 模型执行序列分类的 XLMRobertaForSequenceClassification 类。
类型: models
的静态类
xlmRobertaForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
类型: XLMRobertaForSequenceClassification
的实例方法
返回:Promise.<SequenceClassifierOutput>
- 返回的对象
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.XLMRobertaForTokenClassification
用于对 XLMRoberta 模型执行令牌分类的 XLMRobertaForTokenClassification 类。
类型: models
的静态类
xlmRobertaForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
类型: XLMRobertaForTokenClassification
的实例方法
返回: Promise.<TokenClassifierOutput>
- 一个包含模型词元分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.XLMRobertaForQuestionAnswering
用于对 XLMRoberta 模型执行问答的 XLMRobertaForQuestionAnswering 类。
类型: models
的静态类
xlmRobertaForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>
在新输入上调用模型。
类型: XLMRobertaForQuestionAnswering
的实例方法
返回:Promise.<QuestionAnsweringModelOutput>
- 返回的对象
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.ASTModel
基础 AST 模型转换器,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.ASTForAudioClassification
带有音频分类头的音频频谱图转换器模型(在池化输出之上有一个线性层),例如用于 AudioSet、Speech Commands v2 等数据集。
类型: models
的静态类
models.WhisperModel
用于训练不带语言模型头的 Whisper 模型的 WhisperModel 类。
类型: models
的静态类
models.WhisperForConditionalGeneration
用于从 Whisper 模型生成条件输出的 WhisperForConditionalGeneration 类。
类型: models
的静态类
whisperForConditionalGeneration._retrieve_init_tokens(generation_config)
类型: WhisperForConditionalGeneration
的实例方法
参数量 | 类型 |
---|---|
generation_config | WhisperGenerationConfig |
whisperForConditionalGeneration.generate(options) ⇒ <code> Promise. < (ModelOutput|Tensor) > </code>
将 log-mel 输入特征转录或翻译成自回归生成的令牌 ID 序列。
类型: WhisperForConditionalGeneration
的实例方法
返回: Promise.<(ModelOutput|Tensor)>
- 模型的输出,可以包含生成的词元 ID、注意力分数和得分。
参数量 | 类型 |
---|---|
选项 | * |
whisperForConditionalGeneration._extract_token_timestamps(generate_outputs, alignment_heads, [num_frames], [time_precision]) ⇒ <code> Tensor </code>
使用编码器-解码器交叉注意力和动态时间规整 (DTW) 计算令牌级别的时间戳,以将每个输出令牌映射到输入音频中的位置。如果指定了 `num_frames`,则在应用 DTW 之前将裁剪编码器-解码器交叉注意力。
类型: WhisperForConditionalGeneration
的实例方法
返回: Tensor
- 包含每个预测令牌的时间戳(以秒为单位)的张量
参数量 | 类型 | 默认 | 描述 |
---|---|---|---|
generate_outputs | Object | 模型生成的输出 | |
generate_outputs.cross_attentions | Array.<Array<Tensor>> | 模型输出的交叉注意力 | |
generate_outputs.sequences | 张量 | 模型输出的序列 | |
alignment_heads | Array.<Array<number>> | 模型的对齐头 | |
[num_frames] | 数字 |
| 输入音频中的帧数。 |
[time_precision] | 数字 | 0.02 | 时间戳的精度(以秒为单位) |
models.MoonshineModel
用于训练不带语言模型头的 Moonshine 模型的 MoonshineModel 类。
类型: models
的静态类
models.VisionEncoderDecoderModel
基于 OpenAI GPT 架构的视觉编码器-解码器模型,用于图像字幕和其他视觉任务
类型: models
的静态类
models.LlavaForConditionalGeneration
LLAVA 模型,由一个视觉主干和一个语言模型组成。
类型: models
的静态类
models.Idefics3ForConditionalGeneration
Idefics3 模型,由一个视觉主干和一个语言模型组成。
类型: models
的静态类
models.SmolVLMForConditionalGeneration
带有语言模型头的 SmolVLM 模型。它由一个 SigLIP 视觉编码器和一个顶部的语言模型头组成。
类型: 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) [ ... ],
// }
// }
类型: models
的静态类
models.CLIPTextModel
来自 CLIP 的文本模型,顶部没有任何头或投影。
类型: 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
// }
类型: models
的静态类
CLIPTextModelWithProjection.from_pretrained() : <code> * </code>
类型: CLIPTextModelWithProjection
的静态方法
models.CLIPVisionModel
来自 CLIP 的视觉模型,顶部没有任何头或投影。
类型: 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
// }
类型: 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) [ ... ],
// }
// }
类型: 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
// }
类型: 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
// }
类型: models
的静态类
SiglipVisionModel.from_pretrained() : <code> * </code>
类型: SiglipVisionModel
的静态方法
models.CLIPSegForImageSegmentation
带有基于 Transformer 的解码器的 CLIPSeg 模型,用于零样本和单样本图像分割。
示例: 使用 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`);
}
类型: models
的静态类
models.GPT2LMHeadModel
在 GPT-2 基础模型之上的 GPT-2 语言模型头。该模型适用于文本生成任务。
类型: models
的静态类
models.JAISModel
基础 JAIS 模型转换器,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.JAISLMHeadModel
带有语言模型头的 JAIS 模型转换器(权重与输入嵌入绑定的线性层)。
类型: models
的静态类
models.CodeGenModel
CodeGenModel 是一个表示不带语言模型头的代码生成模型的类。
类型: models
的静态类
models.CodeGenForCausalLM
CodeGenForCausalLM 是一个表示基于 GPT-2 架构的代码生成模型的类。它扩展了 CodeGenPreTrainedModel
类。
类型: models
的静态类
models.LlamaPreTrainedModel
基础 LLama 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.LlamaModel
基础 LLaMA 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.CoherePreTrainedModel
基础 Cohere 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.GemmaPreTrainedModel
基础 Gemma 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.GemmaModel
基础 Gemma 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.Gemma2PreTrainedModel
基础 Gemma2 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.Gemma2Model
基础 Gemma2 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.Gemma3PreTrainedModel
基础 Gemma3 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.Gemma3Model
基础 Gemma3 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.Qwen2PreTrainedModel
基础 Qwen2 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.Qwen2Model
基础 Qwen2 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.Qwen3PreTrainedModel
基础 Qwen3 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.Qwen3Model
基础 Qwen3 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.PhiModel
基础 Phi 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.Phi3Model
基础 Phi3 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.BloomPreTrainedModel
带有语言模型头的 Bloom 模型转换器(权重与输入嵌入绑定的线性层)。
类型: models
的静态类
models.BloomModel
基础 Bloom 模型转换器,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.BloomForCausalLM
带有语言模型头的 Bloom 模型转换器(权重与输入嵌入绑定的线性层)。
类型: models
的静态类
models.MptModel
基础 Mpt 模型转换器,输出原始的隐藏状态,顶部没有任何特定的头部模块。
类型: models
的静态类
models.MptForCausalLM
带有一个语言建模头部的 MPT 模型转换器(线性层,其权重与输入嵌入层绑定)。
类型: models
的静态类
models.OPTModel
基础 OPT 模型,输出原始的隐藏状态,顶部没有任何特定的头部模块。
类型: models
的静态类
models.OPTForCausalLM
带有一个语言建模头部的 OPT 模型转换器(线性层,其权重与输入嵌入层绑定)。
类型: models
的静态类
models.VitPoseForPoseEstimation
带有一个姿态估计头部的 VitPose 模型。
类型: 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');
类型: models
的静态类
vitMatteForImageMatting._call(model_inputs)
类型:VitMatteForImageMatting
的实例方法
参数量 | 类型 |
---|---|
model_inputs | 任何 |
models.DetrObjectDetectionOutput
类型: models
的静态类
new DetrObjectDetectionOutput(output)
参数量 | 类型 | 描述 |
---|---|---|
输出 | Object | 模型的输出。 |
output.logits | 张量 | 所有查询的分类 logits(包括无对象)。 |
output.pred_boxes | 张量 | 所有查询的归一化边界框坐标,表示为 (center_x, center_y, width, height)。这些值在 [0, 1] 范围内归一化,相对于批次中每个单独图像的大小(不考虑可能的填充)。 |
models.DetrSegmentationOutput
类型: models
的静态类
new DetrSegmentationOutput(output)
参数量 | 类型 | 描述 |
---|---|---|
输出 | Object | 模型的输出。 |
output.logits | 张量 | 模型的输出 logits。 |
output.pred_boxes | 张量 | 预测的边界框。 |
output.pred_masks | 张量 | 预测的遮罩。 |
models.RTDetrObjectDetectionOutput
类型: models
的静态类
new RTDetrObjectDetectionOutput(output)
参数量 | 类型 | 描述 |
---|---|---|
输出 | Object | 模型的输出。 |
output.logits | 张量 | 所有查询的分类 logits(包括无对象)。 |
output.pred_boxes | 张量 | 所有查询的归一化边界框坐标,表示为 (center_x, center_y, width, height)。这些值在 [0, 1] 范围内归一化,相对于批次中每个单独图像的大小(不考虑可能的填充)。 |
models.TableTransformerModel
基础 Table Transformer 模型(由骨干网络和编码器-解码器 Transformer 组成),输出原始的隐藏状态,顶部没有任何特定的头部模块。
类型: models
的静态类
models.TableTransformerForObjectDetection
带有目标检测头部的 Table Transformer 模型(由骨干网络和编码器-解码器 Transformer 组成),用于 COCO 检测等任务。
类型: models
的静态类
tableTransformerForObjectDetection._call(model_inputs)
类型:TableTransformerForObjectDetection
的实例方法
参数量 | 类型 |
---|---|
model_inputs | 任何 |
models.ResNetPreTrainedModel
一个用于处理权重初始化以及提供下载和加载预训练模型的简单接口的抽象类。
类型: models
的静态类
models.ResNetModel
基础 ResNet 模型,输出原始特征,顶部没有任何特定的头部模块。
类型: models
的静态类
models.ResNetForImageClassification
带有图像分类头部的 ResNet 模型(在池化特征之上有一个线性层),例如用于 ImageNet。
类型: models
的静态类
resNetForImageClassification._call(model_inputs)
类型:ResNetForImageClassification
的实例方法
参数量 | 类型 |
---|---|
model_inputs | 任何 |
models.Swin2SRModel
基础 Swin2SR 模型转换器,输出原始的隐藏状态,顶部没有任何特定的头部模块。
类型: models
的静态类
models.Swin2SRForImageSuperResolution
带有一个上采样头部的 Swin2SR 模型转换器,用于图像超分辨率和修复。
示例:使用 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
// }
类型: models
的静态类
models.DPTModel
基础 DPT 模型转换器,输出原始的隐藏状态,顶部没有任何特定的头部模块。
类型: models
的静态类
models.DPTForDepthEstimation
带有一个深度估计头部的 DPT 模型(由3个卷积层组成),例如用于 KITTI、NYUv2。
示例:使用 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
// }
类型: models
的静态类
models.DepthAnythingForDepthEstimation
Depth Anything 模型,顶部带有一个深度估计头部(由 3 个卷积层组成),例如用于 KITTI、NYUv2。
类型: models
的静态类
models.GLPNModel
基础 GLPN 编码器 (Mix-Transformer),输出原始的隐藏状态,顶部没有任何特定的头部模块。
类型: 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>
示例:分步文档视觉问答 (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>
类型: models
的静态类
models.ConvNextModel
基础 ConvNext 模型,输出原始特征,顶部没有任何特定的头部模块。
类型: models
的静态类
models.ConvNextForImageClassification
带有图像分类头部的 ConvNext 模型(在池化特征之上有一个线性层),例如用于 ImageNet。
类型: models
的静态类
convNextForImageClassification._call(model_inputs)
类型:ConvNextForImageClassification
的实例方法
参数量 | 类型 |
---|---|
model_inputs | 任何 |
models.ConvNextV2Model
基础 ConvNextV2 模型,输出原始特征,顶部没有任何特定的头部模块。
类型: models
的静态类
models.ConvNextV2ForImageClassification
带有图像分类头部的 ConvNextV2 模型(在池化特征之上有一个线性层),例如用于 ImageNet。
类型: models
的静态类
convNextV2ForImageClassification._call(model_inputs)
类型:ConvNextV2ForImageClassification
的实例方法
参数量 | 类型 |
---|---|
model_inputs | 任何 |
models.Dinov2Model
基础 DINOv2 模型转换器,输出原始的隐藏状态,顶部没有任何特定的头部模块。
类型: models
的静态类
models.Dinov2ForImageClassification
带有图像分类头部的 Dinov2 模型转换器(在 [CLS] 标记的最终隐藏状态之上有一个线性层),例如用于 ImageNet。
类型: models
的静态类
dinov2ForImageClassification._call(model_inputs)
类型:Dinov2ForImageClassification
的实例方法
参数量 | 类型 |
---|---|
model_inputs | 任何 |
models.Dinov2WithRegistersModel
基础 Dinov2WithRegisters 模型转换器,输出原始的隐藏状态,顶部没有任何特定的头部模块。
类型: models
的静态类
models.Dinov2WithRegistersForImageClassification
带有图像分类头部的 Dinov2WithRegisters 模型转换器(在 [CLS] 标记的最终隐藏状态之上有一个线性层),例如用于 ImageNet。
类型: models
的静态类
dinov2WithRegistersForImageClassification._call(model_inputs)
类型:Dinov2WithRegistersForImageClassification
的实例方法
参数量 | 类型 |
---|---|
model_inputs | 任何 |
models.YolosObjectDetectionOutput
类型: models
的静态类
new YolosObjectDetectionOutput(output)
参数量 | 类型 | 描述 |
---|---|---|
输出 | Object | 模型的输出。 |
output.logits | 张量 | 所有查询的分类 logits(包括无对象)。 |
output.pred_boxes | 张量 | 所有查询的归一化边界框坐标,表示为 (center_x, center_y, width, height)。这些值在 [0, 1] 范围内归一化,相对于批次中每个单独图像的大小(不考虑可能的填充)。 |
models.SamModel
分割一切模型 (Segment Anything Model, SAM),用于根据输入图像以及可选的 2D 位置和边界框生成分割掩码。
示例:使用 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
// }
类型: 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>
根据图像的像素值计算图像嵌入和位置图像嵌入。
类型:SamModel
的实例方法
返回:Promise.<{image_embeddings: Tensor, image_positional_embeddings: Tensor}>
- 图像嵌入和位置图像嵌入。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 包含模型输入的对象。 |
model_inputs.pixel_values | 张量 | 使用 |
samModel.forward(model_inputs) ⇒ <code> Promise. < Object > </code>
类型:SamModel
的实例方法
返回:Promise.<Object>
- 模型的输出。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | SamModelInputs | 包含模型输入的对象。 |
samModel._call(model_inputs) ⇒ <code> Promise. < SamImageSegmentationOutput > </code>
使用提供的输入运行模型
类型:SamModel
的实例方法
返回:Promise.<SamImageSegmentationOutput>
- 包含分割输出的对象
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型输入 |
models.SamImageSegmentationOutput
Segment-Anything 模型输出的基类。
类型: models
的静态类
new SamImageSegmentationOutput(output)
参数量 | 类型 | 描述 |
---|---|---|
输出 | Object | 模型的输出。 |
output.iou_scores | 张量 | 模型的输出 logits。 |
output.pred_masks | 张量 | 预测的边界框。 |
models.Wav2Vec2Model
基础 Wav2Vec2 模型转换器,输出原始的隐藏状态,顶部没有任何特定的头部模块。
示例:加载并运行一个 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
// }
// }
类型: models
的静态类
models.Wav2Vec2ForAudioFrameClassification
带有一个帧分类头部的 Wav2Vec2 模型,用于说话人分割等任务。
类型: models
的静态类
wav2Vec2ForAudioFrameClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
类型:Wav2Vec2ForAudioFrameClassification
的实例方法
返回:Promise.<TokenClassifierOutput>
- 一个包含模型序列分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.PyAnnoteModel
基础 PyAnnote 模型转换器,输出原始的隐藏状态,顶部没有任何特定的头部模块。
类型: models
的静态类
models.PyAnnoteForAudioFrameClassification
带有一个帧分类头部的 PyAnnote 模型,用于说话人分割等任务。
示例:加载并运行一个 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 │
// └─────────┴────────────────────┴────────────────────┴────┴─────────────────────┘
类型: models
的静态类
pyAnnoteForAudioFrameClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
类型:PyAnnoteForAudioFrameClassification
的实例方法
返回:Promise.<TokenClassifierOutput>
- 一个包含模型序列分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.UniSpeechModel
基础 UniSpeech 模型转换器,输出原始的隐藏状态,顶部没有任何特定的头部模块。
类型: models
的静态类
models.UniSpeechForCTC
带有一个用于连接时序分类 (CTC) 的 语言建模
头部的 UniSpeech 模型。
类型: models
的静态类
uniSpeechForCTC._call(model_inputs)
类型:UniSpeechForCTC
的实例方法
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | |
model_inputs.input_values | 张量 | 输入原始语音波形的浮点数值。 |
model_inputs.attention_mask | 张量 | 用于避免对填充标记索引执行卷积和注意力的掩码。掩码值选择在 [0, 1] 范围内。 |
models.UniSpeechForSequenceClassification
带有一个序列分类头部的 UniSpeech 模型(在池化输出之上有一个线性层)。
类型: models
的静态类
uniSpeechForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
类型:UniSpeechForSequenceClassification
的实例方法
返回: Promise.<SequenceClassifierOutput>
- 一个包含模型序列分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.UniSpeechSatModel
基础 UniSpeechSat 模型转换器,输出原始的隐藏状态,顶部没有任何特定的头部模块。
类型: models
的静态类
models.UniSpeechSatForCTC
带有一个用于连接时序分类 (CTC) 的 语言建模
头部的 UniSpeechSat 模型。
类型: models
的静态类
uniSpeechSatForCTC._call(model_inputs)
类型:UniSpeechSatForCTC
的实例方法
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | |
model_inputs.input_values | 张量 | 输入原始语音波形的浮点数值。 |
model_inputs.attention_mask | 张量 | 用于避免对填充标记索引执行卷积和注意力的掩码。掩码值选择在 [0, 1] 范围内。 |
models.UniSpeechSatForSequenceClassification
UniSpeechSat 模型,顶部带有一个序列分类头(在池化输出之上是一个线性层)。
类型: models
的静态类
uniSpeechSatForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
种类: UniSpeechSatForSequenceClassification
的实例方法
返回: Promise.<SequenceClassifierOutput>
- 一个包含模型序列分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.UniSpeechSatForAudioFrameClassification
UniSpeechSat 模型,顶部带有一个帧分类头,用于如说话人分割等任务。
类型: models
的静态类
uniSpeechSatForAudioFrameClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
种类: UniSpeechSatForAudioFrameClassification
的实例方法
返回:Promise.<TokenClassifierOutput>
- 一个包含模型序列分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.Wav2Vec2BertModel
基础的 Wav2Vec2Bert 模型转换器,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.Wav2Vec2BertForCTC
Wav2Vec2Bert 模型,顶部带有一个用于连接时序分类 (CTC) 的 `语言建模` 头。
类型: models
的静态类
wav2Vec2BertForCTC._call(model_inputs)
种类: Wav2Vec2BertForCTC
的实例方法
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | |
model_inputs.input_features | 张量 | 输入梅尔频谱图的浮点数值。 |
model_inputs.attention_mask | 张量 | 用于避免对填充标记索引执行卷积和注意力的掩码。掩码值选择在 [0, 1] 范围内。 |
models.Wav2Vec2BertForSequenceClassification
Wav2Vec2Bert 模型,顶部带有一个序列分类头(在池化输出之上是一个线性层)。
类型: models
的静态类
wav2Vec2BertForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
种类: Wav2Vec2BertForSequenceClassification
的实例方法
返回: Promise.<SequenceClassifierOutput>
- 一个包含模型序列分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.HubertModel
基础的 Hubert 模型转换器,输出原始的隐藏状态,顶部没有任何特定的头。
示例: 加载并运行一个 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
// }
// }
类型: models
的静态类
models.HubertForCTC
Hubert 模型,顶部带有一个用于连接时序分类 (CTC) 的 `语言建模` 头。
类型: models
的静态类
hubertForCTC._call(model_inputs)
种类: HubertForCTC
的实例方法
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | |
model_inputs.input_values | 张量 | 输入原始语音波形的浮点数值。 |
model_inputs.attention_mask | 张量 | 用于避免对填充标记索引执行卷积和注意力的掩码。掩码值选择在 [0, 1] 范围内。 |
models.HubertForSequenceClassification
Hubert 模型,顶部带有一个序列分类头(在池化输出之上是一个线性层),用于像 SUPERB 关键词识别等任务。
类型: models
的静态类
hubertForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
种类: HubertForSequenceClassification
的实例方法
返回: Promise.<SequenceClassifierOutput>
- 一个包含模型序列分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.WavLMPreTrainedModel
一个用于处理权重初始化以及提供下载和加载预训练模型的简单接口的抽象类。
类型: models
的静态类
models.WavLMModel
基础的 WavLM 模型转换器,输出原始的隐藏状态,顶部没有任何特定的头。
示例: 加载并运行一个 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
// }
// }
类型: models
的静态类
models.WavLMForCTC
WavLM 模型,顶部带有一个用于连接时序分类 (CTC) 的 `语言建模` 头。
类型: models
的静态类
wavLMForCTC._call(model_inputs)
种类: WavLMForCTC
的实例方法
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | |
model_inputs.input_values | 张量 | 输入原始语音波形的浮点数值。 |
model_inputs.attention_mask | 张量 | 用于避免对填充标记索引执行卷积和注意力的掩码。掩码值选择在 [0, 1] 范围内。 |
models.WavLMForSequenceClassification
WavLM 模型,顶部带有一个序列分类头(在池化输出之上是一个线性层)。
类型: models
的静态类
wavLMForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>
在新输入上调用模型。
种类: WavLMForSequenceClassification
的实例方法
返回: Promise.<SequenceClassifierOutput>
- 一个包含模型序列分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.WavLMForXVector
WavLM 模型,顶部带有一个 XVector 特征提取头,用于如说话人验证等任务。
示例: 使用 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
// }
// }
类型: 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],
// ...
// ]
类型: models
的静态类
wavLMForAudioFrameClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>
在新输入上调用模型。
种类: WavLMForAudioFrameClassification
的实例方法
返回:Promise.<TokenClassifierOutput>
- 一个包含模型序列分类输出 logits 的对象。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.SpeechT5PreTrainedModel
一个用于处理权重初始化以及提供下载和加载预训练模型的简单接口的抽象类。
类型: models
的静态类
models.SpeechT5Model
基础的 SpeechT5 编码器-解码器模型,输出原始的隐藏状态,没有任何特定的前置或后置网络。
类型: 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, ... ],
// }
类型: models
的静态类
models.SpeechT5ForTextToSpeech
带有一个文本编码器和一个语音解码器的 SpeechT5 模型。
类型: models
的静态类
speechT5ForTextToSpeech.generate_speech(input_values, speaker_embeddings, options) ⇒ <code> Promise. < SpeechOutput > </code>
将输入词元序列转换为梅尔频谱图序列,随后使用声码器将其转换为语音波形。
种类: SpeechT5ForTextToSpeech
的实例方法
返回: Promise.<SpeechOutput>
- 一个解析为包含频谱图、波形和交叉注意力张量的对象的 Promise。
参数量 | 类型 | 默认 | 描述 |
---|---|---|---|
input_values | 张量 | 输入序列词元在词汇表中的索引。 | |
speaker_embeddings | 张量 | 包含说话人嵌入的张量。 | |
选项 | Object | 生成语音的可选参数。 | |
[options.threshold] | 数字 | 0.5 | 当预测的停止词元概率超过此值时,生成的序列结束。 |
[options.minlenratio] | 数字 | 0.0 | 用于计算输出序列所需的最小长度。 |
[options.maxlenratio] | 数字 | 20.0 | 用于计算输出序列允许的最大长度。 |
[options.vocoder] | Object |
| 将梅尔频谱图转换为语音波形的声码器。如果为 |
[options.output_cross_attentions] | boolean | false | 是否返回解码器交叉注意力层的注意力张量。 |
models.SpeechT5HifiGan
HiFi-GAN 声码器。
有关用法示例,请参阅 SpeechT5ForSpeechToText。
类型: models
的静态类
models.TrOCRForCausalLM
带有一个语言建模头的 TrOCR 解码器。
类型: models
的静态类
models.MistralPreTrainedModel
基础的 Mistral 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.Starcoder2PreTrainedModel
基础的 Starcoder2 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.FalconPreTrainedModel
基础的 Falcon 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: 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
// }
类型: 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
// }
类型: 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,
// }
类型: models
的静态类
vitsModel._call(model_inputs) ⇒ <code> Promise. < VitsModelOutput > </code>
在新输入上调用模型。
种类: VitsModel
的实例方法
返回: Promise.<VitsModelOutput>
- VITS 模型的输出。
参数量 | 类型 | 描述 |
---|---|---|
model_inputs | Object | 模型的输入。 |
models.SegformerModel
基础的 SegFormer 编码器(Mix-Transformer),输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.SegformerForImageClassification
SegFormer 模型转换器,顶部带有一个图像分类头(在最终隐藏状态之上是一个线性层),例如用于 ImageNet。
类型: models
的静态类
models.SegformerForSemanticSegmentation
SegFormer 模型转换器,顶部带有一个全 MLP 解码头,例如用于 ADE20k、CityScapes。
类型: models
的静态类
models.StableLmModel
基础的 StableLm 模型转换器,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.StableLmForCausalLM
StableLm 模型,顶部带有一个用于因果语言建模(带有 past)的 `语言建模` 头。
类型: models
的静态类
models.EfficientNetModel
基础的 EfficientNet 模型,输出原始特征,顶部没有任何特定的头。
类型: models
的静态类
models.EfficientNetForImageClassification
EfficientNet 模型,顶部带有一个图像分类头(在池化特征之上是一个线性层)。
类型: models
的静态类
efficientNetForImageClassification._call(model_inputs)
种类: EfficientNetForImageClassification
的实例方法
参数量 | 类型 |
---|---|
model_inputs | 任何 |
models.MusicgenModel
基础的 Musicgen 解码器模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.MusicgenForCausalLM
顶部带有语言建模头的 MusicGen 解码器模型。
类型: 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());
类型: 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,然后通过在一个步骤中过滤掉填充标记 id 来恢复模式延迟掩码。
种类: MusicgenForConditionalGeneration
的实例方法
返回: Tensor
- 过滤后的输出张量。
参数量 | 类型 | 描述 |
---|---|---|
输出 | 张量 | 模型的输出张量。 |
musicgenForConditionalGeneration.generate(options) ⇒ <code> Promise. < (ModelOutput|Tensor) > </code>
为具有语言建模头的模型生成词元 ID 序列。
种类: MusicgenForConditionalGeneration
的实例方法
返回: Promise.<(ModelOutput|Tensor)>
- 模型的输出,可以包含生成的词元 ID、注意力分数和得分。
参数量 | 类型 |
---|---|
选项 | * |
models.MobileNetV1Model
基础的 MobileNetV1 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.MobileNetV1ForImageClassification
MobileNetV1 模型,顶部带有一个图像分类头(在池化特征之上是一个线性层),例如用于 ImageNet。
类型: models
的静态类
mobileNetV1ForImageClassification._call(model_inputs)
种类: MobileNetV1ForImageClassification
的实例方法
参数量 | 类型 |
---|---|
model_inputs | 任何 |
models.MobileNetV2Model
基础的 MobileNetV2 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.MobileNetV2ForImageClassification
MobileNetV2 模型,顶部带有一个图像分类头(在池化特征之上是一个线性层),例如用于 ImageNet。
类型: models
的静态类
mobileNetV2ForImageClassification._call(model_inputs)
种类: MobileNetV2ForImageClassification
的实例方法
参数量 | 类型 |
---|---|
model_inputs | 任何 |
models.MobileNetV3Model
基础的 MobileNetV3 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.MobileNetV3ForImageClassification
MobileNetV3 模型,顶部带有一个图像分类头(在池化特征之上是一个线性层),例如用于 ImageNet。
类型: models
的静态类
mobileNetV3ForImageClassification._call(model_inputs)
种类: MobileNetV3ForImageClassification
的实例方法
参数量 | 类型 |
---|---|
model_inputs | 任何 |
models.MobileNetV4Model
基础的 MobileNetV4 模型,输出原始的隐藏状态,顶部没有任何特定的头。
类型: models
的静态类
models.MobileNetV4ForImageClassification
带有图像分类头的 MobileNetV4 模型(在池化特征之上有一个线性层),例如用于 ImageNet。
类型: models
的静态类
mobileNetV4ForImageClassification._call(model_inputs)
种类: MobileNetV4ForImageClassification
的实例方法
参数量 | 类型 |
---|---|
model_inputs | 任何 |
models.DecisionTransformerModel
该模型基于 GPT2 架构,在离线强化学习(RL)设置中执行动作的自回归预测。更多详情请参阅论文:https://huggingface.co/papers/2106.01345
类型: models
的静态类
models.MultiModalityCausalLM
类型: models
的静态类
new MultiModalityCausalLM(...args)
参数量 | 类型 |
---|---|
...args | * |
multiModalityCausalLM.generate(options)
种类: MultiModalityCausalLM
的实例方法
参数量 | 类型 |
---|---|
选项 | * |
multiModalityCausalLM.generate_images(options)
种类: MultiModalityCausalLM
的实例方法
参数量 | 类型 |
---|---|
选项 | * |
models.MgpstrForSceneTextRecognition
MGP-STR 模型 transformer,顶部有三个分类头(三个 A^3 模块和三个线性层,位于 transformer 编码器输出之上),用于场景文本识别(STR)。
类型: models
的静态类
mgpstrForSceneTextRecognition._call(model_inputs)
种类: MgpstrForSceneTextRecognition
的实例方法
参数量 | 类型 |
---|---|
model_inputs | 任何 |
models.PatchTSTModel
基础的 PatchTST 模型,输出原始的隐藏状态,没有任何特定的头。
类型: models
的静态类
models.PatchTSTForPrediction
用于预测的 PatchTST 模型。
类型: models
的静态类
models.PatchTSMixerModel
基础的 PatchTSMixer 模型,输出原始的隐藏状态,没有任何特定的头。
类型: models
的静态类
models.PatchTSMixerForPrediction
用于预测的 PatchTSMixer 模型。
类型: models
的静态类
models.MimiEncoderOutput
类型: models
的静态类
new MimiEncoderOutput(output)
参数量 | 类型 | 描述 |
---|---|---|
输出 | Object | 模型的输出。 |
output.audio_codes | 张量 | 离散代码嵌入,形状为 |
models.MimiDecoderOutput
类型: models
的静态类
new MimiDecoderOutput(output)
参数量 | 类型 | 描述 |
---|---|---|
输出 | Object | 模型的输出。 |
output.audio_values | 张量 | 解码后的音频值,形状为 |
models.MimiModel
Mimi 神经音频编解码器模型。
类型: 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)
的输出张量。
参数量 | 类型 | 描述 |
---|---|---|
输入 | Object | 模型输入 |
[inputs.input_values] | 张量 | 输入音频波形的浮点数值,形状为 |
mimiModel.decode(inputs) ⇒ <code> Promise. < MimiDecoderOutput > </code>
将给定帧解码为输出音频波形。
种类: MimiModel
的实例方法
返回: Promise.<MimiDecoderOutput>
- 形状为 (batch_size, num_channels, sequence_length)
的输出张量。
参数量 | 类型 | 描述 |
---|---|---|
输入 | MimiEncoderOutput | 编码后的音频码。 |
models.DacEncoderOutput
类型: models
的静态类
new DacEncoderOutput(output)
参数量 | 类型 | 描述 |
---|---|---|
输出 | Object | 模型的输出。 |
output.audio_codes | 张量 | 离散代码嵌入,形状为 |
models.DacDecoderOutput
类型: models
的静态类
new DacDecoderOutput(output)
参数量 | 类型 | 描述 |
---|---|---|
输出 | Object | 模型的输出。 |
output.audio_values | 张量 | 解码后的音频值,形状为 |
models.DacModel
DAC (Descript Audio Codec) 模型。
类型: 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)
的输出张量。
参数量 | 类型 | 描述 |
---|---|---|
输入 | Object | 模型输入 |
[inputs.input_values] | 张量 | 输入音频波形的浮点数值,形状为 |
dacModel.decode(inputs) ⇒ <code> Promise. < DacDecoderOutput > </code>
将给定帧解码为输出音频波形。
种类: DacModel
的实例方法
返回: Promise.<DacDecoderOutput>
- 形状为 (batch_size, num_channels, sequence_length)
的输出张量。
参数量 | 类型 | 描述 |
---|---|---|
输入 | DacEncoderOutput | 编码后的音频码。 |
models.SnacModel
SNAC (Multi-Scale Neural Audio Codec) 模型。
类型: 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)
的输出张量。
参数量 | 类型 | 描述 |
---|---|---|
输入 | Object | 模型输入 |
[inputs.input_values] | 张量 | 输入音频波形的浮点数值,形状为 |
snacModel.decode(inputs) ⇒ <code> Promise. < {audio_values: Tensor} > </code>
将给定帧解码为输出音频波形。
种类: SnacModel
的实例方法
返回: Promise.<{audio_values: Tensor}>
- 形状为 (batch_size, num_channels, sequence_length)
的输出张量。
参数量 | 类型 | 描述 |
---|---|---|
输入 | Record.<string, Tensor> | 编码后的音频码。 |
models.PretrainedMixin
所有 AutoModels 的基类。包含用于实例化预训练模型的 `from_pretrained` 函数。
类型: models
的静态类
pretrainedMixin.MODEL_CLASS_MAPPINGS : <code> * </code>
从模型类型到模型类的映射。
种类: PretrainedMixin
的实例属性
pretrainedMixin.BASE_IF_FAIL
如果映射中未找到模型类型,是否尝试实例化基类 (PretrainedModel
)。
种类: PretrainedMixin
的实例属性
PretrainedMixin.from_pretrained() : <code> * </code>
种类: PretrainedMixin
的静态方法
models.AutoModel
用于通过 `from_pretrained` 函数实例化预训练模型的辅助类。所选模型类由模型配置中指定的类型决定。
类型: models
的静态类
new AutoModel()
示例
let model = await AutoModel.from_pretrained('Xenova/bert-base-uncased');
autoModel.MODEL_CLASS_MAPPINGS : <code> * </code>
种类: AutoModel
的实例属性
models.AutoModelForSequenceClassification
用于通过 `from_pretrained` 函数实例化预训练序列分类模型的辅助类。所选模型类由模型配置中指定的类型决定。
类型: models
的静态类
new AutoModelForSequenceClassification()
示例
let model = await AutoModelForSequenceClassification.from_pretrained('Xenova/distilbert-base-uncased-finetuned-sst-2-english');
models.AutoModelForTokenClassification
用于通过 `from_pretrained` 函数实例化预训练词元分类模型的辅助类。所选模型类由模型配置中指定的类型决定。
类型: models
的静态类
new AutoModelForTokenClassification()
示例
let model = await AutoModelForTokenClassification.from_pretrained('Xenova/distilbert-base-multilingual-cased-ner-hrl');
models.AutoModelForSeq2SeqLM
用于通过 `from_pretrained` 函数实例化预训练序列到序列模型的辅助类。所选模型类由模型配置中指定的类型决定。
类型: models
的静态类
new AutoModelForSeq2SeqLM()
示例
let model = await AutoModelForSeq2SeqLM.from_pretrained('Xenova/t5-small');
models.AutoModelForSpeechSeq2Seq
用于通过 `from_pretrained` 函数实例化预训练的序列到序列语音转文本模型的辅助类。所选模型类由模型配置中指定的类型决定。
类型: models
的静态类
new AutoModelForSpeechSeq2Seq()
示例
let model = await AutoModelForSpeechSeq2Seq.from_pretrained('openai/whisper-tiny.en');
models.AutoModelForTextToSpectrogram
用于通过 `from_pretrained` 函数实例化预训练的序列到序列文本到频谱图模型的辅助类。所选模型类由模型配置中指定的类型决定。
类型: models
的静态类
new AutoModelForTextToSpectrogram()
示例
let model = await AutoModelForTextToSpectrogram.from_pretrained('microsoft/speecht5_tts');
models.AutoModelForTextToWaveform
用于通过 `from_pretrained` 函数实例化预训练文本到波形模型的辅助类。所选模型类由模型配置中指定的类型决定。
类型: models
的静态类
new AutoModelForTextToWaveform()
示例
let model = await AutoModelForTextToSpectrogram.from_pretrained('facebook/mms-tts-eng');
models.AutoModelForCausalLM
用于通过 `from_pretrained` 函数实例化预训练因果语言模型的辅助类。所选模型类由模型配置中指定的类型决定。
类型: models
的静态类
new AutoModelForCausalLM()
示例
let model = await AutoModelForCausalLM.from_pretrained('Xenova/gpt2');
models.AutoModelForMaskedLM
用于通过 `from_pretrained` 函数实例化预训练的掩码语言模型的辅助类。所选模型类由模型配置中指定的类型决定。
类型: models
的静态类
new AutoModelForMaskedLM()
示例
let model = await AutoModelForMaskedLM.from_pretrained('Xenova/bert-base-uncased');
models.AutoModelForQuestionAnswering
用于通过 `from_pretrained` 函数实例化预训练问答模型的辅助类。所选模型类由模型配置中指定的类型决定。
类型: models
的静态类
new AutoModelForQuestionAnswering()
示例
let model = await AutoModelForQuestionAnswering.from_pretrained('Xenova/distilbert-base-cased-distilled-squad');
models.AutoModelForVision2Seq
用于通过 `from_pretrained` 函数实例化预训练的视觉到序列模型的辅助类。所选模型类由模型配置中指定的类型决定。
类型: models
的静态类
new AutoModelForVision2Seq()
示例
let model = await AutoModelForVision2Seq.from_pretrained('Xenova/vit-gpt2-image-captioning');
models.AutoModelForImageClassification
用于通过 `from_pretrained` 函数实例化预训练图像分类模型的辅助类。所选模型类由模型配置中指定的类型决定。
类型: models
的静态类
new AutoModelForImageClassification()
示例
let model = await AutoModelForImageClassification.from_pretrained('Xenova/vit-base-patch16-224');
models.AutoModelForImageSegmentation
用于通过 `from_pretrained` 函数实例化预训练图像分割模型的辅助类。所选模型类由模型配置中指定的类型决定。
类型: models
的静态类
new AutoModelForImageSegmentation()
示例
let model = await AutoModelForImageSegmentation.from_pretrained('Xenova/detr-resnet-50-panoptic');
models.AutoModelForSemanticSegmentation
用于通过 `from_pretrained` 函数实例化预训练图像分割模型的辅助类。所选模型类由模型配置中指定的类型决定。
类型: models
的静态类
new AutoModelForSemanticSegmentation()
示例
let model = await AutoModelForSemanticSegmentation.from_pretrained('nvidia/segformer-b3-finetuned-cityscapes-1024-1024');
models.AutoModelForUniversalSegmentation
用于通过 `from_pretrained` 函数实例化预训练通用图像分割模型的辅助类。所选模型类由模型配置中指定的类型决定。
类型: models
的静态类
new AutoModelForUniversalSegmentation()
示例
let model = await AutoModelForUniversalSegmentation.from_pretrained('hf-internal-testing/tiny-random-MaskFormerForInstanceSegmentation');
models.AutoModelForObjectDetection
一个辅助类,用于通过 from_pretrained
函数实例化预训练的目标检测模型。所选的模型类由模型配置中指定的类型决定。
类型: models
的静态类
new AutoModelForObjectDetection()
示例
let model = await AutoModelForObjectDetection.from_pretrained('Xenova/detr-resnet-50');
models.AutoModelForMaskGeneration
一个辅助类,用于通过 from_pretrained
函数实例化预训练的掩码生成模型。所选的模型类由模型配置中指定的类型决定。
类型: models
的静态类
new AutoModelForMaskGeneration()
示例
let model = await AutoModelForMaskGeneration.from_pretrained('Xenova/sam-vit-base');
models.Seq2SeqLMOutput
类型: models
的静态类
new Seq2SeqLMOutput(output)
参数量 | 类型 | 描述 |
---|---|---|
输出 | Object | 模型的输出。 |
output.logits | 张量 | 模型的输出 logits。 |
output.past_key_values | 张量 | 表示模型先前状态的键/值对张量。 |
output.encoder_outputs | 张量 | 序列到序列模型中编码器的输出。 |
[output.decoder_attentions] | 张量 | 解码器的注意力权重,在注意力 softmax 之后,用于计算自注意力头中的加权平均。 |
[output.cross_attentions] | 张量 | 解码器交叉注意力层的注意力权重,在注意力 softmax 之后,用于计算交叉注意力头中的加权平均值。 |
models.SequenceClassifierOutput
句子分类模型输出的基类。
类型: models
的静态类
new SequenceClassifierOutput(output)
参数量 | 类型 | 描述 |
---|---|---|
输出 | Object | 模型的输出。 |
output.logits | 张量 | 分类(如果 config.num_labels==1,则为回归)得分(在 SoftMax 之前)。 |
[output.attentions] | Record.<string, Tensor> |
|
models.XVectorOutput
XVector 模型输出的基类。
类型: models
的静态类
new XVectorOutput(output)
参数量 | 类型 | 描述 |
---|---|---|
输出 | Object | 模型的输出。 |
output.logits | 张量 | AMSoftmax 之前的分类隐藏状态,形状为 |
output.embeddings | 张量 | 用于基于向量相似度检索的语句嵌入,形状为 |
models.TokenClassifierOutput
Token分类模型输出的基类。
类型: models
的静态类
new TokenClassifierOutput(output)
参数量 | 类型 | 描述 |
---|---|---|
输出 | Object | 模型的输出。 |
output.logits | 张量 | 分类分数(SoftMax 之前)。 |
models.MaskedLMOutput
掩码语言模型输出的基类。
类型: models
的静态类
new MaskedLMOutput(output)
参数量 | 类型 | 描述 |
---|---|---|
输出 | Object | 模型的输出。 |
output.logits | 张量 | 语言模型头的预测得分(在 SoftMax 之前每个词汇标记的得分)。 |
models.QuestionAnsweringModelOutput
问答模型输出的基类。
类型: models
的静态类
new QuestionAnsweringModelOutput(output)
参数量 | 类型 | 描述 |
---|---|---|
输出 | Object | 模型的输出。 |
output.start_logits | 张量 | 答案范围开始位置的得分(在 SoftMax 之前)。 |
output.end_logits | 张量 | 答案范围结束位置的得分(在 SoftMax 之前)。 |
models.CausalLMOutput
因果语言模型(或自回归)输出的基类。
类型: models
的静态类
new CausalLMOutput(output)
参数量 | 类型 | 描述 |
---|---|---|
输出 | Object | 模型的输出。 |
output.logits | 张量 | 语言模型头的预测得分(在 softmax 之前每个词汇标记的得分)。 |
models.CausalLMOutputWithPast
因果语言模型(或自回归)输出的基类。
类型: models
的静态类
new CausalLMOutputWithPast(output)
参数量 | 类型 | 描述 |
---|---|---|
输出 | Object | 模型的输出。 |
output.logits | 张量 | 语言模型头的预测得分(在 softmax 之前每个词汇标记的得分)。 |
output.past_key_values | 张量 | 包含预计算的隐藏状态(自注意力块中的键和值),可用于(参见 |
models.ImageMattingOutput
类型: models
的静态类
new ImageMattingOutput(output)
参数量 | 类型 | 描述 |
---|---|---|
输出 | Object | 模型的输出。 |
output.alphas | 张量 | 估计的 alpha 值,形状为 |
models.VitsModelOutput
描述 VITS 模型的输出。
类型: models
的静态类
new VitsModelOutput(output)
参数量 | 类型 | 描述 |
---|---|---|
输出 | Object | 模型的输出。 |
output.waveform | 张量 | 模型预测的最终音频波形,形状为 |
output.spectrogram | 张量 | 在流模型输出端预测的对数梅尔频谱图。此频谱图被传递给 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 | 张量 |
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
的内部 typedef
属性
名称 | 类型 | 描述 |
---|---|---|
pixel_values | 张量 | 形状为 |
[input_points] | 张量 | 形状为 |
[input_labels] | 张量 | 点的输入标签,形状为
|
[input_boxes] | 张量 | 形状为 |
[image_embeddings] | 张量 | 掩码解码器使用的图像嵌入。 |
[image_positional_embeddings] | 张量 | 掩码解码器使用的图像位置嵌入。 |
models~SpeechOutput : <code> Object </code>
类型: models
的内部 typedef
属性
名称 | 类型 | 描述 |
---|---|---|
[spectrogram] | 张量 | 预测的对数梅尔频谱图,形状为 |
[waveform] | 张量 | 预测的波形,形状为 |
[cross_attentions] | 张量 | 解码器交叉注意力层的输出,形状为 |
< > 在 GitHub 上更新