Transformers.js 文件

模型

您正在檢視的是需要從原始碼安裝。如果您想透過常規的 npm install 安裝,請查閱最新的穩定版本 (v3.0.0)。
Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

模型

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!'

models.PreTrainedModel

預訓練模型的基類,提供模型配置和 ONNX 會話。

型別: models 的靜態類


new PreTrainedModel(config, sessions, configs)

建立 PreTrainedModel 類的新例項。

引數量型別描述
config*

模型配置。

sessionsRecord.<string, any>

模型的推理會話。

configsRecord.<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_inputsObject

包含輸入張量的物件


preTrainedModel.forward(model_inputs) ⇒ <code> Promise. < Object > </code>

預訓練模型的前向方法。如果子類未重寫,將根據模型型別選擇正確的前向方法。

型別: PreTrainedModel 的例項方法
返回: Promise.<Object> - 來自模型的輸出資料,其格式在 ONNX 模型中指定。
丟擲:

  • Error 此方法必須在子類中實現。
引數量型別描述
model_inputsObject

模型的輸入資料,其格式在 ONNX 模型中指定。


preTrainedModel._get_logits_warper(generation_config) ⇒ <code> LogitsProcessorList </code>

此函式返回一個 [LogitsProcessorList] 列表物件,其中包含用於多項式取樣的所有相關 [LogitsWarper] 例項。

型別: PreTrainedModel 的例項方法
返回: LogitsProcessorList - generation_config

引數量型別描述
generation_configGenerationConfig

生成配置。


preTrainedModel._prepare_generation_config(generation_config, kwargs) ⇒ <code> GenerationConfig </code>

此函式將多個生成配置合併在一起,形成一個最終的生成配置,供模型用於文字生成。它首先建立一個空的 GenerationConfig 物件,然後將模型自身的 generation_config 屬性應用到它上面。最後,如果在引數中傳入了一個 generation_config 物件,它會用傳入的配置物件中的屬性覆蓋最終配置中相應的屬性。

型別: PreTrainedModel 的例項方法
返回: GenerationConfig - 用於模型文字生成的最終生成配置物件。

引數量型別描述
generation_configGenerationConfig | null

一個包含生成引數的 GenerationConfig 物件。

kwargsObject

用於替代 generation_config 物件中的附加生成引數。


preTrainedModel._get_stopping_criteria(generation_config, [stopping_criteria])

型別: PreTrainedModel 的例項方法

