pub fn new<'p, P>(p: P, config: &ElectraConfig) -> ElectraModel
    where
        P: Borrow<nn::Path<'p>>,
    {
        let p = p.borrow();

        let embeddings = ElectraEmbeddings::new(p / "embeddings", config);
        let embeddings_project = if config.embedding_size != config.hidden_size {
            Some(nn::linear(
                p / "embeddings_project",
                config.embedding_size,
                config.hidden_size,
                Default::default(),
            ))
        } else {
            None
        };
        let bert_config = BertConfig {
            hidden_act: config.hidden_act.clone(),
            attention_probs_dropout_prob: config.attention_probs_dropout_prob,
            hidden_dropout_prob: config.hidden_dropout_prob,
            hidden_size: config.hidden_size,
            initializer_range: config.initializer_range,
            intermediate_size: config.intermediate_size,
            max_position_embeddings: config.max_position_embeddings,
            num_attention_heads: config.num_attention_heads,
            num_hidden_layers: config.num_hidden_layers,
            type_vocab_size: config.type_vocab_size,
            vocab_size: config.vocab_size,
            output_attentions: config.output_attentions,
            output_hidden_states: config.output_hidden_states,
            is_decoder: None,
            id2label: config.id2label.clone(),
            label2id: config.label2id.clone(),
        };
        let encoder = BertEncoder::new(p / "encoder", &bert_config);
        ElectraModel {
            embeddings,
            embeddings_project,
            encoder,
        }
    }
/// Build a new `ElectraModel`
///
/// # Arguments
///
/// * `p` - Variable store path for the root of the Electra model
/// * `config` - `ElectraConfig` object defining the model architecture
///
/// # Example
///
/// ```no_run
/// use rust_bert::electra::{ElectraConfig, ElectraModel};
/// use rust_bert::Config;
/// use std::path::Path;
/// use tch::{nn, Device};
///
/// let config_path = Path::new("path/to/config.json");
/// let device = Device::Cpu;
/// let p = nn::VarStore::new(device);
/// let config = ElectraConfig::from_file(config_path);
/// let electra_model: ElectraModel = ElectraModel::new(&p.root() / "electra", &config);
/// ```
Build a new `ElectraModel`
Build a new ` ElectraModel `
pub fn new<'p, P>(p: P, config: &ElectraConfig) -> ElectraModel
    where
        P: Borrow<nn::Path<'p>>,
    {
        let p = p.borrow();
        let embeddings = ElectraEmbeddings::new(p / "embeddings", config);
        let embeddings_project = if config.embedding_size != config.hidden_size {
            Some(nn::linear(
                p / "embeddings_project",
                config.embedding_size,
                config.hidden_size,
                Default::default(),
            ))
        } else {
            None
        };
        let bert_config = BertConfig {
            hidden_act: config.hidden_act.clone(),
            attention_probs_dropout_prob: config.attention_probs_dropout_prob,
            hidden_dropout_prob: config.hidden_dropout_prob,
            hidden_size: config.hidden_size,
            initializer_range: config.initializer_range,
            intermediate_size: config.intermediate_size,
            max_position_embeddings: config.max_position_embeddings,
            num_attention_heads: config.num_attention_heads,
            num_hidden_layers: config.num_hidden_layers,
            type_vocab_size: config.type_vocab_size,
            vocab_size: config.vocab_size,
            output_attentions: config.output_attentions,
            output_hidden_states: config.output_hidden_states,
            is_decoder: None,
            id2label: config.id2label.clone(),
            label2id: config.label2id.clone(),
        };
        let encoder = BertEncoder::new(p / "encoder", &bert_config);
        ElectraModel {
            embeddings,
            embeddings_project,
            encoder,
        }
    }
pub fn new < ' p , P > ( p : P , config : & ElectraConfig ) -> ElectraModel where P : Borrow < nn :: Path < ' p > > , { let p = p . borrow ( ) ; let embeddings = ElectraEmbeddings :: new ( p / " " , config ) ; let embeddings_project = if config . embedding_size != config . hidden_size { Some ( nn :: linear ( p / " " , config . embedding_size , config . hidden_size , Default :: default ( ) , ) ) } else { None } ; let bert_config = BertConfig { hidden_act : config . hidden_act . clone ( ) , attention_probs_dropout_prob : config . attention_probs_dropout_prob , hidden_dropout_prob : config . hidden_dropout_prob , hidden_size : config . hidden_size , initializer_range : config . initializer_range , intermediate_size : config . intermediate_size , max_position_embeddings : config . max_position_embeddings , num_attention_heads : config . num_attention_heads , num_hidden_layers : config . num_hidden_layers , type_vocab_size : config . type_vocab_size , vocab_size : config . vocab_size , output_attentions : config . output_attentions , output_hidden_states : config . output_hidden_states , is_decoder : None , id2label : config . id2label . clone ( ) , label2id : config . label2id . clone ( ) , } ; let encoder = BertEncoder :: new ( p / " " , & bert_config ) ; ElectraModel { embeddings , embeddings_project , encoder , } }
Build a new `ElectraModel`
Build a new ` ElectraModel `
p
P
config
&ElectraConfig
p
P
config
&ElectraConfig
example
```no_run
use rust_bert::electra::{ElectraConfig, ElectraModel};
use rust_bert::Config;
use std::path::Path;
use tch::{nn, Device}.

let config_path = Path::new("path/to/config.json");
let device = Device::Cpu;
let p = nn::VarStore::new(device);
let config = ElectraConfig::from_file(config_path);
let electra_model: ElectraModel = ElectraModel::new(&p.root() / "electra", &config);
```
` ` ` no_run use rust_bert :: electra :: { ElectraConfig ElectraModel } ; use rust_bert :: Config ; use std :: path :: Path ; use tch :: { nn Device } . let config_path = Path :: new ( " path / to / config . json " ) ; let device = Device :: Cpu ; let p = nn :: VarStore :: new ( device ) ; let config = ElectraConfig :: from_file ( config_path ) ; let electra_model : ElectraModel = ElectraModel :: new ( &p . root () / " electra " &config ) ; ` ` `