UNPKG

@huggingface/transformers

Version:

State-of-the-art Machine Learning for the web. Run 🤗 Transformers directly in your browser, with no need for a server!

63 lines (58 loc) • 2.55 kB
import { PreTrainedModel } from '../modeling_utils.js'; import { CausalLMOutput, SequenceClassifierOutput } from '../modeling_outputs.js'; import { Wav2Vec2PreTrainedModel } from '../wav2vec2/modeling_wav2vec2.js'; import { Tensor } from '../../utils/tensor.js'; export class HubertPreTrainedModel extends PreTrainedModel {} /** * The bare Hubert Model transformer outputting raw hidden-states without any specific head on top. * * **Example:** Load and run a `HubertModel` for feature extraction. * * ```javascript * 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 * // } * // } * ``` */ export class HubertModel extends Wav2Vec2PreTrainedModel {} /** * Hubert Model with a `language modeling` head on top for Connectionist Temporal Classification (CTC). */ export class HubertForCTC extends Wav2Vec2PreTrainedModel { /** * @param {Object} model_inputs * @param {Tensor} model_inputs.input_values Float values of input raw speech waveform. * @param {Tensor} model_inputs.attention_mask Mask to avoid performing convolution and attention on padding token indices. Mask values selected in [0, 1] */ async _call(model_inputs) { return new CausalLMOutput(await super._call(model_inputs)); } } /** * Hubert Model with a sequence classification head on top (a linear layer over the pooled output) for tasks like SUPERB Keyword Spotting. */ export class HubertForSequenceClassification extends Wav2Vec2PreTrainedModel { /** * Calls the model on new inputs. * @param {Object} model_inputs The inputs to the model. * @returns {Promise<SequenceClassifierOutput>} An object containing the model's output logits for sequence classification. */ async _call(model_inputs) { return new SequenceClassifierOutput(await super._call(model_inputs)); } }