引數量型別預設
generation_configGenerationConfig
[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.outputsObject
inputs.model_inputsObject
inputs.is_encoder_decoderboolean

preTrainedModel._prepare_model_inputs(params) ⇒ <code> Object </code>

此函式提取用於生成的模型特定 inputs

型別: PreTrainedModel 的例項方法
返回: Object - 用於生成的模型特定輸入。

引數量型別預設
paramsObject
[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 - 一個包含過去鍵值的物件。

引數量型別描述
decoderResultsObject

解碼器結果物件。

pastKeyValuesObject

先前的過去鍵值。


preTrainedModel.getAttentions(model_output) ⇒ <code> * </code>

從給定的模型輸出物件中返回一個包含注意力的物件。

型別: PreTrainedModel 的例項方法
返回: * - 一個包含注意力的物件。

引數量型別描述
model_outputObject

模型的輸出。


preTrainedModel.addPastKeyValues(decoderFeeds, pastKeyValues)

將過去鍵值新增到解碼器輸入物件。如果 pastKeyValues 為 null,則為過去鍵值建立新的張量。

型別: PreTrainedModel 的例項方法

引數量型別描述
decoderFeedsObject

要新增過去鍵值的解碼器輸入物件。

pastKeyValuesObject

一個包含過去鍵值的物件。


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字串

預訓練模型的名稱或路徑。可以是

  • 一個字串,託管在 huggingface.co 上模型倉庫中的預訓練模型的*模型 ID*。有效的模型 ID 可以位於根級別,例如 bert-base-uncased,也可以在使用者或組織名稱下名稱空間,例如 dbmdz/bert-base-german-cased
  • 一個包含模型權重的*目錄*路徑,例如 ./my_model_directory/
選項*

載入模型的附加選項。


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_inputsObject

模型的輸入。


models.BertForSequenceClassification

BertForSequenceClassification 是一個表示用於序列分類的 BERT 模型的類。

型別: models 的靜態類


bertForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>

在新輸入上呼叫模型。

型別: BertForSequenceClassification 的例項方法
返回: Promise.<SequenceClassifierOutput> - 一個包含模型序列分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.BertForTokenClassification

BertForTokenClassification 是一個表示用於詞元分類的 BERT 模型的類。

型別: models 的靜態類


bertForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>

在新輸入上呼叫模型。

型別: BertForTokenClassification 的例項方法
返回: Promise.<TokenClassifierOutput> - 一個包含模型詞元分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.BertForQuestionAnswering

BertForQuestionAnswering 是一個表示用於問答的 BERT 模型的類。

型別: models 的靜態類


bertForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>

在新輸入上呼叫模型。

種類: BertForQuestionAnswering 的例項方法
返回: Promise.<QuestionAnsweringModelOutput> - 包含模型問答任務輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.RoFormerModel

基礎的 RoFormer 模型 Transformer,輸出原始的隱藏狀態,頂部沒有任何特定的頭。

型別: models 的靜態類


models.RoFormerForMaskedLM

頂部帶有一個語言建模頭的 RoFormer 模型。

型別: models 的靜態類


roFormerForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>

在新輸入上呼叫模型。

種類: RoFormerForMaskedLM 的例項方法
返回: Promise.<MaskedLMOutput> - 一個包含模型掩碼語言建模輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.RoFormerForSequenceClassification

頂部帶有序列分類/迴歸頭的 RoFormer Transformer 模型(在池化輸出之上有一個線性層)

型別: models 的靜態類


roFormerForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>

在新輸入上呼叫模型。

種類: RoFormerForSequenceClassification 的例項方法
返回: Promise.<SequenceClassifierOutput> - 一個包含模型序列分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.RoFormerForTokenClassification

頂部帶有詞元分類頭的 RoFormer 模型(在隱藏狀態輸出之上有一個線性層),例如用於命名實體識別(NER)任務。

型別: models 的靜態類


roFormerForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>

在新輸入上呼叫模型。

種類: RoFormerForTokenClassification 的例項方法
返回: Promise.<TokenClassifierOutput> - 一個包含模型詞元分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.RoFormerForQuestionAnswering

頂部帶有片段分類頭的 RoFormer 模型,用於像 SQuAD 這樣的抽取式問答任務(在隱藏狀態輸出之上有一系列線性層,用於計算片段開始 logits片段結束 logits)。

型別: models 的靜態類


roFormerForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>

在新輸入上呼叫模型。

種類: RoFormerForQuestionAnswering 的例項方法
返回: Promise.<QuestionAnsweringModelOutput> - 包含模型問答任務輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.ConvBertModel

基礎的 ConvBERT 模型 Transformer,輸出原始的隱藏狀態,頂部沒有任何特定的頭。

型別: models 的靜態類


models.ConvBertForMaskedLM

頂部帶有語言建模頭的 ConvBERT 模型。

型別: models 的靜態類


convBertForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>

在新輸入上呼叫模型。

種類: ConvBertForMaskedLM 的例項方法
返回: Promise.<MaskedLMOutput> - 一個包含模型掩碼語言建模輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.ConvBertForSequenceClassification

頂部帶有序列分類/迴歸頭的 ConvBERT Transformer 模型(在池化輸出之上有一個線性層)

型別: models 的靜態類


convBertForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>

在新輸入上呼叫模型。

種類: ConvBertForSequenceClassification 的例項方法
返回: Promise.<SequenceClassifierOutput> - 一個包含模型序列分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.ConvBertForTokenClassification

頂部帶有詞元分類頭的 ConvBERT 模型(在隱藏狀態輸出之上有一個線性層),例如用於命名實體識別(NER)任務。

型別: models 的靜態類


convBertForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>

在新輸入上呼叫模型。

種類: ConvBertForTokenClassification 的例項方法
返回: Promise.<TokenClassifierOutput> - 一個包含模型詞元分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.ConvBertForQuestionAnswering

頂部帶有片段分類頭的 ConvBERT 模型,用於像 SQuAD 這樣的抽取式問答任務(在隱藏狀態輸出之上有一系列線性層,用於計算片段開始 logits片段結束 logits

型別: models 的靜態類


convBertForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>

在新輸入上呼叫模型。

種類: ConvBertForQuestionAnswering 的例項方法
返回: Promise.<QuestionAnsweringModelOutput> - 包含模型問答任務輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.ElectraModel

基礎的 Electra 模型 Transformer,輸出原始的隱藏狀態,頂部沒有任何特定的頭。與 BERT 模型相同,但如果隱藏大小和嵌入大小不同,則在嵌入層和編碼器之間使用一個額外的線性層。

型別: models 的靜態類


models.ElectraForMaskedLM

頂部帶有語言建模頭的 Electra 模型。

型別: models 的靜態類


electraForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>

在新輸入上呼叫模型。

種類: ElectraForMaskedLM 的例項方法
返回: Promise.<MaskedLMOutput> - 一個包含模型掩碼語言建模輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.ElectraForSequenceClassification

頂部帶有序列分類/迴歸頭的 ELECTRA Transformer 模型(在池化輸出之上有一個線性層)

型別: models 的靜態類


electraForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>

在新輸入上呼叫模型。

種類: ElectraForSequenceClassification 的例項方法
返回: Promise.<SequenceClassifierOutput> - 一個包含模型序列分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.ElectraForTokenClassification

頂部帶有詞元分類頭的 Electra 模型。

型別: models 的靜態類


electraForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>

在新輸入上呼叫模型。

種類: ElectraForTokenClassification 的例項方法
返回: Promise.<TokenClassifierOutput> - 一個包含模型詞元分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.ElectraForQuestionAnswering

頂部帶有片段分類頭的 LECTRA 模型,用於像 SQuAD 這樣的抽取式問答任務(在隱藏狀態輸出之上有一系列線性層,用於計算片段開始 logits片段結束 logits)。

型別: models 的靜態類


electraForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>

在新輸入上呼叫模型。

種類: ElectraForQuestionAnswering 的例項方法
返回: Promise.<QuestionAnsweringModelOutput> - 包含模型問答任務輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.CamembertModel

基礎的 CamemBERT 模型 Transformer,輸出原始的隱藏狀態,頂部沒有任何特定的頭。

型別: models 的靜態類


models.CamembertForMaskedLM

頂部帶有一個語言建模頭的 CamemBERT 模型。

型別: models 的靜態類


camembertForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>

在新輸入上呼叫模型。

種類: CamembertForMaskedLM 的例項方法
返回: Promise.<MaskedLMOutput> - 一個包含模型掩碼語言建模輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.CamembertForSequenceClassification

頂部帶有序列分類/迴歸頭的 CamemBERT Transformer 模型(在池化輸出之上有一個線性層),例如用於 GLUE 任務。

型別: models 的靜態類


camembertForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>

在新輸入上呼叫模型。

種類: CamembertForSequenceClassification 的例項方法
返回: Promise.<SequenceClassifierOutput> - 一個包含模型序列分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.CamembertForTokenClassification

頂部帶有詞元分類頭的 CamemBERT 模型(在隱藏狀態輸出之上有一個線性層),例如用於命名實體識別(NER)任務。

型別: models 的靜態類


camembertForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>

在新輸入上呼叫模型。

種類: CamembertForTokenClassification 的例項方法
返回: Promise.<TokenClassifierOutput> - 一個包含模型詞元分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.CamembertForQuestionAnswering

頂部帶有片段分類頭的 CamemBERT 模型,用於抽取式問答任務

型別: models 的靜態類


camembertForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>

在新輸入上呼叫模型。

種類: CamembertForQuestionAnswering 的例項方法
返回: Promise.<QuestionAnsweringModelOutput> - 包含模型問答任務輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.DebertaModel

基礎的 DeBERTa 模型 Transformer,輸出原始的隱藏狀態,頂部沒有任何特定的頭。

型別: models 的靜態類


models.DebertaForMaskedLM

頂部帶有一個語言建模頭的 DeBERTa 模型。

型別: models 的靜態類


debertaForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>

在新輸入上呼叫模型。

種類: DebertaForMaskedLM 的例項方法
返回: Promise.<MaskedLMOutput> - 一個包含模型掩碼語言建模輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.DebertaForSequenceClassification

頂部帶有序列分類/迴歸頭的 DeBERTa Transformer 模型(在池化輸出之上有一個線性層)

型別: models 的靜態類


debertaForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>

在新輸入上呼叫模型。

種類: DebertaForSequenceClassification 的例項方法
返回: Promise.<SequenceClassifierOutput> - 一個包含模型序列分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.DebertaForTokenClassification

頂部帶有詞元分類頭的 DeBERTa 模型(在隱藏狀態輸出之上有一個線性層),例如用於命名實體識別(NER)任務。

型別: models 的靜態類


debertaForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>

在新輸入上呼叫模型。

種類: DebertaForTokenClassification 的例項方法
返回: Promise.<TokenClassifierOutput> - 一個包含模型詞元分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.DebertaForQuestionAnswering

頂部帶有片段分類頭的 DeBERTa 模型,用於像 SQuAD 這樣的抽取式問答任務(在隱藏狀態輸出之上有一系列線性層,用於計算片段開始 logits片段結束 logits)。

型別: models 的靜態類


debertaForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>

在新輸入上呼叫模型。

種類: DebertaForQuestionAnswering 的例項方法
返回: Promise.<QuestionAnsweringModelOutput> - 包含模型問答任務輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.DebertaV2Model

基礎的 DeBERTa-V2 模型 Transformer,輸出原始的隱藏狀態,頂部沒有任何特定的頭。

型別: models 的靜態類


models.DebertaV2ForMaskedLM

頂部帶有一個語言建模頭的 DeBERTa-V2 模型。

型別: models 的靜態類


debertaV2ForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>

在新輸入上呼叫模型。

種類: DebertaV2ForMaskedLM 的例項方法
返回: Promise.<MaskedLMOutput> - 一個包含模型掩碼語言建模輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.DebertaV2ForSequenceClassification

頂部帶有序列分類/迴歸頭的 DeBERTa-V2 Transformer 模型(在池化輸出之上有一個線性層)

型別: models 的靜態類


debertaV2ForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>

在新輸入上呼叫模型。

種類: DebertaV2ForSequenceClassification 的例項方法
返回: Promise.<SequenceClassifierOutput> - 一個包含模型序列分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.DebertaV2ForTokenClassification

頂部帶有詞元分類頭的 DeBERTa-V2 模型(在隱藏狀態輸出之上有一個線性層),例如用於命名實體識別(NER)任務。

型別: models 的靜態類


debertaV2ForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>

在新輸入上呼叫模型。

種類: DebertaV2ForTokenClassification 的例項方法
返回: Promise.<TokenClassifierOutput> - 一個包含模型詞元分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.DebertaV2ForQuestionAnswering

頂部帶有片段分類頭的 DeBERTa-V2 模型,用於像 SQuAD 這樣的抽取式問答任務(在隱藏狀態輸出之上有一系列線性層,用於計算片段開始 logits片段結束 logits)。

型別: models 的靜態類


debertaV2ForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>

在新輸入上呼叫模型。

種類: DebertaV2ForQuestionAnswering 的例項方法
返回: Promise.<QuestionAnsweringModelOutput> - 包含模型問答任務輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.DistilBertForSequenceClassification

DistilBertForSequenceClassification 是一個表示用於序列分類的 DistilBERT 模型的類。

型別: models 的靜態類


distilBertForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>

在新輸入上呼叫模型。

種類: DistilBertForSequenceClassification 的例項方法
返回: Promise.<SequenceClassifierOutput> - 一個包含模型序列分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.DistilBertForTokenClassification

DistilBertForTokenClassification 是一個表示用於詞元分類的 DistilBERT 模型的類。

型別: models 的靜態類


distilBertForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>

在新輸入上呼叫模型。

種類: DistilBertForTokenClassification 的例項方法
返回: Promise.<TokenClassifierOutput> - 一個包含模型詞元分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.DistilBertForQuestionAnswering

DistilBertForQuestionAnswering 是一個表示用於問答任務的 DistilBERT 模型的類。

型別: models 的靜態類


distilBertForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>

在新輸入上呼叫模型。

種類: DistilBertForQuestionAnswering 的例項方法
返回: Promise.<QuestionAnsweringModelOutput> - 包含模型問答任務輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.DistilBertForMaskedLM

DistilBertForMaskedLM 是一個表示用於掩碼任務的 DistilBERT 模型的類。

型別: models 的靜態類


distilBertForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>

在新輸入上呼叫模型。

種類DistilBertForMaskedLM 的例項方法
返回Promise.<MaskedLMOutput> - 返回的物件

引數量型別描述
model_inputsObject

模型的輸入。


models.EsmModel

基礎的 ESM 模型轉換器,輸出原始的隱藏狀態,頂部沒有任何特定的頭。

型別: models 的靜態類


models.EsmForMaskedLM

頂部帶有語言建模頭的 ESM 模型。

型別: models 的靜態類


esmForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>

在新輸入上呼叫模型。

種類EsmForMaskedLM 的例項方法
返回: Promise.<MaskedLMOutput> - 一個包含模型掩碼語言建模輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.EsmForSequenceClassification

ESM 模型轉換器,頂部帶有一個序列分類/迴歸頭(在池化輸出之上有一個線性層)

型別: models 的靜態類


esmForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>

在新輸入上呼叫模型。

種類EsmForSequenceClassification 的例項方法
返回: Promise.<SequenceClassifierOutput> - 一個包含模型序列分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.EsmForTokenClassification

頂部帶有一個標記分類頭的 ESM 模型(在隱藏狀態輸出之上有一個線性層),例如用於命名實體識別(NER)任務。

型別: models 的靜態類


esmForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>

在新輸入上呼叫模型。

種類EsmForTokenClassification 的例項方法
返回: Promise.<TokenClassifierOutput> - 一個包含模型詞元分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.MobileBertForMaskedLM

MobileBertForMaskedLM 是一個表示用於掩碼任務的 MobileBERT 模型的類。

型別: models 的靜態類


mobileBertForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>

在新輸入上呼叫模型。

種類MobileBertForMaskedLM 的例項方法
返回Promise.<MaskedLMOutput> - 返回的物件

引數量型別描述
model_inputsObject

模型的輸入。


models.MobileBertForSequenceClassification

MobileBert 模型轉換器,頂部帶有一個序列分類/迴歸頭(在池化輸出之上有一個線性層)

型別: models 的靜態類


mobileBertForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>

在新輸入上呼叫模型。

種類MobileBertForSequenceClassification 的例項方法
返回Promise.<SequenceClassifierOutput> - 返回的物件

引數量型別描述
model_inputsObject

模型的輸入。


models.MobileBertForQuestionAnswering

MobileBert 模型,頂部帶有一個用於抽取式問答任務的跨度分類頭

型別: models 的靜態類


mobileBertForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>

在新輸入上呼叫模型。

種類MobileBertForQuestionAnswering 的例項方法
返回Promise.<QuestionAnsweringModelOutput> - 返回的物件

引數量型別描述
model_inputsObject

模型的輸入。


models.MPNetModel

基礎的 MPNet 模型轉換器,輸出原始的隱藏狀態,頂部沒有任何特定的頭。

型別: models 的靜態類


models.MPNetForMaskedLM

MPNetForMaskedLM 是一個表示用於掩碼語言建模的 MPNet 模型的類。

型別: models 的靜態類


mpNetForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>

在新輸入上呼叫模型。

種類MPNetForMaskedLM 的例項方法
返回: Promise.<MaskedLMOutput> - 一個包含模型掩碼語言建模輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.MPNetForSequenceClassification

MPNetForSequenceClassification 是一個表示用於序列分類的 MPNet 模型的類。

型別: models 的靜態類


mpNetForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>

在新輸入上呼叫模型。

種類MPNetForSequenceClassification 的例項方法
返回: Promise.<SequenceClassifierOutput> - 一個包含模型序列分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.MPNetForTokenClassification

MPNetForTokenClassification 是一個表示用於標記分類的 MPNet 模型的類。

型別: models 的靜態類


mpNetForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>

在新輸入上呼叫模型。

種類MPNetForTokenClassification 的例項方法
返回: Promise.<TokenClassifierOutput> - 一個包含模型詞元分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.MPNetForQuestionAnswering

MPNetForQuestionAnswering 是一個表示用於問答任務的 MPNet 模型的類。

型別: models 的靜態類


mpNetForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>

在新輸入上呼叫模型。

種類MPNetForQuestionAnswering 的例項方法
返回: Promise.<QuestionAnsweringModelOutput> - 包含模型問答任務輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


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_inputsObject

模型的輸入。


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_inputsObject

模型的輸入。


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_inputsObject

模型的輸入。


models.RobertaForSequenceClassification

用於在 Roberta 模型上執行序列分類的 RobertaForSequenceClassification 類。

型別: models 的靜態類


robertaForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>

在新輸入上呼叫模型。

種類RobertaForSequenceClassification 的例項方法
返回Promise.<SequenceClassifierOutput> - 返回的物件

引數量型別描述
model_inputsObject

模型的輸入。


models.RobertaForTokenClassification

用於在 Roberta 模型上執行標記分類的 RobertaForTokenClassification 類。

型別: models 的靜態類


robertaForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>

在新輸入上呼叫模型。

種類RobertaForTokenClassification 的例項方法
返回: Promise.<TokenClassifierOutput> - 一個包含模型詞元分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.RobertaForQuestionAnswering

用於在 Roberta 模型上執行問答任務的 RobertaForQuestionAnswering 類。

型別: models 的靜態類


robertaForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>

在新輸入上呼叫模型。

種類RobertaForQuestionAnswering 的例項方法
返回Promise.<QuestionAnsweringModelOutput> - 返回的物件

引數量型別描述
model_inputsObject

模型的輸入。


models.XLMPreTrainedModel

一個用於處理權重初始化以及提供下載和載入預訓練模型的簡單介面的抽象類。

型別: models 的靜態類


models.XLMModel

基礎的 XLM 模型轉換器,輸出原始的隱藏狀態,頂部沒有任何特定的頭。

型別: models 的靜態類


models.XLMWithLMHeadModel

頂部帶有語言建模頭的 XLM 模型轉換器(線性層權重與輸入嵌入繫結)。

型別: models 的靜態類


xlmWithLMHeadModel._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>

在新輸入上呼叫模型。

種類XLMWithLMHeadModel 的例項方法
返回Promise.<MaskedLMOutput> - 返回的物件

引數量型別描述
model_inputsObject

模型的輸入。


models.XLMForSequenceClassification

XLM 模型,頂部帶有一個序列分類/迴歸頭(在池化輸出之上有一個線性層)

型別: models 的靜態類


xlmForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>

在新輸入上呼叫模型。

種類XLMForSequenceClassification 的例項方法
返回Promise.<SequenceClassifierOutput> - 返回的物件

引數量型別描述
model_inputsObject

模型的輸入。


models.XLMForTokenClassification

XLM 模型,頂部帶有一個標記分類頭(在隱藏狀態輸出之上有一個線性層)

型別: models 的靜態類


xlmForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>

在新輸入上呼叫模型。

種類XLMForTokenClassification 的例項方法
返回: Promise.<TokenClassifierOutput> - 一個包含模型詞元分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.XLMForQuestionAnswering

XLM 模型,頂部帶有一個用於抽取式問答任務的跨度分類頭

型別: models 的靜態類


xlmForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>

在新輸入上呼叫模型。

種類XLMForQuestionAnswering 的例項方法
返回Promise.<QuestionAnsweringModelOutput> - 返回的物件

引數量型別描述
model_inputsObject

模型的輸入。


models.XLMRobertaForMaskedLM

用於對 XLMRoberta 模型執行掩碼語言建模的 XLMRobertaForMaskedLM 類。

型別: models 的靜態類


xlmRobertaForMaskedLM._call(model_inputs) ⇒ <code> Promise. < MaskedLMOutput > </code>

在新輸入上呼叫模型。

型別: XLMRobertaForMaskedLM 的例項方法
返回Promise.<MaskedLMOutput> - 返回的物件

引數量型別描述
model_inputsObject

模型的輸入。


models.XLMRobertaForSequenceClassification

用於對 XLMRoberta 模型執行序列分類的 XLMRobertaForSequenceClassification 類。

型別: models 的靜態類


xlmRobertaForSequenceClassification._call(model_inputs) ⇒ <code> Promise. < SequenceClassifierOutput > </code>

在新輸入上呼叫模型。

型別: XLMRobertaForSequenceClassification 的例項方法
返回Promise.<SequenceClassifierOutput> - 返回的物件

引數量型別描述
model_inputsObject

模型的輸入。


models.XLMRobertaForTokenClassification

用於對 XLMRoberta 模型執行令牌分類的 XLMRobertaForTokenClassification 類。

型別: models 的靜態類


xlmRobertaForTokenClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>

在新輸入上呼叫模型。

型別: XLMRobertaForTokenClassification 的例項方法
返回: Promise.<TokenClassifierOutput> - 一個包含模型詞元分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.XLMRobertaForQuestionAnswering

用於對 XLMRoberta 模型執行問答的 XLMRobertaForQuestionAnswering 類。

型別: models 的靜態類


xlmRobertaForQuestionAnswering._call(model_inputs) ⇒ <code> Promise. < QuestionAnsweringModelOutput > </code>

在新輸入上呼叫模型。

型別: XLMRobertaForQuestionAnswering 的例項方法
返回Promise.<QuestionAnsweringModelOutput> - 返回的物件

引數量型別描述
model_inputsObject

模型的輸入。


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_configWhisperGenerationConfig

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_outputsObject

模型生成的輸出

generate_outputs.cross_attentionsArray.<Array<Tensor>>

模型輸出的交叉注意力

generate_outputs.sequences張量

模型輸出的序列

alignment_headsArray.<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) ⇒ <code> Promise. < {image_embeddings: Tensor, image_positional_embeddings: Tensor} > </code>

根據影像的畫素值計算影像嵌入和位置影像嵌入。

型別SamModel 的例項方法
返回Promise.<{image_embeddings: Tensor, image_positional_embeddings: Tensor}> - 影像嵌入和位置影像嵌入。

引數量型別描述
model_inputsObject

包含模型輸入的物件。

model_inputs.pixel_values張量

使用 SamProcessor 獲得的畫素值。


samModel.forward(model_inputs) ⇒ <code> Promise. < Object > </code>

型別SamModel 的例項方法
返回Promise.<Object> - 模型的輸出。

引數量型別描述
model_inputsSamModelInputs

包含模型輸入的物件。


samModel._call(model_inputs) ⇒ <code> Promise. < SamImageSegmentationOutput > </code>

使用提供的輸入執行模型

型別SamModel 的例項方法
返回Promise.<SamImageSegmentationOutput> - 包含分割輸出的物件

引數量型別描述
model_inputsObject

模型輸入


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_inputsObject

模型的輸入。


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_inputsObject

模型的輸入。


models.UniSpeechModel

基礎 UniSpeech 模型轉換器,輸出原始的隱藏狀態,頂部沒有任何特定的頭部模組。

型別: models 的靜態類


models.UniSpeechForCTC

帶有一個用於連線時序分類 (CTC) 的 語言建模 頭部的 UniSpeech 模型。

型別: models 的靜態類


uniSpeechForCTC._call(model_inputs)

型別UniSpeechForCTC 的例項方法

引數量型別描述
model_inputsObject
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_inputsObject

模型的輸入。


models.UniSpeechSatModel

基礎 UniSpeechSat 模型轉換器,輸出原始的隱藏狀態,頂部沒有任何特定的頭部模組。

型別: models 的靜態類


models.UniSpeechSatForCTC

帶有一個用於連線時序分類 (CTC) 的 語言建模 頭部的 UniSpeechSat 模型。

型別: models 的靜態類


uniSpeechSatForCTC._call(model_inputs)

型別UniSpeechSatForCTC 的例項方法

引數量型別描述
model_inputsObject
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_inputsObject

模型的輸入。


models.UniSpeechSatForAudioFrameClassification

UniSpeechSat 模型,頂部帶有一個幀分類頭,用於如說話人分割等任務。

型別: models 的靜態類


uniSpeechSatForAudioFrameClassification._call(model_inputs) ⇒ <code> Promise. < TokenClassifierOutput > </code>

在新輸入上呼叫模型。

種類: UniSpeechSatForAudioFrameClassification 的例項方法
返回Promise.<TokenClassifierOutput> - 一個包含模型序列分類輸出 logits 的物件。

引數量型別描述
model_inputsObject

模型的輸入。


models.Wav2Vec2BertModel

基礎的 Wav2Vec2Bert 模型轉換器,輸出原始的隱藏狀態,頂部沒有任何特定的頭。

型別: models 的靜態類


models.Wav2Vec2BertForCTC

Wav2Vec2Bert 模型,頂部帶有一個用於連線時序分類 (CTC) 的 `語言建模` 頭。

型別: models 的靜態類


wav2Vec2BertForCTC._call(model_inputs)

種類: Wav2Vec2BertForCTC 的例項方法

引數量型別描述
model_inputsObject
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_inputsObject

模型的輸入。


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_inputsObject
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_inputsObject

模型的輸入。


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_inputsObject
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_inputsObject

模型的輸入。


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_inputsObject

模型的輸入。


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_inputsObject

模型的輸入。


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

將梅爾頻譜圖轉換為語音波形的聲碼器。如果為 null,則輸出為梅爾頻譜圖。

[options.output_cross_attentions]booleanfalse

是否返回解碼器交叉注意力層的注意力張量。


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_inputsObject

模型的輸入。


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) ⇒ <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張量

離散程式碼嵌入,形狀為 (batch_size, num_quantizers, codes_length)


models.MimiDecoderOutput

型別: models 的靜態類


new MimiDecoderOutput(output)

引數量型別描述
輸出Object

模型的輸出。

output.audio_values張量

解碼後的音訊值,形狀為 (batch_size, num_channels, sequence_length)


models.MimiModel

Mimi 神經音訊編解碼器模型。

型別: models 的靜態類


mimiModel.encode(inputs) ⇒ <code> Promise. < MimiEncoderOutput > </code>

將輸入音訊波形編碼為離散程式碼。

種類: MimiModel 的例項方法
返回: Promise.<MimiEncoderOutput> - 形狀為 (batch_size, num_codebooks, sequence_length) 的輸出張量。

引數量型別描述
輸入Object

模型輸入

[inputs.input_values]張量

輸入音訊波形的浮點數值,形狀為 (batch_size, channels, sequence_length))。


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張量

