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.0.0).
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,
//   ...
// }

configs.PretrainedConfig

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

Kind: static class of configs


new PretrainedConfig(configJSON)

Create a new PreTrainedTokenizer instance.

ParamTypeDescription
configJSONObject

The JSON of the config.


pretrainedConfig.model_type : <code> string </code> | <code> null </code>

Kind: instance property of PretrainedConfig


pretrainedConfig.is_encoder_decoder : <code> boolean </code>

Kind: instance property of PretrainedConfig


pretrainedConfig.max_position_embeddings : <code> number </code>

Kind: instance property of PretrainedConfig


PretrainedConfig.from_pretrained(pretrained_model_name_or_path, options) β‡’ <code> Promise. < PretrainedConfig > </code>

Loads a pre-trained config from the given pretrained_model_name_or_path.

Kind: static method of PretrainedConfig
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`.
ParamTypeDescription
pretrained_model_name_or_pathstring

The path to the pre-trained config.

optionsPretrainedOptions

Additional options for loading the config.


configs.AutoConfig

Helper class which is used to instantiate pretrained configs with the from_pretrained function.

Kind: static class of configs


AutoConfig.from_pretrained() : <code> * </code>

Kind: static method of AutoConfig


configs.getKeyValueShapes(config) β‡’ <code> Record. < string, Array < number > > </code>

Kind: static method of configs

ParamType
configPretrainedConfig

getKeyValueShapes~decoderFeeds : <code> Record. < string, Array < number > > </code>

Kind: inner constant of getKeyValueShapes


configs~loadConfig(pretrained_model_name_or_path, options) β‡’ <code> Promise. < Object > </code>

Loads a config from the specified path.

Kind: inner method of configs
Returns: Promise.<Object> - A promise that resolves with information about the loaded config.

ParamTypeDescription
pretrained_model_name_or_pathstring

The path to the config directory.

optionsPretrainedOptions

Additional options for loading the config.


configs~getNormalizedConfig(config) β‡’ <code> Object </code>

Kind: inner method of configs
Returns: Object - The normalized configuration.

ParamType
configPretrainedConfig

configs~PretrainedOptions : <code> * </code>

Kind: inner typedef of configs


< > Update on GitHub