pub struct GPT2LMHeadModel { /* private fields */ }
Expand description
§GPT2 Language Modeling head
GPT2 model with a decoding head (linear layer without bias). The weights of the linear layer are tied to the word embeddings It is made of the following blocks:
transformer
: Base Gpt2Model
Implementations§
Source§impl GPT2LMHeadModel
impl GPT2LMHeadModel
Sourcepub fn new<'p, P>(p: P, config: &Gpt2Config) -> GPT2LMHeadModel
pub fn new<'p, P>(p: P, config: &Gpt2Config) -> GPT2LMHeadModel
Build a new GPT2LMHeadModel
§Arguments
p
- Variable store path for the root of the GPT2 modelconfig
-Gpt2Config
object defining the model architecture
§Example
use rust_bert::gpt2::{GPT2LMHeadModel, Gpt2Config};
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 = Gpt2Config::from_file(config_path);
let gpt2: GPT2LMHeadModel = GPT2LMHeadModel::new(&p.root() / "gpt2", &config);
pub fn forward_t( &self, input_ids: Option<&Tensor>, layer_past: Option<&Vec<Tensor>>, attention_mask: Option<&Tensor>, token_type_ids: Option<&Tensor>, position_ids: Option<&Tensor>, input_embeds: Option<&Tensor>, train: bool, ) -> Result<LMModelOutput, RustBertError>
Auto Trait Implementations§
impl Freeze for GPT2LMHeadModel
impl RefUnwindSafe for GPT2LMHeadModel
impl Send for GPT2LMHeadModel
impl !Sync for GPT2LMHeadModel
impl Unpin for GPT2LMHeadModel
impl UnwindSafe for GPT2LMHeadModel
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