離散程式碼嵌入,形狀為 (batch_size, num_quantizers, codes_length)


models.DacDecoderOutput

型別: models 的靜態類


new DacDecoderOutput(output)

引數量型別描述
輸出Object

模型的輸出。

output.audio_values張量

解碼後的音訊值,形狀為 (batch_size, num_channels, sequence_length)


models.DacModel

DAC (Descript Audio Codec) 模型。

型別: models 的靜態類


dacModel.encode(inputs) ⇒ <code> Promise. < DacEncoderOutput > </code>

將輸入音訊波形編碼為離散程式碼。

種類: DacModel 的例項方法
返回: Promise.<DacEncoderOutput> - 形狀為 (batch_size, num_codebooks, sequence_length) 的輸出張量。

引數量型別描述
輸入Object

模型輸入

[inputs.input_values]張量

輸入音訊波形的浮點數值,形狀為 (batch_size, channels, sequence_length))。


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) ⇒ <code> Promise. < Record < string, Tensor > > </code>

將輸入音訊波形編碼為離散程式碼。

種類: SnacModel 的例項方法
返回: Promise.<Record<string, Tensor>> - 形狀為 (batch_size, num_codebooks, sequence_length) 的輸出張量。

引數量型別描述
輸入Object

模型輸入

[inputs.input_values]張量

