pub struct ElectraGeneratorHead { /* private fields */ }
Expand description
§Electra Generator head
Generator head for Electra models It is made of the following blocks:
dense
: linear layer of dimension (hidden_size, embeddings_size) to project the model output dimension to the embeddings sizelayer_norm
: Layer normalizationactivation
: GeLU activation
Implementations§
Source§impl ElectraGeneratorHead
Defines the implementation of the ElectraGeneratorHead.
impl ElectraGeneratorHead
Defines the implementation of the ElectraGeneratorHead.
Sourcepub fn new<'p, P>(p: P, config: &ElectraConfig) -> ElectraGeneratorHead
pub fn new<'p, P>(p: P, config: &ElectraConfig) -> ElectraGeneratorHead
Build a new ElectraGeneratorHead
§Arguments
p
- Variable store path for the root of the Electra modelconfig
-ElectraConfig
object defining the model architecture
§Example
use rust_bert::electra::{ElectraConfig, ElectraGeneratorHead};
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 generator_head = ElectraGeneratorHead::new(&p.root() / "electra", &config);
Sourcepub fn forward(&self, encoder_hidden_states: &Tensor) -> Tensor
pub fn forward(&self, encoder_hidden_states: &Tensor) -> Tensor
Forward pass through the generator head
§Arguments
encoder_hidden_states
- Reference to input tensor of shape (batch size, sequence_length, hidden_size).
§Returns
output
-Tensor
of shape (batch size, sequence_length, embeddings_size)
§Example
let (batch_size, sequence_length) = (64, 128);
let input_tensor = Tensor::rand(
&[batch_size, sequence_length, config.hidden_size],
(Float, device),
);
let output = no_grad(|| generator_head.forward(&input_tensor));
Auto Trait Implementations§
impl Freeze for ElectraGeneratorHead
impl RefUnwindSafe for ElectraGeneratorHead
impl Send for ElectraGeneratorHead
impl !Sync for ElectraGeneratorHead
impl Unpin for ElectraGeneratorHead
impl UnwindSafe for ElectraGeneratorHead
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more