Transformers.js documentation

configs

You are viewing main version, which requires installation from source. If you'd like regular npm install, checkout the latest stable version (v3.8.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

configs

Helper module for using model configs. For more information, see the corresponding Python documentation.

Example: Load an AutoConfig.

import { AutoConfig } from '@huggingface/transformers';
const config = await AutoConfig.from_pretrained('bert-base-uncased');
console.log(config);
// PretrainedConfig {
//   "model_type": "bert",
//   "is_encoder_decoder": false,
//   "architectures": [
//       "BertForMaskedLM"
//   ],
//   "vocab_size": 30522
//   "num_attention_heads": 12,
//   "num_hidden_layers": 12,
//   "hidden_size": 768,
//   "max_position_embeddings": 512,
//   ...
// }

Classes

PretrainedConfig

Base class for all configuration classes. For more information, see the corresponding Python documentation.

PretrainedConfig.model_type : string | null

Default: null

PretrainedConfig.is_encoder_decoder : boolean

Default: false

PretrainedConfig.max_position_embeddings : number

PretrainedConfig.'transformers.js_config' : TransformersJSConfig

PretrainedConfig.constructor(configJSON)

Create a new PretrainedConfig from a parsed config.json object.

Parameters

  • configJSON (Object) β€” The JSON of the config.

PretrainedConfig.from_pretrained(pretrained_model_name_or_path, options)

Loads a pretrained config from the given pretrained_model_name_or_path.

Parameters

  • pretrained_model_name_or_path (string) β€” The path to the pretrained config.
  • options (PretrainedOptions) β€” Additional options for loading the config.

Returns: Promise<PretrainedConfig> β€” A new instance of the PretrainedConfig class.

Throws

  • Error β€” Throws an error if the config.json is not found in the pretrained_model_name_or_path.

AutoConfig

Loads a model config from a pretrained id. Thin alias for PretrainedConfig.from_pretrained.

import { AutoConfig } from '@huggingface/transformers';

const config = await AutoConfig.from_pretrained('Xenova/bert-base-uncased');

AutoConfig.from_pretrained(pretrained_model_name_or_path, options)

Loads a pretrained config from the given pretrained_model_name_or_path.

Parameters

  • pretrained_model_name_or_path (string) β€” The path to the pretrained config.
  • options (PretrainedOptions) β€” Additional options for loading the config.

Returns: Promise<PretrainedConfig> β€” A new instance of the PretrainedConfig class.

Throws

  • Error β€” Throws an error if the config.json is not found in the pretrained_model_name_or_path.

Type Definitions

TransformersJSConfig

Transformers.js-specific configuration, possibly present in config.json under the key transformers.js_config.

Properties

DeviceConfig

Device-specific configuration options.

Type: Omit<TransformersJSConfig, 'device' | 'device_config'>

Update on GitHub