輸入音訊波形的浮點數值,形狀為 (batch_size, channels, sequence_length))。


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>

torch.FloatTensor 物件(每層一個),形狀為 (batch_size, num_heads, sequence_length, sequence_length)。注意力 softmax 之後的注意力權重,用於計算自注意力頭中的加權平均值。


models.XVectorOutput

XVector 模型輸出的基類。

型別: models 的靜態類


new XVectorOutput(output)

引數量型別描述
輸出Object

模型的輸出。

output.logits張量

AMSoftmax 之前的分類隱藏狀態,形狀為 (batch_size, config.xvector_output_dim)

output.embeddings張量

用於基於向量相似度檢索的語句嵌入,形狀為 (batch_size, config.xvector_output_dim)


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張量

包含預計算的隱藏狀態(自注意力塊中的鍵和值),可用於(參見 past_key_values 輸入)加速順序解碼。


models.ImageMattingOutput

型別: models 的靜態類


new ImageMattingOutput(output)

引數量型別描述
輸出Object

模型的輸出。

output.alphas張量

估計的 alpha 值,形狀為 (batch_size, num_channels, height, width)


models.VitsModelOutput

描述 VITS 模型的輸出。

型別: models 的靜態類


new VitsModelOutput(output)

引數量型別描述
輸出Object

模型的輸出。

output.waveform張量

模型預測的最終音訊波形,形狀為 (batch_size, sequence_length)

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張量

形狀為 (batch_size, num_channels, height, width) 的畫素值張量。這些可以透過 SamProcessor 獲得。

[input_points]張量

形狀為 (batch_size, num_points, 2) 的輸入二維空間點。提示編碼器使用它來編碼提示。

[input_labels]張量

點的輸入標籤,形狀為 (batch_size, point_batch_size, num_points) 的張量。提示編碼器使用它來編碼提示。有 4 種標籤型別

  • 1:該點是包含感興趣物件的點
  • 0:該點是不包含感興趣物件的點
  • -1:該點對應於背景
  • -10:該點是填充點,因此提示編碼器應忽略
[input_boxes]張量

形狀為 (batch_size, num_boxes, 4) 的輸入邊界框。

[image_embeddings]張量

掩碼解碼器使用的影像嵌入。

[image_positional_embeddings]張量

掩碼解碼器使用的影像位置嵌入。


models~SpeechOutput : <code> Object </code>

型別: models 的內部 typedef
屬性

名稱型別描述
[spectrogram]張量

預測的對數梅爾頻譜圖,形狀為 (output_sequence_length, config.num_mel_bins)。在未提供 vocoder 時返回。

[waveform]張量

預測的波形,形狀為 (num_frames,)。在提供了 vocoder 時返回。

[cross_attentions]張量

解碼器交叉注意力層的輸出,形狀為 (config.decoder_layers, config.decoder_attention_heads, output_sequence_length, input_sequence_length)。當 output_cross_attentionstrue 時返回。


< > 在 GitHub 上更新

© . This site is unofficial and not affiliated with Hugging Face, Inc.