import{S as jc,i as Pc,s as Lc,e as r,k as h,w as k,t as s,M as Oc,c as i,d as o,m,a as l,x as M,h as a,b as u,G as e,g as b,y as w,q as y,o as T,B as $,v as Sc,L as we}from"../../chunks/vendor-hf-doc-builder.js";import{T as ho}from"../../chunks/Tip-hf-doc-builder.js";import{D as N}from"../../chunks/Docstring-hf-doc-builder.js";import{C as ye}from"../../chunks/CodeBlock-hf-doc-builder.js";import{I as te}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{E as Me}from"../../chunks/ExampleCodeBlock-hf-doc-builder.js";function Nc(z){let d,v,g,p,_;return p=new ye({props:{code:`from transformers import MegaConfig, MegaModel

# Initializing a Mega configuration
configuration = MegaConfig()

# Initializing a model (with random weights) from the configuration
model = MegaModel(configuration)

# Accessing the model configuration
configuration = model.config`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> MegaConfig, MegaModel

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Initializing a Mega configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>configuration = MegaConfig()

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Initializing a model (with random weights) from the configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = MegaModel(configuration)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Accessing the model configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>configuration = model.config`}}),{c(){d=r("p"),v=s("Examples:"),g=h(),k(p.$$.fragment)},l(n){d=i(n,"P",{});var c=l(d);v=a(c,"Examples:"),c.forEach(o),g=m(n),M(p.$$.fragment,n)},m(n,c){b(n,d,c),e(d,v),b(n,g,c),w(p,n,c),_=!0},p:we,i(n){_||(y(p.$$.fragment,n),_=!0)},o(n){T(p.$$.fragment,n),_=!1},d(n){n&&o(d),n&&o(g),$(p,n)}}}function Ic(z){let d,v,g,p,_;return{c(){d=r("p"),v=s("Although the recipe for forward pass needs to be defined within this function, one should call the "),g=r("code"),p=s("Module"),_=s(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(n){d=i(n,"P",{});var c=l(d);v=a(c,"Although the recipe for forward pass needs to be defined within this function, one should call the "),g=i(c,"CODE",{});var x=l(g);p=a(x,"Module"),x.forEach(o),_=a(c,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),c.forEach(o)},m(n,c){b(n,d,c),e(d,v),e(d,g),e(g,p),e(d,_)},d(n){n&&o(d)}}}function Dc(z){let d,v,g,p,_;return p=new ye({props:{code:`from transformers import AutoTokenizer, MegaModel
import torch

tokenizer = AutoTokenizer.from_pretrained("mnaylor/mega-base-wikitext")
model = MegaModel.from_pretrained("mnaylor/mega-base-wikitext")

inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")
outputs = model(**inputs)

last_hidden_states = outputs.last_hidden_state`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, MegaModel
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;mnaylor/mega-base-wikitext&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = MegaModel.from_pretrained(<span class="hljs-string">&quot;mnaylor/mega-base-wikitext&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(<span class="hljs-string">&quot;Hello, my dog is cute&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(**inputs)

<span class="hljs-meta">&gt;&gt;&gt; </span>last_hidden_states = outputs.last_hidden_state`}}),{c(){d=r("p"),v=s("Example:"),g=h(),k(p.$$.fragment)},l(n){d=i(n,"P",{});var c=l(d);v=a(c,"Example:"),c.forEach(o),g=m(n),M(p.$$.fragment,n)},m(n,c){b(n,d,c),e(d,v),b(n,g,c),w(p,n,c),_=!0},p:we,i(n){_||(y(p.$$.fragment,n),_=!0)},o(n){T(p.$$.fragment,n),_=!1},d(n){n&&o(d),n&&o(g),$(p,n)}}}function Wc(z){let d,v,g,p,_;return{c(){d=r("p"),v=s("Although the recipe for forward pass needs to be defined within this function, one should call the "),g=r("code"),p=s("Module"),_=s(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(n){d=i(n,"P",{});var c=l(d);v=a(c,"Although the recipe for forward pass needs to be defined within this function, one should call the "),g=i(c,"CODE",{});var x=l(g);p=a(x,"Module"),x.forEach(o),_=a(c,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),c.forEach(o)},m(n,c){b(n,d,c),e(d,v),e(d,g),e(g,p),e(d,_)},d(n){n&&o(d)}}}function Gc(z){let d,v,g,p,_;return p=new ye({props:{code:`from transformers import AutoTokenizer, MegaForCausalLM, AutoConfig
import torch

tokenizer = AutoTokenizer.from_pretrained("mnaylor/mega-base-wikitext")
config = AutoConfig.from_pretrained("mnaylor/mega-base-wikitext")
config.is_decoder = True
config.bidirectional = False
model = MegaForCausalLM.from_pretrained("mnaylor/mega-base-wikitext", config=config)

inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")
outputs = model(**inputs)

prediction_logits = outputs.logits`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, MegaForCausalLM, AutoConfig
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;mnaylor/mega-base-wikitext&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>config = AutoConfig.from_pretrained(<span class="hljs-string">&quot;mnaylor/mega-base-wikitext&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>config.is_decoder = <span class="hljs-literal">True</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>config.bidirectional = <span class="hljs-literal">False</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = MegaForCausalLM.from_pretrained(<span class="hljs-string">&quot;mnaylor/mega-base-wikitext&quot;</span>, config=config)

<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(<span class="hljs-string">&quot;Hello, my dog is cute&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(**inputs)

<span class="hljs-meta">&gt;&gt;&gt; </span>prediction_logits = outputs.logits`}}),{c(){d=r("p"),v=s("Example:"),g=h(),k(p.$$.fragment)},l(n){d=i(n,"P",{});var c=l(d);v=a(c,"Example:"),c.forEach(o),g=m(n),M(p.$$.fragment,n)},m(n,c){b(n,d,c),e(d,v),b(n,g,c),w(p,n,c),_=!0},p:we,i(n){_||(y(p.$$.fragment,n),_=!0)},o(n){T(p.$$.fragment,n),_=!1},d(n){n&&o(d),n&&o(g),$(p,n)}}}function Hc(z){let d,v,g,p,_;return{c(){d=r("p"),v=s("Although the recipe for forward pass needs to be defined within this function, one should call the "),g=r("code"),p=s("Module"),_=s(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(n){d=i(n,"P",{});var c=l(d);v=a(c,"Although the recipe for forward pass needs to be defined within this function, one should call the "),g=i(c,"CODE",{});var x=l(g);p=a(x,"Module"),x.forEach(o),_=a(c,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),c.forEach(o)},m(n,c){b(n,d,c),e(d,v),e(d,g),e(g,p),e(d,_)},d(n){n&&o(d)}}}function Qc(z){let d,v,g,p,_;return p=new ye({props:{code:`from transformers import AutoTokenizer, MegaForMaskedLM
import torch

tokenizer = AutoTokenizer.from_pretrained("mnaylor/mega-base-wikitext")
model = MegaForMaskedLM.from_pretrained("mnaylor/mega-base-wikitext")

inputs = tokenizer("The capital of France is <mask>.", return_tensors="pt")

with torch.no_grad():
    logits = model(**inputs).logits

# retrieve index of <mask>
mask_token_index = (inputs.input_ids == tokenizer.mask_token_id)[0].nonzero(as_tuple=True)[0]

predicted_token_id = logits[0, mask_token_index].argmax(axis=-1)
tokenizer.decode(predicted_token_id)

labels = tokenizer("The capital of France is Paris.", return_tensors="pt")["input_ids"]
# mask labels of non-<mask> tokens
labels = torch.where(inputs.input_ids == tokenizer.mask_token_id, labels, -100)

outputs = model(**inputs, labels=labels)
round(outputs.loss.item(), 2)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, MegaForMaskedLM
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;mnaylor/mega-base-wikitext&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = MegaForMaskedLM.from_pretrained(<span class="hljs-string">&quot;mnaylor/mega-base-wikitext&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(<span class="hljs-string">&quot;The capital of France is &lt;mask&gt;.&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>    logits = model(**inputs).logits

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># retrieve index of &lt;mask&gt;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>mask_token_index = (inputs.input_ids == tokenizer.mask_token_id)[<span class="hljs-number">0</span>].nonzero(as_tuple=<span class="hljs-literal">True</span>)[<span class="hljs-number">0</span>]

<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_token_id = logits[<span class="hljs-number">0</span>, mask_token_index].argmax(axis=-<span class="hljs-number">1</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.decode(predicted_token_id)
<span class="hljs-string">&#x27; Paris&#x27;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>labels = tokenizer(<span class="hljs-string">&quot;The capital of France is Paris.&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)[<span class="hljs-string">&quot;input_ids&quot;</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># mask labels of non-&lt;mask&gt; tokens</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>labels = torch.where(inputs.input_ids == tokenizer.mask_token_id, labels, -<span class="hljs-number">100</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(**inputs, labels=labels)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">round</span>(outputs.loss.item(), <span class="hljs-number">2</span>)
<span class="hljs-number">0.1</span>`}}),{c(){d=r("p"),v=s("Example:"),g=h(),k(p.$$.fragment)},l(n){d=i(n,"P",{});var c=l(d);v=a(c,"Example:"),c.forEach(o),g=m(n),M(p.$$.fragment,n)},m(n,c){b(n,d,c),e(d,v),b(n,g,c),w(p,n,c),_=!0},p:we,i(n){_||(y(p.$$.fragment,n),_=!0)},o(n){T(p.$$.fragment,n),_=!1},d(n){n&&o(d),n&&o(g),$(p,n)}}}function Uc(z){let d,v,g,p,_;return{c(){d=r("p"),v=s("Although the recipe for forward pass needs to be defined within this function, one should call the "),g=r("code"),p=s("Module"),_=s(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(n){d=i(n,"P",{});var c=l(d);v=a(c,"Although the recipe for forward pass needs to be defined within this function, one should call the "),g=i(c,"CODE",{});var x=l(g);p=a(x,"Module"),x.forEach(o),_=a(c,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),c.forEach(o)},m(n,c){b(n,d,c),e(d,v),e(d,g),e(g,p),e(d,_)},d(n){n&&o(d)}}}function Rc(z){let d,v,g,p,_;return p=new ye({props:{code:`import torch
from transformers import AutoTokenizer, MegaForSequenceClassification

tokenizer = AutoTokenizer.from_pretrained("mnaylor/mega-base-wikitext")
model = MegaForSequenceClassification.from_pretrained("mnaylor/mega-base-wikitext")

inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")

with torch.no_grad():
    logits = model(**inputs).logits

predicted_class_id = logits.argmax().item()

# To train a model on \`num_labels\` classes, you can pass \`num_labels=num_labels\` to \`.from_pretrained(...)\`
num_labels = len(model.config.id2label)
model = MegaForSequenceClassification.from_pretrained("mnaylor/mega-base-wikitext", num_labels=num_labels)

labels = torch.tensor([1])
loss = model(**inputs, labels=labels).loss`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, MegaForSequenceClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;mnaylor/mega-base-wikitext&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = MegaForSequenceClassification.from_pretrained(<span class="hljs-string">&quot;mnaylor/mega-base-wikitext&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(<span class="hljs-string">&quot;Hello, my dog is cute&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>    logits = model(**inputs).logits

<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_class_id = logits.argmax().item()

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># To train a model on \`num_labels\` classes, you can pass \`num_labels=num_labels\` to \`.from_pretrained(...)\`</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>num_labels = <span class="hljs-built_in">len</span>(model.config.id2label)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = MegaForSequenceClassification.from_pretrained(<span class="hljs-string">&quot;mnaylor/mega-base-wikitext&quot;</span>, num_labels=num_labels)

<span class="hljs-meta">&gt;&gt;&gt; </span>labels = torch.tensor([<span class="hljs-number">1</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span>loss = model(**inputs, labels=labels).loss`}}),{c(){d=r("p"),v=s("Example of single-label classification:"),g=h(),k(p.$$.fragment)},l(n){d=i(n,"P",{});var c=l(d);v=a(c,"Example of single-label classification:"),c.forEach(o),g=m(n),M(p.$$.fragment,n)},m(n,c){b(n,d,c),e(d,v),b(n,g,c),w(p,n,c),_=!0},p:we,i(n){_||(y(p.$$.fragment,n),_=!0)},o(n){T(p.$$.fragment,n),_=!1},d(n){n&&o(d),n&&o(g),$(p,n)}}}function Bc(z){let d,v,g,p,_;return p=new ye({props:{code:`import torch
from transformers import AutoTokenizer, MegaForSequenceClassification

tokenizer = AutoTokenizer.from_pretrained("mnaylor/mega-base-wikitext")
model = MegaForSequenceClassification.from_pretrained("mnaylor/mega-base-wikitext", problem_type="multi_label_classification")

inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")

with torch.no_grad():
    logits = model(**inputs).logits

predicted_class_ids = torch.arange(0, logits.shape[-1])[torch.sigmoid(logits).squeeze(dim=0) > 0.5]

# To train a model on \`num_labels\` classes, you can pass \`num_labels=num_labels\` to \`.from_pretrained(...)\`
num_labels = len(model.config.id2label)
model = MegaForSequenceClassification.from_pretrained(
    "mnaylor/mega-base-wikitext", num_labels=num_labels, problem_type="multi_label_classification"
)

labels = torch.sum(
    torch.nn.functional.one_hot(predicted_class_ids[None, :].clone(), num_classes=num_labels), dim=1
).to(torch.float)
loss = model(**inputs, labels=labels).loss`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, MegaForSequenceClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;mnaylor/mega-base-wikitext&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = MegaForSequenceClassification.from_pretrained(<span class="hljs-string">&quot;mnaylor/mega-base-wikitext&quot;</span>, problem_type=<span class="hljs-string">&quot;multi_label_classification&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(<span class="hljs-string">&quot;Hello, my dog is cute&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>    logits = model(**inputs).logits

<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_class_ids = torch.arange(<span class="hljs-number">0</span>, logits.shape[-<span class="hljs-number">1</span>])[torch.sigmoid(logits).squeeze(dim=<span class="hljs-number">0</span>) &gt; <span class="hljs-number">0.5</span>]

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># To train a model on \`num_labels\` classes, you can pass \`num_labels=num_labels\` to \`.from_pretrained(...)\`</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>num_labels = <span class="hljs-built_in">len</span>(model.config.id2label)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = MegaForSequenceClassification.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;mnaylor/mega-base-wikitext&quot;</span>, num_labels=num_labels, problem_type=<span class="hljs-string">&quot;multi_label_classification&quot;</span>
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>labels = torch.<span class="hljs-built_in">sum</span>(
<span class="hljs-meta">... </span>    torch.nn.functional.one_hot(predicted_class_ids[<span class="hljs-literal">None</span>, :].clone(), num_classes=num_labels), dim=<span class="hljs-number">1</span>
<span class="hljs-meta">... </span>).to(torch.<span class="hljs-built_in">float</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>loss = model(**inputs, labels=labels).loss`}}),{c(){d=r("p"),v=s("Example of multi-label classification:"),g=h(),k(p.$$.fragment)},l(n){d=i(n,"P",{});var c=l(d);v=a(c,"Example of multi-label classification:"),c.forEach(o),g=m(n),M(p.$$.fragment,n)},m(n,c){b(n,d,c),e(d,v),b(n,g,c),w(p,n,c),_=!0},p:we,i(n){_||(y(p.$$.fragment,n),_=!0)},o(n){T(p.$$.fragment,n),_=!1},d(n){n&&o(d),n&&o(g),$(p,n)}}}function Vc(z){let d,v,g,p,_;return{c(){d=r("p"),v=s("Although the recipe for forward pass needs to be defined within this function, one should call the "),g=r("code"),p=s("Module"),_=s(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(n){d=i(n,"P",{});var c=l(d);v=a(c,"Although the recipe for forward pass needs to be defined within this function, one should call the "),g=i(c,"CODE",{});var x=l(g);p=a(x,"Module"),x.forEach(o),_=a(c,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),c.forEach(o)},m(n,c){b(n,d,c),e(d,v),e(d,g),e(g,p),e(d,_)},d(n){n&&o(d)}}}function Jc(z){let d,v,g,p,_;return p=new ye({props:{code:`from transformers import AutoTokenizer, MegaForMultipleChoice
import torch

tokenizer = AutoTokenizer.from_pretrained("mnaylor/mega-base-wikitext")
model = MegaForMultipleChoice.from_pretrained("mnaylor/mega-base-wikitext")

prompt = "In Italy, pizza served in formal settings, such as at a restaurant, is presented unsliced."
choice0 = "It is eaten with a fork and a knife."
choice1 = "It is eaten while held in the hand."
labels = torch.tensor(0).unsqueeze(0)  # choice0 is correct (according to Wikipedia ;)), batch size 1

encoding = tokenizer([prompt, prompt], [choice0, choice1], return_tensors="pt", padding=True)
outputs = model(**{k: v.unsqueeze(0) for k, v in encoding.items()}, labels=labels)  # batch size is 1

# the linear classifier still needs to be trained
loss = outputs.loss
logits = outputs.logits`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, MegaForMultipleChoice
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;mnaylor/mega-base-wikitext&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = MegaForMultipleChoice.from_pretrained(<span class="hljs-string">&quot;mnaylor/mega-base-wikitext&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>prompt = <span class="hljs-string">&quot;In Italy, pizza served in formal settings, such as at a restaurant, is presented unsliced.&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>choice0 = <span class="hljs-string">&quot;It is eaten with a fork and a knife.&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>choice1 = <span class="hljs-string">&quot;It is eaten while held in the hand.&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>labels = torch.tensor(<span class="hljs-number">0</span>).unsqueeze(<span class="hljs-number">0</span>)  <span class="hljs-comment"># choice0 is correct (according to Wikipedia ;)), batch size 1</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>encoding = tokenizer([prompt, prompt], [choice0, choice1], return_tensors=<span class="hljs-string">&quot;pt&quot;</span>, padding=<span class="hljs-literal">True</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(**{k: v.unsqueeze(<span class="hljs-number">0</span>) <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> encoding.items()}, labels=labels)  <span class="hljs-comment"># batch size is 1</span>

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># the linear classifier still needs to be trained</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>loss = outputs.loss
<span class="hljs-meta">&gt;&gt;&gt; </span>logits = outputs.logits`}}),{c(){d=r("p"),v=s("Example:"),g=h(),k(p.$$.fragment)},l(n){d=i(n,"P",{});var c=l(d);v=a(c,"Example:"),c.forEach(o),g=m(n),M(p.$$.fragment,n)},m(n,c){b(n,d,c),e(d,v),b(n,g,c),w(p,n,c),_=!0},p:we,i(n){_||(y(p.$$.fragment,n),_=!0)},o(n){T(p.$$.fragment,n),_=!1},d(n){n&&o(d),n&&o(g),$(p,n)}}}function Xc(z){let d,v,g,p,_;return{c(){d=r("p"),v=s("Although the recipe for forward pass needs to be defined within this function, one should call the "),g=r("code"),p=s("Module"),_=s(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(n){d=i(n,"P",{});var c=l(d);v=a(c,"Although the recipe for forward pass needs to be defined within this function, one should call the "),g=i(c,"CODE",{});var x=l(g);p=a(x,"Module"),x.forEach(o),_=a(c,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),c.forEach(o)},m(n,c){b(n,d,c),e(d,v),e(d,g),e(g,p),e(d,_)},d(n){n&&o(d)}}}function Zc(z){let d,v,g,p,_;return p=new ye({props:{code:`from transformers import AutoTokenizer, MegaForTokenClassification
import torch

tokenizer = AutoTokenizer.from_pretrained("mnaylor/mega-base-wikitext")
model = MegaForTokenClassification.from_pretrained("mnaylor/mega-base-wikitext")

inputs = tokenizer(
    "HuggingFace is a company based in Paris and New York", add_special_tokens=False, return_tensors="pt"
)

with torch.no_grad():
    logits = model(**inputs).logits

predicted_token_class_ids = logits.argmax(-1)

# Note that tokens are classified rather then input words which means that
# there might be more predicted token classes than words.
# Multiple token classes might account for the same word
predicted_tokens_classes = [model.config.id2label[t.item()] for t in predicted_token_class_ids[0]]

labels = predicted_token_class_ids
loss = model(**inputs, labels=labels).loss`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, MegaForTokenClassification
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;mnaylor/mega-base-wikitext&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = MegaForTokenClassification.from_pretrained(<span class="hljs-string">&quot;mnaylor/mega-base-wikitext&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;HuggingFace is a company based in Paris and New York&quot;</span>, add_special_tokens=<span class="hljs-literal">False</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>    logits = model(**inputs).logits

<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_token_class_ids = logits.argmax(-<span class="hljs-number">1</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Note that tokens are classified rather then input words which means that</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># there might be more predicted token classes than words.</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Multiple token classes might account for the same word</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_tokens_classes = [model.config.id2label[t.item()] <span class="hljs-keyword">for</span> t <span class="hljs-keyword">in</span> predicted_token_class_ids[<span class="hljs-number">0</span>]]

<span class="hljs-meta">&gt;&gt;&gt; </span>labels = predicted_token_class_ids
<span class="hljs-meta">&gt;&gt;&gt; </span>loss = model(**inputs, labels=labels).loss`}}),{c(){d=r("p"),v=s("Example:"),g=h(),k(p.$$.fragment)},l(n){d=i(n,"P",{});var c=l(d);v=a(c,"Example:"),c.forEach(o),g=m(n),M(p.$$.fragment,n)},m(n,c){b(n,d,c),e(d,v),b(n,g,c),w(p,n,c),_=!0},p:we,i(n){_||(y(p.$$.fragment,n),_=!0)},o(n){T(p.$$.fragment,n),_=!1},d(n){n&&o(d),n&&o(g),$(p,n)}}}function Kc(z){let d,v,g,p,_;return{c(){d=r("p"),v=s("Although the recipe for forward pass needs to be defined within this function, one should call the "),g=r("code"),p=s("Module"),_=s(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(n){d=i(n,"P",{});var c=l(d);v=a(c,"Although the recipe for forward pass needs to be defined within this function, one should call the "),g=i(c,"CODE",{});var x=l(g);p=a(x,"Module"),x.forEach(o),_=a(c,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),c.forEach(o)},m(n,c){b(n,d,c),e(d,v),e(d,g),e(g,p),e(d,_)},d(n){n&&o(d)}}}function Yc(z){let d,v,g,p,_;return p=new ye({props:{code:`from transformers import AutoTokenizer, MegaForQuestionAnswering
import torch

tokenizer = AutoTokenizer.from_pretrained("mnaylor/mega-base-wikitext")
model = MegaForQuestionAnswering.from_pretrained("mnaylor/mega-base-wikitext")

question, text = "Who was Jim Henson?", "Jim Henson was a nice puppet"

inputs = tokenizer(question, text, return_tensors="pt")
with torch.no_grad():
    outputs = model(**inputs)

answer_start_index = outputs.start_logits.argmax()
answer_end_index = outputs.end_logits.argmax()

predict_answer_tokens = inputs.input_ids[0, answer_start_index : answer_end_index + 1]

# target is "nice puppet"
target_start_index = torch.tensor([14])
target_end_index = torch.tensor([15])

outputs = model(**inputs, start_positions=target_start_index, end_positions=target_end_index)
loss = outputs.loss`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, MegaForQuestionAnswering
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;mnaylor/mega-base-wikitext&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = MegaForQuestionAnswering.from_pretrained(<span class="hljs-string">&quot;mnaylor/mega-base-wikitext&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>question, text = <span class="hljs-string">&quot;Who was Jim Henson?&quot;</span>, <span class="hljs-string">&quot;Jim Henson was a nice puppet&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(question, text, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>    outputs = model(**inputs)

<span class="hljs-meta">&gt;&gt;&gt; </span>answer_start_index = outputs.start_logits.argmax()
<span class="hljs-meta">&gt;&gt;&gt; </span>answer_end_index = outputs.end_logits.argmax()

<span class="hljs-meta">&gt;&gt;&gt; </span>predict_answer_tokens = inputs.input_ids[<span class="hljs-number">0</span>, answer_start_index : answer_end_index + <span class="hljs-number">1</span>]

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># target is &quot;nice puppet&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>target_start_index = torch.tensor([<span class="hljs-number">14</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span>target_end_index = torch.tensor([<span class="hljs-number">15</span>])

<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(**inputs, start_positions=target_start_index, end_positions=target_end_index)
<span class="hljs-meta">&gt;&gt;&gt; </span>loss = outputs.loss`}}),{c(){d=r("p"),v=s("Example:"),g=h(),k(p.$$.fragment)},l(n){d=i(n,"P",{});var c=l(d);v=a(c,"Example:"),c.forEach(o),g=m(n),M(p.$$.fragment,n)},m(n,c){b(n,d,c),e(d,v),b(n,g,c),w(p,n,c),_=!0},p:we,i(n){_||(y(p.$$.fragment,n),_=!0)},o(n){T(p.$$.fragment,n),_=!1},d(n){n&&o(d),n&&o(g),$(p,n)}}}function ep(z){let d,v,g,p,_,n,c,x,Zs,Yn,oe,Te,Uo,rt,Ks,Ro,Ys,es,$e,ea,it,ta,oa,ts,mo,na,os,uo,Bo,sa,ns,go,aa,ss,ze,lt,ra,Vo,ia,la,da,Jo,ca,as,B,pa,dt,ha,ma,ct,ua,ga,rs,fo,fa,is,xe,Xo,_a,ba,Zo,va,ls,ne,Fe,Ko,pt,ka,Yo,Ma,ds,D,ht,wa,se,ya,_o,Ta,$a,mt,za,xa,Fa,ae,qa,bo,Ca,Ea,vo,Aa,ja,Pa,qe,cs,re,Ce,en,ut,La,tn,Oa,ps,q,gt,Sa,on,Na,Ia,ft,Da,ko,Wa,Ga,Ha,_t,Qa,bt,Ua,Ra,Ba,vt,Va,nn,Ja,Xa,Za,F,Ka,sn,Ya,er,an,tr,or,rn,nr,sr,ln,ar,rr,dn,ir,lr,cn,dr,cr,pn,pr,hr,hn,mr,ur,mn,gr,fr,_r,Ee,br,un,vr,kr,kt,Mr,wr,W,Mt,yr,ie,Tr,Mo,$r,zr,gn,xr,Fr,qr,Ae,Cr,je,hs,le,Pe,fn,wt,Er,_n,Ar,ms,A,yt,jr,Tt,Pr,bn,Lr,Or,Sr,$t,Nr,wo,Ir,Dr,Wr,zt,Gr,xt,Hr,Qr,Ur,G,Ft,Rr,de,Br,yo,Vr,Jr,vn,Xr,Zr,Kr,Le,Yr,Oe,us,ce,Se,kn,qt,ei,Mn,ti,gs,j,Ct,oi,Et,ni,wn,si,ai,ri,At,ii,To,li,di,ci,jt,pi,Pt,hi,mi,ui,H,Lt,gi,pe,fi,$o,_i,bi,yn,vi,ki,Mi,Ne,wi,Ie,fs,he,De,Tn,Ot,yi,$n,Ti,_s,P,St,$i,zn,zi,xi,Nt,Fi,zo,qi,Ci,Ei,It,Ai,Dt,ji,Pi,Li,I,Wt,Oi,me,Si,xo,Ni,Ii,xn,Di,Wi,Gi,We,Hi,Ge,Qi,He,bs,ue,Qe,Fn,Gt,Ui,qn,Ri,vs,L,Ht,Bi,Cn,Vi,Ji,Qt,Xi,Fo,Zi,Ki,Yi,Ut,el,Rt,tl,ol,nl,Q,Bt,sl,ge,al,qo,rl,il,En,ll,dl,cl,Ue,pl,Re,ks,fe,Be,An,Vt,hl,jn,ml,Ms,O,Jt,ul,Pn,gl,fl,Xt,_l,Co,bl,vl,kl,Zt,Ml,Kt,wl,yl,Tl,U,Yt,$l,_e,zl,Eo,xl,Fl,Ln,ql,Cl,El,Ve,Al,Je,ws,be,Xe,On,eo,jl,Sn,Pl,ys,S,to,Ll,ve,Ol,Nn,Sl,Nl,In,Il,Dl,Wl,oo,Gl,Ao,Hl,Ql,Ul,no,Rl,so,Bl,Vl,Jl,R,ao,Xl,ke,Zl,jo,Kl,Yl,Dn,ed,td,od,Ze,nd,Ke,Ts;return n=new te({}),rt=new te({}),pt=new te({}),ht=new N({props:{name:"class transformers.MegaConfig",anchor:"transformers.MegaConfig",parameters:[{name:"vocab_size",val:" = 30522"},{name:"hidden_size",val:" = 128"},{name:"num_hidden_layers",val:" = 4"},{name:"intermediate_size",val:" = 256"},{name:"ema_projection_size",val:" = 16"},{name:"bidirectional",val:" = True"},{name:"shared_representation_size",val:" = 64"},{name:"use_chunking",val:" = False"},{name:"chunk_size",val:" = -1"},{name:"truncation",val:" = None"},{name:"normalize_before_mega",val:" = True"},{name:"normalization_type",val:" = 'scalenorm'"},{name:"norm_affine",val:" = True"},{name:"activation",val:" = 'silu'"},{name:"attention_activation",val:" = 'softmax'"},{name:"dropout_prob",val:" = 0.1"},{name:"hidden_dropout_prob",val:" = 0.1"},{name:"attention_probs_dropout_prob",val:" = 0.1"},{name:"use_feature_dropout",val:" = False"},{name:"use_normalized_ffn",val:" = True"},{name:"nffn_hidden_size",val:" = 256"},{name:"normalize_before_ffn",val:" = True"},{name:"nffn_activation_dropout_prob",val:" = 0.1"},{name:"max_positions",val:" = 2048"},{name:"add_token_type_embeddings",val:" = False"},{name:"type_vocab_size",val:" = 2"},{name:"initializer_range",val:" = 0.02"},{name:"ema_delta_alpha_range",val:" = 0.2"},{name:"ema_beta_range",val:" = 0.02"},{name:"ema_gamma_omega_range",val:" = 1.0"},{name:"pad_token_id",val:" = 1"},{name:"bos_token_id",val:" = 0"},{name:"eos_token_id",val:" = 2"},{name:"relative_positional_bias",val:" = 'rotary'"},{name:"classifier_dropout",val:" = None"},{name:"use_cache",val:" = True"},{name:"add_lm_hidden_dense_layer",val:" = True"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.MegaConfig.vocab_size",description:`<strong>vocab_size</strong> (<code>int</code>, <em>optional</em>, defaults to 30522) &#x2014;
Vocabulary size of the Mega model. Defines the number of different tokens that can be represented by the
<code>inputs_ids</code> passed when calling <a href="/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaModel">MegaModel</a>.`,name:"vocab_size"},{anchor:"transformers.MegaConfig.hidden_size",description:`<strong>hidden_size</strong> (<code>int</code>, <em>optional</em>, defaults to 128) &#x2014;
Dimensionality of the encoder layers and the pooler layer.`,name:"hidden_size"},{anchor:"transformers.MegaConfig.num_hidden_layers",description:`<strong>num_hidden_layers</strong> (<code>int</code>, <em>optional</em>, defaults to 4) &#x2014;
Number of hidden layers in the Mega encoder.`,name:"num_hidden_layers"},{anchor:"transformers.MegaConfig.intermediate_size",description:`<strong>intermediate_size</strong> (<code>int</code>, <em>optional</em>, defaults to 256) &#x2014;
Dimensionality of the hidden size (self-attention value projection) within the Mega encoder`,name:"intermediate_size"},{anchor:"transformers.MegaConfig.ema_projection_size",description:`<strong>ema_projection_size</strong> (<code>int</code>, <em>optional</em>, defaults to 16) &#x2014;
Dimensionality of the MegaMultiDimensionDampedEma`,name:"ema_projection_size"},{anchor:"transformers.MegaConfig.bidirectional",description:`<strong>bidirectional</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether the MegaMultiDimensionDampedEma used in Mega&#x2019;s self-attention should work bidirectionally (<code>True</code>)
or unidirectionally (<code>False</code>). Bidirectional EMA is incompatible with causal decoding, so this should be
False if you intend to use the model as a decoder.`,name:"bidirectional"},{anchor:"transformers.MegaConfig.shared_representation_size",description:`<strong>shared_representation_size</strong> (<code>int</code>, <em>optional</em>, defaults to 64) &#x2014;
Dimensionality of the linear projection for shared representation of self-attention queries and keys`,name:"shared_representation_size"},{anchor:"transformers.MegaConfig.use_chunking",description:`<strong>use_chunking</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to chunk inputs for linear self-attention complexity (described as Mega-chunk in the paper)`,name:"use_chunking"},{anchor:"transformers.MegaConfig.chunk_size",description:`<strong>chunk_size</strong> (<code>int</code>, <em>optional</em>, defaults to -1) &#x2014;
If <code>use_chunking</code> is set to <code>True</code>, determines the size of the chunks to apply to the input sequence. If
chunking is used, input sequences must be padded to a multiple of <code>chunk_size</code>`,name:"chunk_size"},{anchor:"transformers.MegaConfig.truncation",description:`<strong>truncation</strong> (<code>int</code>, <em>optional</em>) &#x2014;
If specified, the sequence length for which to truncate MegaMultiDimensionDampedEma`,name:"truncation"},{anchor:"transformers.MegaConfig.normalize_before_mega",description:`<strong>normalize_before_mega</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to normalize before (<code>True</code>) or after (<code>False</code>) passing through Mega encoder blocks`,name:"normalize_before_mega"},{anchor:"transformers.MegaConfig.normalization_type",description:`<strong>normalization_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;scalenorm&quot;</code>) &#x2014;
Type of normalization to use in Mega encoder blocks. Choose one of <code>&quot;scalenorm&quot;</code>, <code>&quot;layernorm&quot;</code>,
<code>&quot;rmsnorm&quot;</code>, <code>&quot;batchnorm&quot;</code>, or <code>&quot;syncbatchnorm&quot;</code> (GPU required for syncbatchnorm)`,name:"normalization_type"},{anchor:"transformers.MegaConfig.norm_affine",description:`<strong>norm_affine</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
If <code>True</code>, applies a parameterized affine transformation to inputs during normalization`,name:"norm_affine"},{anchor:"transformers.MegaConfig.activation",description:`<strong>activation</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;silu&quot;</code>) &#x2014;
Activation function to apply within Mega encoder blocks. Choose one of <code>&quot;silu&quot;</code>, <code>&quot;relu&quot;</code>, <code>&quot;linear&quot;</code>,
<code>&quot;gelu&quot;</code>, or <code>&quot;gelu_accurate&quot;</code>`,name:"activation"},{anchor:"transformers.MegaConfig.attention_activation",description:`<strong>attention_activation</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;softmax&quot;</code>) &#x2014;
Activation function to apply for single-headed self-attention (a la Transformer). Choose one of
<code>&quot;softmax&quot;</code>, <code>&quot;laplace&quot;</code>, or <code>&quot;relu2&quot;</code>`,name:"attention_activation"},{anchor:"transformers.MegaConfig.dropout_prob",description:`<strong>dropout_prob</strong> (<code>float</code>, <em>optional</em>, defaults to 0.1) &#x2014;
The dropout probability for EMA self-attention`,name:"dropout_prob"},{anchor:"transformers.MegaConfig.hidden_dropout_prob",description:`<strong>hidden_dropout_prob</strong> (<code>float</code>, <em>optional</em>, defaults to 0.1) &#x2014;
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.`,name:"hidden_dropout_prob"},{anchor:"transformers.MegaConfig.attention_probs_dropout_prob",description:`<strong>attention_probs_dropout_prob</strong> (<code>float</code>, <em>optional</em>, defaults to 0.1) &#x2014;
The dropout ratio for the attention probabilities.`,name:"attention_probs_dropout_prob"},{anchor:"transformers.MegaConfig.use_feature_dropout",description:`<strong>use_feature_dropout</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to use feature-based (<code>True</code>) or standard dropout (<code>False</code>)`,name:"use_feature_dropout"},{anchor:"transformers.MegaConfig.use_normalized_ffn",description:`<strong>use_normalized_ffn</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to use the normalized feed-forward sub-layer in Mega blocks (<code>True</code>) or pass Mega encoder output
as-is (<code>False</code>)`,name:"use_normalized_ffn"},{anchor:"transformers.MegaConfig.nffn_hidden_size",description:`<strong>nffn_hidden_size</strong> (<code>int</code>, <em>optional</em>, defaults to 256) &#x2014;
If using the normalized feed-forward network (NFFN) layer within Mega (<code>use_normalized_ffn = True</code>), this
is the hidden size of the NFFN`,name:"nffn_hidden_size"},{anchor:"transformers.MegaConfig.normalize_before_ffn",description:`<strong>normalize_before_ffn</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to normalize before (<code>True</code>) or after (<code>False</code>) the feed-forward portion of NFFN`,name:"normalize_before_ffn"},{anchor:"transformers.MegaConfig.nffn_activation_dropout_prob",description:`<strong>nffn_activation_dropout_prob</strong> (<code>float</code>, <em>optional</em>, defaults to 0.1) &#x2014;
The dropout ratio for the NFFN component.`,name:"nffn_activation_dropout_prob"},{anchor:"transformers.MegaConfig.max_positions",description:`<strong>max_positions</strong> (<code>int</code>, <em>optional</em>, defaults to 2048) &#x2014;
The maximum sequence length to use for positional representations. For <code>&quot;simple&quot;</code> relative positional bias,
this is a hard limit on input length; <code>&quot;rotary&quot;</code> relative positional bias will extrapolate to longer
sequences`,name:"max_positions"},{anchor:"transformers.MegaConfig.add_token_type_embeddings",description:`<strong>add_token_type_embeddings</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to account for token types in embeddings. Left as optional to maintain compatibility with original
implementation while adding support for token types.`,name:"add_token_type_embeddings"},{anchor:"transformers.MegaConfig.type_vocab_size",description:`<strong>type_vocab_size</strong> (<code>int</code>, <em>optional</em>, defaults to 2) &#x2014;
The vocabulary size of the <code>token_type_ids</code> passed when calling <a href="/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaModel">MegaModel</a>. Only used if
<code>add_token_type_embeddings = True</code>`,name:"type_vocab_size"},{anchor:"transformers.MegaConfig.initializer_range",description:`<strong>initializer_range</strong> (<code>float</code>, <em>optional</em>, defaults to 0.02) &#x2014;
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.`,name:"initializer_range"},{anchor:"transformers.MegaConfig.ema_delta_alpha_range",description:`<strong>ema_delta_alpha_range</strong> (<code>float</code>, <em>optional</em>, defaults to 0.2) &#x2014;
The standard deviation for initializing the delta (damping factor) and alpha (decay factor) parameters in
MegaMultiDimensionDampedEma.`,name:"ema_delta_alpha_range"},{anchor:"transformers.MegaConfig.ema_beta_range",description:`<strong>ema_beta_range</strong> (<code>float</code>, <em>optional</em>, defaults to 0.02) &#x2014;
The standard deviation for initializing the beta parameter (expansion matrix) in
MegaMultiDimensionDampedEma.`,name:"ema_beta_range"},{anchor:"transformers.MegaConfig.ema_gamma_omega_range",description:`<strong>ema_gamma_omega_range</strong> (<code>float</code>, <em>optional</em>, defaults to 1.0) &#x2014;
The standard deviation for initializing the gamma (projection matrix) and omega (residual weight)
parameters in MultiDimensionEMA.`,name:"ema_gamma_omega_range"},{anchor:"transformers.MegaConfig.relative_positional_bias",description:`<strong>relative_positional_bias</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;rotary&quot;</code>) &#x2014;
Type of relative positional encoding. Choose one of <code>&quot;rotary&quot;</code> or <code>&quot;simple&quot;</code>. If <code>&quot;simple&quot;</code> is selected,
<code>max_positions</code> is used as a limit on input size, while <code>&quot;rotary&quot;</code> extrapolates beyond <code>max_positions</code>.`,name:"relative_positional_bias"},{anchor:"transformers.MegaConfig.is_decoder",description:`<strong>is_decoder</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether the model is used as a decoder or not. If <code>False</code>, the model is used as an encoder.`,name:"is_decoder"},{anchor:"transformers.MegaConfig.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not the model should return the last key/values attentions (not used by all models). Only
relevant if <code>config.is_decoder=True</code>.`,name:"use_cache"},{anchor:"transformers.MegaConfig.classifier_dropout",description:`<strong>classifier_dropout</strong> (<code>float</code>, <em>optional</em>) &#x2014;
The dropout ratio for the classification head.`,name:"classifier_dropout"},{anchor:"transformers.MegaConfig.add_lm_hidden_dense_layer",description:`<strong>add_lm_hidden_dense_layer</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to include a hidden layer for projection between encoder outputs and LM heads (<code>True</code>) or pass
hidden states directly to LM head (<code>False</code>). Remains optional for compatibility with original
implementation`,name:"add_lm_hidden_dense_layer"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/mega/configuration_mega.py#L31"}}),qe=new Me({props:{anchor:"transformers.MegaConfig.example",$$slots:{default:[Nc]},$$scope:{ctx:z}}}),ut=new te({}),gt=new N({props:{name:"class transformers.MegaModel",anchor:"transformers.MegaModel",parameters:[{name:"config",val:": MegaConfig"},{name:"add_pooling_layer",val:" = True"}],parametersDescription:[{anchor:"transformers.MegaModel.config",description:`<strong>config</strong> (<a href="/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaConfig">MegaConfig</a>) &#x2014; Model configuration class with all the parameters of the
model. Initializing with a config file does not load the weights associated with the model, only the
configuration. Check out the <a href="/docs/transformers/v4.29.0/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/mega/modeling_mega.py#L1460"}}),Mt=new N({props:{name:"forward",anchor:"transformers.MegaModel.forward",parameters:[{name:"input_ids",val:": typing.Optional[torch.Tensor] = None"},{name:"attention_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"token_type_ids",val:": typing.Optional[torch.Tensor] = None"},{name:"inputs_embeds",val:": typing.Optional[torch.Tensor] = None"},{name:"encoder_hidden_states",val:": typing.Optional[torch.Tensor] = None"},{name:"encoder_attention_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"past_key_values",val:": typing.Optional[typing.List[torch.FloatTensor]] = None"},{name:"use_cache",val:": typing.Optional[bool] = None"},{name:"output_attentions",val:": typing.Optional[bool] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"return_dict",val:": typing.Optional[bool] = None"}],parametersDescription:[{anchor:"transformers.MegaModel.forward.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>) &#x2014;
Indices of input sequence tokens in the vocabulary.</p>
<p>Indices can be obtained using <a href="/docs/transformers/v4.29.0/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p>
<p><a href="../glossary#input-ids">What are input IDs?</a>`,name:"input_ids"},{anchor:"transformers.MegaModel.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.MegaModel.forward.token_type_ids",description:`<strong>token_type_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Segment token indices to indicate first and second portions of the inputs. Indices are selected in <code>[0,1]</code>:</p>
<ul>
<li>0 corresponds to a <em>sentence A</em> token,</li>
<li>1 corresponds to a <em>sentence B</em> token.
This parameter can only be used when the model is initialized with <code>add_token_type_embeddings</code> parameter
set to <code>True</code>. All the value in this tensor should be always &lt; config.type_vocab_size.</li>
</ul>
<p><a href="../glossary#token-type-ids">What are token type IDs?</a>`,name:"token_type_ids"},{anchor:"transformers.MegaModel.forward.inputs_embeds",description:`<strong>inputs_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Optionally, instead of passing <code>input_ids</code> you can choose to directly pass an embedded representation. This
is useful if you want more control over how to convert <code>input_ids</code> indices into associated vectors than the
model&#x2019;s internal embedding lookup matrix.`,name:"inputs_embeds"},{anchor:"transformers.MegaModel.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.MegaModel.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.MegaModel.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <a href="/docs/transformers/v4.29.0/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"},{anchor:"transformers.MegaModel.forward.encoder_hidden_states",description:`<strong>encoder_hidden_states</strong>  (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if
the model is configured as a decoder.`,name:"encoder_hidden_states"},{anchor:"transformers.MegaModel.forward.encoder_attention_mask",description:`<strong>encoder_attention_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on the padding token indices of the encoder input. This mask is used in
the cross-attention if the model is configured as a decoder. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>`,name:"encoder_attention_mask"},{anchor:"transformers.MegaModel.forward.past_key_values",description:`<strong>past_key_values</strong> (<code>tuple(tuple(torch.FloatTensor))</code> of length <code>config.n_layers</code> with each tuple having 4 tensors of shape <code>(batch_size, num_heads, sequence_length - 1, embed_size_per_head)</code>) &#x2014;
Contains precomputed key and value hidden states of the attention blocks. Can be used to speed up decoding.</p>
<p>If <code>past_key_values</code> are used, the user can optionally input only the last <code>decoder_input_ids</code> (those that
don&#x2019;t have their past key value states given to this model) of shape <code>(batch_size, 1)</code> instead of all
<code>decoder_input_ids</code> of shape <code>(batch_size, sequence_length)</code>.`,name:"past_key_values"},{anchor:"transformers.MegaModel.forward.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
If set to <code>True</code>, <code>past_key_values</code> key value states are returned and can be used to speed up decoding (see
<code>past_key_values</code>).`,name:"use_cache"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/mega/modeling_mega.py#L1497",returnDescription:`
<p>A <a
  href="/docs/transformers/v4.29.0/en/main_classes/output#transformers.modeling_outputs.BaseModelOutputWithPoolingAndCrossAttentions"
>transformers.modeling_outputs.BaseModelOutputWithPoolingAndCrossAttentions</a> or a tuple of
<code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
  href="/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaConfig"
>MegaConfig</a>) and inputs.</p>
<ul>
<li>
<p><strong>last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>) \u2014 Sequence of hidden-states at the output of the last layer of the model.</p>
</li>
<li>
<p><strong>pooler_output</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, hidden_size)</code>) \u2014 Last layer hidden-state of the first token of the sequence (classification token) after further processing
through the layers used for the auxiliary pretraining task. E.g. for BERT-family of models, this returns
the classification token after processing through a linear layer and a tanh activation function. The linear
layer weights are trained from the next sentence prediction (classification) objective during pretraining.</p>
</li>
<li>
<p><strong>hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.</p>
</li>
<li>
<p><strong>attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
heads.</p>
</li>
<li>
<p><strong>cross_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> and <code>config.add_cross_attention=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the decoder\u2019s cross-attention layer, after the attention softmax, used to compute the
weighted average in the cross-attention heads.</p>
</li>
<li>
<p><strong>past_key_values</strong> (<code>tuple(tuple(torch.FloatTensor))</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) \u2014 Tuple of <code>tuple(torch.FloatTensor)</code> of length <code>config.n_layers</code>, with each tuple having 2 tensors of shape
<code>(batch_size, num_heads, sequence_length, embed_size_per_head)</code>) and optionally if
<code>config.is_encoder_decoder=True</code> 2 additional tensors of shape <code>(batch_size, num_heads, encoder_sequence_length, embed_size_per_head)</code>.</p>
<p>Contains pre-computed hidden-states (key and values in the self-attention blocks and optionally if
<code>config.is_encoder_decoder=True</code> in the cross-attention blocks) that can be used (see <code>past_key_values</code>
input) to speed up sequential decoding.</p>
</li>
</ul>
`,returnType:`
<p><a
  href="/docs/transformers/v4.29.0/en/main_classes/output#transformers.modeling_outputs.BaseModelOutputWithPoolingAndCrossAttentions"
>transformers.modeling_outputs.BaseModelOutputWithPoolingAndCrossAttentions</a> or <code>tuple(torch.FloatTensor)</code></p>
`}}),Ae=new ho({props:{$$slots:{default:[Ic]},$$scope:{ctx:z}}}),je=new Me({props:{anchor:"transformers.MegaModel.forward.example",$$slots:{default:[Dc]},$$scope:{ctx:z}}}),wt=new te({}),yt=new N({props:{name:"class transformers.MegaForCausalLM",anchor:"transformers.MegaForCausalLM",parameters:[{name:"config",val:": MegaConfig"}],parametersDescription:[{anchor:"transformers.MegaForCausalLM.config",description:`<strong>config</strong> (<a href="/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaConfig">MegaConfig</a>) &#x2014; Model configuration class with all the parameters of the
model. Initializing with a config file does not load the weights associated with the model, only the
configuration. Check out the <a href="/docs/transformers/v4.29.0/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/mega/modeling_mega.py#L1658"}}),Ft=new N({props:{name:"forward",anchor:"transformers.MegaForCausalLM.forward",parameters:[{name:"input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"attention_mask",val:": typing.Optional[torch.FloatTensor] = None"},{name:"token_type_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"inputs_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"encoder_hidden_states",val:": typing.Optional[torch.FloatTensor] = None"},{name:"encoder_attention_mask",val:": typing.Optional[torch.FloatTensor] = None"},{name:"labels",val:": typing.Optional[torch.LongTensor] = None"},{name:"past_key_values",val:": typing.Tuple[typing.Tuple[torch.FloatTensor]] = None"},{name:"use_cache",val:": typing.Optional[bool] = None"},{name:"output_attentions",val:": typing.Optional[bool] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"return_dict",val:": typing.Optional[bool] = None"}],parametersDescription:[{anchor:"transformers.MegaForCausalLM.forward.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>) &#x2014;
Indices of input sequence tokens in the vocabulary.</p>
<p>Indices can be obtained using <a href="/docs/transformers/v4.29.0/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p>
<p><a href="../glossary#input-ids">What are input IDs?</a>`,name:"input_ids"},{anchor:"transformers.MegaForCausalLM.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.MegaForCausalLM.forward.token_type_ids",description:`<strong>token_type_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Segment token indices to indicate first and second portions of the inputs. Indices are selected in <code>[0,1]</code>:</p>
<ul>
<li>0 corresponds to a <em>sentence A</em> token,</li>
<li>1 corresponds to a <em>sentence B</em> token.
This parameter can only be used when the model is initialized with <code>add_token_type_embeddings</code> parameter
set to <code>True</code>. All the value in this tensor should be always &lt; config.type_vocab_size.</li>
</ul>
<p><a href="../glossary#token-type-ids">What are token type IDs?</a>`,name:"token_type_ids"},{anchor:"transformers.MegaForCausalLM.forward.inputs_embeds",description:`<strong>inputs_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Optionally, instead of passing <code>input_ids</code> you can choose to directly pass an embedded representation. This
is useful if you want more control over how to convert <code>input_ids</code> indices into associated vectors than the
model&#x2019;s internal embedding lookup matrix.`,name:"inputs_embeds"},{anchor:"transformers.MegaForCausalLM.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.MegaForCausalLM.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.MegaForCausalLM.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <a href="/docs/transformers/v4.29.0/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"},{anchor:"transformers.MegaForCausalLM.forward.encoder_hidden_states",description:`<strong>encoder_hidden_states</strong>  (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if
the model is configured as a decoder.`,name:"encoder_hidden_states"},{anchor:"transformers.MegaForCausalLM.forward.encoder_attention_mask",description:`<strong>encoder_attention_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on the padding token indices of the encoder input. This mask is used in
the cross-attention if the model is configured as a decoder. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>`,name:"encoder_attention_mask"},{anchor:"transformers.MegaForCausalLM.forward.labels",description:`<strong>labels</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Labels for computing the left-to-right language modeling loss (next word prediction). Indices should be in
<code>[-100, 0, ..., config.vocab_size]</code> (see <code>input_ids</code> docstring) Tokens with indices set to <code>-100</code> are
ignored (masked), the loss is only computed for the tokens with labels in <code>[0, ..., config.vocab_size]</code>`,name:"labels"},{anchor:"transformers.MegaForCausalLM.forward.past_key_values",description:`<strong>past_key_values</strong> (<code>tuple(tuple(torch.FloatTensor))</code> of length <code>config.n_layers</code> with each tuple having 4 tensors of shape <code>(batch_size, num_heads, sequence_length - 1, embed_size_per_head)</code>) &#x2014;
Contains precomputed key and value hidden states of the attention blocks. Can be used to speed up decoding.</p>
<p>If <code>past_key_values</code> are used, the user can optionally input only the last <code>decoder_input_ids</code> (those that
don&#x2019;t have their past key value states given to this model) of shape <code>(batch_size, 1)</code> instead of all
<code>decoder_input_ids</code> of shape <code>(batch_size, sequence_length)</code>.`,name:"past_key_values"},{anchor:"transformers.MegaForCausalLM.forward.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
If set to <code>True</code>, <code>past_key_values</code> key value states are returned and can be used to speed up decoding (see
<code>past_key_values</code>).`,name:"use_cache"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/mega/modeling_mega.py#L1692",returnDescription:`
<p>A <a
  href="/docs/transformers/v4.29.0/en/main_classes/output#transformers.modeling_outputs.CausalLMOutputWithCrossAttentions"
>transformers.modeling_outputs.CausalLMOutputWithCrossAttentions</a> or a tuple of
<code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
  href="/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaConfig"
>MegaConfig</a>) and inputs.</p>
<ul>
<li>
<p><strong>loss</strong> (<code>torch.FloatTensor</code> of shape <code>(1,)</code>, <em>optional</em>, returned when <code>labels</code> is provided) \u2014 Language modeling loss (for next-token prediction).</p>
</li>
<li>
<p><strong>logits</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, config.vocab_size)</code>) \u2014 Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).</p>
</li>
<li>
<p><strong>hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.</p>
</li>
<li>
<p><strong>attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
heads.</p>
</li>
<li>
<p><strong>cross_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Cross attentions weights after the attention softmax, used to compute the weighted average in the
cross-attention heads.</p>
</li>
<li>
<p><strong>past_key_values</strong> (<code>tuple(tuple(torch.FloatTensor))</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> tuples of length <code>config.n_layers</code>, with each tuple containing the cached key,
value states of the self-attention and the cross-attention layers if model is used in encoder-decoder
setting. Only relevant if <code>config.is_decoder = True</code>.</p>
<p>Contains pre-computed hidden-states (key and values in the attention blocks) that can be used (see
<code>past_key_values</code> input) to speed up sequential decoding.</p>
</li>
</ul>
`,returnType:`
<p><a
  href="/docs/transformers/v4.29.0/en/main_classes/output#transformers.modeling_outputs.CausalLMOutputWithCrossAttentions"
>transformers.modeling_outputs.CausalLMOutputWithCrossAttentions</a> or <code>tuple(torch.FloatTensor)</code></p>
`}}),Le=new ho({props:{$$slots:{default:[Wc]},$$scope:{ctx:z}}}),Oe=new Me({props:{anchor:"transformers.MegaForCausalLM.forward.example",$$slots:{default:[Gc]},$$scope:{ctx:z}}}),qt=new te({}),Ct=new N({props:{name:"class transformers.MegaForMaskedLM",anchor:"transformers.MegaForMaskedLM",parameters:[{name:"config",val:": MegaConfig"}],parametersDescription:[{anchor:"transformers.MegaForMaskedLM.config",description:`<strong>config</strong> (<a href="/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaConfig">MegaConfig</a>) &#x2014; Model configuration class with all the parameters of the
model. Initializing with a config file does not load the weights associated with the model, only the
configuration. Check out the <a href="/docs/transformers/v4.29.0/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/mega/modeling_mega.py#L1820"}}),Lt=new N({props:{name:"forward",anchor:"transformers.MegaForMaskedLM.forward",parameters:[{name:"input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"attention_mask",val:": typing.Optional[torch.FloatTensor] = None"},{name:"token_type_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"inputs_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"encoder_hidden_states",val:": typing.Optional[torch.FloatTensor] = None"},{name:"encoder_attention_mask",val:": typing.Optional[torch.FloatTensor] = None"},{name:"labels",val:": typing.Optional[torch.LongTensor] = None"},{name:"output_attentions",val:": typing.Optional[bool] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"return_dict",val:": typing.Optional[bool] = None"}],parametersDescription:[{anchor:"transformers.MegaForMaskedLM.forward.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>) &#x2014;
Indices of input sequence tokens in the vocabulary.</p>
<p>Indices can be obtained using <a href="/docs/transformers/v4.29.0/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p>
<p><a href="../glossary#input-ids">What are input IDs?</a>`,name:"input_ids"},{anchor:"transformers.MegaForMaskedLM.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.MegaForMaskedLM.forward.token_type_ids",description:`<strong>token_type_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Segment token indices to indicate first and second portions of the inputs. Indices are selected in <code>[0,1]</code>:</p>
<ul>
<li>0 corresponds to a <em>sentence A</em> token,</li>
<li>1 corresponds to a <em>sentence B</em> token.
This parameter can only be used when the model is initialized with <code>add_token_type_embeddings</code> parameter
set to <code>True</code>. All the value in this tensor should be always &lt; config.type_vocab_size.</li>
</ul>
<p><a href="../glossary#token-type-ids">What are token type IDs?</a>`,name:"token_type_ids"},{anchor:"transformers.MegaForMaskedLM.forward.inputs_embeds",description:`<strong>inputs_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Optionally, instead of passing <code>input_ids</code> you can choose to directly pass an embedded representation. This
is useful if you want more control over how to convert <code>input_ids</code> indices into associated vectors than the
model&#x2019;s internal embedding lookup matrix.`,name:"inputs_embeds"},{anchor:"transformers.MegaForMaskedLM.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.MegaForMaskedLM.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.MegaForMaskedLM.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <a href="/docs/transformers/v4.29.0/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"},{anchor:"transformers.MegaForMaskedLM.forward.labels",description:`<strong>labels</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Labels for computing the masked language modeling loss. Indices should be in <code>[-100, 0, ..., config.vocab_size]</code> (see <code>input_ids</code> docstring) Tokens with indices set to <code>-100</code> are ignored (masked), the
loss is only computed for the tokens with labels in <code>[0, ..., config.vocab_size]</code>`,name:"labels"},{anchor:"transformers.MegaForMaskedLM.forward.kwargs",description:`<strong>kwargs</strong> (<code>Dict[str, any]</code>, optional, defaults to <em>{}</em>) &#x2014;
Used to hide legacy arguments that have been deprecated.`,name:"kwargs"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/mega/modeling_mega.py#L1856",returnDescription:`
<p>A <a
  href="/docs/transformers/v4.29.0/en/main_classes/output#transformers.modeling_outputs.MaskedLMOutput"
>transformers.modeling_outputs.MaskedLMOutput</a> or a tuple of
<code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
  href="/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaConfig"
>MegaConfig</a>) and inputs.</p>
<ul>
<li>
<p><strong>loss</strong> (<code>torch.FloatTensor</code> of shape <code>(1,)</code>, <em>optional</em>, returned when <code>labels</code> is provided) \u2014 Masked language modeling (MLM) loss.</p>
</li>
<li>
<p><strong>logits</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, config.vocab_size)</code>) \u2014 Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).</p>
</li>
<li>
<p><strong>hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.</p>
</li>
<li>
<p><strong>attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
heads.</p>
</li>
</ul>
`,returnType:`
<p><a
  href="/docs/transformers/v4.29.0/en/main_classes/output#transformers.modeling_outputs.MaskedLMOutput"
>transformers.modeling_outputs.MaskedLMOutput</a> or <code>tuple(torch.FloatTensor)</code></p>
`}}),Ne=new ho({props:{$$slots:{default:[Hc]},$$scope:{ctx:z}}}),Ie=new Me({props:{anchor:"transformers.MegaForMaskedLM.forward.example",$$slots:{default:[Qc]},$$scope:{ctx:z}}}),Ot=new te({}),St=new N({props:{name:"class transformers.MegaForSequenceClassification",anchor:"transformers.MegaForSequenceClassification",parameters:[{name:"config",val:""}],parametersDescription:[{anchor:"transformers.MegaForSequenceClassification.config",description:`<strong>config</strong> (<a href="/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaConfig">MegaConfig</a>) &#x2014; Model configuration class with all the parameters of the
model. Initializing with a config file does not load the weights associated with the model, only the
configuration. Check out the <a href="/docs/transformers/v4.29.0/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/mega/modeling_mega.py#L1929"}}),Wt=new N({props:{name:"forward",anchor:"transformers.MegaForSequenceClassification.forward",parameters:[{name:"input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"attention_mask",val:": typing.Optional[torch.FloatTensor] = None"},{name:"token_type_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"inputs_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"labels",val:": typing.Optional[torch.LongTensor] = None"},{name:"output_attentions",val:": typing.Optional[bool] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"return_dict",val:": typing.Optional[bool] = None"}],parametersDescription:[{anchor:"transformers.MegaForSequenceClassification.forward.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>) &#x2014;
Indices of input sequence tokens in the vocabulary.</p>
<p>Indices can be obtained using <a href="/docs/transformers/v4.29.0/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p>
<p><a href="../glossary#input-ids">What are input IDs?</a>`,name:"input_ids"},{anchor:"transformers.MegaForSequenceClassification.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.MegaForSequenceClassification.forward.token_type_ids",description:`<strong>token_type_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Segment token indices to indicate first and second portions of the inputs. Indices are selected in <code>[0,1]</code>:</p>
<ul>
<li>0 corresponds to a <em>sentence A</em> token,</li>
<li>1 corresponds to a <em>sentence B</em> token.
This parameter can only be used when the model is initialized with <code>add_token_type_embeddings</code> parameter
set to <code>True</code>. All the value in this tensor should be always &lt; config.type_vocab_size.</li>
</ul>
<p><a href="../glossary#token-type-ids">What are token type IDs?</a>`,name:"token_type_ids"},{anchor:"transformers.MegaForSequenceClassification.forward.inputs_embeds",description:`<strong>inputs_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Optionally, instead of passing <code>input_ids</code> you can choose to directly pass an embedded representation. This
is useful if you want more control over how to convert <code>input_ids</code> indices into associated vectors than the
model&#x2019;s internal embedding lookup matrix.`,name:"inputs_embeds"},{anchor:"transformers.MegaForSequenceClassification.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.MegaForSequenceClassification.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.MegaForSequenceClassification.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <a href="/docs/transformers/v4.29.0/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"},{anchor:"transformers.MegaForSequenceClassification.forward.labels",description:`<strong>labels</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size,)</code>, <em>optional</em>) &#x2014;
Labels for computing the sequence classification/regression loss. Indices should be in <code>[0, ..., config.num_labels - 1]</code>. If <code>config.num_labels == 1</code> a regression loss is computed (Mean-Square loss), If
<code>config.num_labels &gt; 1</code> a classification loss is computed (Cross-Entropy).`,name:"labels"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/mega/modeling_mega.py#L1943",returnDescription:`
<p>A <a
  href="/docs/transformers/v4.29.0/en/main_classes/output#transformers.modeling_outputs.SequenceClassifierOutput"
>transformers.modeling_outputs.SequenceClassifierOutput</a> or a tuple of
<code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
  href="/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaConfig"
>MegaConfig</a>) and inputs.</p>
<ul>
<li>
<p><strong>loss</strong> (<code>torch.FloatTensor</code> of shape <code>(1,)</code>, <em>optional</em>, returned when <code>labels</code> is provided) \u2014 Classification (or regression if config.num_labels==1) loss.</p>
</li>
<li>
<p><strong>logits</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, config.num_labels)</code>) \u2014 Classification (or regression if config.num_labels==1) scores (before SoftMax).</p>
</li>
<li>
<p><strong>hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.</p>
</li>
<li>
<p><strong>attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
heads.</p>
</li>
</ul>
`,returnType:`
<p><a
  href="/docs/transformers/v4.29.0/en/main_classes/output#transformers.modeling_outputs.SequenceClassifierOutput"
>transformers.modeling_outputs.SequenceClassifierOutput</a> or <code>tuple(torch.FloatTensor)</code></p>
`}}),We=new ho({props:{$$slots:{default:[Uc]},$$scope:{ctx:z}}}),Ge=new Me({props:{anchor:"transformers.MegaForSequenceClassification.forward.example",$$slots:{default:[Rc]},$$scope:{ctx:z}}}),He=new Me({props:{anchor:"transformers.MegaForSequenceClassification.forward.example-2",$$slots:{default:[Bc]},$$scope:{ctx:z}}}),Gt=new te({}),Ht=new N({props:{name:"class transformers.MegaForMultipleChoice",anchor:"transformers.MegaForMultipleChoice",parameters:[{name:"config",val:""}],parametersDescription:[{anchor:"transformers.MegaForMultipleChoice.config",description:`<strong>config</strong> (<a href="/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaConfig">MegaConfig</a>) &#x2014; Model configuration class with all the parameters of the
model. Initializing with a config file does not load the weights associated with the model, only the
configuration. Check out the <a href="/docs/transformers/v4.29.0/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/mega/modeling_mega.py#L2022"}}),Bt=new N({props:{name:"forward",anchor:"transformers.MegaForMultipleChoice.forward",parameters:[{name:"input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"token_type_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"attention_mask",val:": typing.Optional[torch.FloatTensor] = None"},{name:"labels",val:": typing.Optional[torch.LongTensor] = None"},{name:"inputs_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"output_attentions",val:": typing.Optional[bool] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"return_dict",val:": typing.Optional[bool] = None"}],parametersDescription:[{anchor:"transformers.MegaForMultipleChoice.forward.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, num_choices, sequence_length)</code>) &#x2014;
Indices of input sequence tokens in the vocabulary.</p>
<p>Indices can be obtained using <a href="/docs/transformers/v4.29.0/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p>
<p><a href="../glossary#input-ids">What are input IDs?</a>`,name:"input_ids"},{anchor:"transformers.MegaForMultipleChoice.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, num_choices, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.MegaForMultipleChoice.forward.token_type_ids",description:`<strong>token_type_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, num_choices, sequence_length)</code>, <em>optional</em>) &#x2014;
Segment token indices to indicate first and second portions of the inputs. Indices are selected in <code>[0,1]</code>:</p>
<ul>
<li>0 corresponds to a <em>sentence A</em> token,</li>
<li>1 corresponds to a <em>sentence B</em> token.
This parameter can only be used when the model is initialized with <code>add_token_type_embeddings</code> parameter
set to <code>True</code>. All the value in this tensor should be always &lt; config.type_vocab_size.</li>
</ul>
<p><a href="../glossary#token-type-ids">What are token type IDs?</a>`,name:"token_type_ids"},{anchor:"transformers.MegaForMultipleChoice.forward.inputs_embeds",description:`<strong>inputs_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, num_choices, sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Optionally, instead of passing <code>input_ids</code> you can choose to directly pass an embedded representation. This
is useful if you want more control over how to convert <code>input_ids</code> indices into associated vectors than the
model&#x2019;s internal embedding lookup matrix.`,name:"inputs_embeds"},{anchor:"transformers.MegaForMultipleChoice.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.MegaForMultipleChoice.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.MegaForMultipleChoice.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <a href="/docs/transformers/v4.29.0/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"},{anchor:"transformers.MegaForMultipleChoice.forward.labels",description:`<strong>labels</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size,)</code>, <em>optional</em>) &#x2014;
Labels for computing the multiple choice classification loss. Indices should be in <code>[0, ..., num_choices-1]</code> where <code>num_choices</code> is the size of the second dimension of the input tensors. (See
<code>input_ids</code> above)`,name:"labels"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/mega/modeling_mega.py#L2035",returnDescription:`
<p>A <a
  href="/docs/transformers/v4.29.0/en/main_classes/output#transformers.modeling_outputs.MultipleChoiceModelOutput"
>transformers.modeling_outputs.MultipleChoiceModelOutput</a> or a tuple of
<code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
  href="/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaConfig"
>MegaConfig</a>) and inputs.</p>
<ul>
<li>
<p><strong>loss</strong> (<code>torch.FloatTensor</code> of shape <em>(1,)</em>, <em>optional</em>, returned when <code>labels</code> is provided) \u2014 Classification loss.</p>
</li>
<li>
<p><strong>logits</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, num_choices)</code>) \u2014 <em>num_choices</em> is the second dimension of the input tensors. (see <em>input_ids</em> above).</p>
<p>Classification scores (before SoftMax).</p>
</li>
<li>
<p><strong>hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.</p>
</li>
<li>
<p><strong>attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
heads.</p>
</li>
</ul>
`,returnType:`
<p><a
  href="/docs/transformers/v4.29.0/en/main_classes/output#transformers.modeling_outputs.MultipleChoiceModelOutput"
>transformers.modeling_outputs.MultipleChoiceModelOutput</a> or <code>tuple(torch.FloatTensor)</code></p>
`}}),Ue=new ho({props:{$$slots:{default:[Vc]},$$scope:{ctx:z}}}),Re=new Me({props:{anchor:"transformers.MegaForMultipleChoice.forward.example",$$slots:{default:[Jc]},$$scope:{ctx:z}}}),Vt=new te({}),Jt=new N({props:{name:"class transformers.MegaForTokenClassification",anchor:"transformers.MegaForTokenClassification",parameters:[{name:"config",val:""}],parametersDescription:[{anchor:"transformers.MegaForTokenClassification.config",description:`<strong>config</strong> (<a href="/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaConfig">MegaConfig</a>) &#x2014; Model configuration class with all the parameters of the
model. Initializing with a config file does not load the weights associated with the model, only the
configuration. Check out the <a href="/docs/transformers/v4.29.0/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/mega/modeling_mega.py#L2109"}}),Yt=new N({props:{name:"forward",anchor:"transformers.MegaForTokenClassification.forward",parameters:[{name:"input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"attention_mask",val:": typing.Optional[torch.FloatTensor] = None"},{name:"token_type_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"inputs_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"labels",val:": typing.Optional[torch.LongTensor] = None"},{name:"output_attentions",val:": typing.Optional[bool] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"return_dict",val:": typing.Optional[bool] = None"}],parametersDescription:[{anchor:"transformers.MegaForTokenClassification.forward.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>) &#x2014;
Indices of input sequence tokens in the vocabulary.</p>
<p>Indices can be obtained using <a href="/docs/transformers/v4.29.0/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p>
<p><a href="../glossary#input-ids">What are input IDs?</a>`,name:"input_ids"},{anchor:"transformers.MegaForTokenClassification.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.MegaForTokenClassification.forward.token_type_ids",description:`<strong>token_type_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Segment token indices to indicate first and second portions of the inputs. Indices are selected in <code>[0,1]</code>:</p>
<ul>
<li>0 corresponds to a <em>sentence A</em> token,</li>
<li>1 corresponds to a <em>sentence B</em> token.
This parameter can only be used when the model is initialized with <code>add_token_type_embeddings</code> parameter
set to <code>True</code>. All the value in this tensor should be always &lt; config.type_vocab_size.</li>
</ul>
<p><a href="../glossary#token-type-ids">What are token type IDs?</a>`,name:"token_type_ids"},{anchor:"transformers.MegaForTokenClassification.forward.inputs_embeds",description:`<strong>inputs_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Optionally, instead of passing <code>input_ids</code> you can choose to directly pass an embedded representation. This
is useful if you want more control over how to convert <code>input_ids</code> indices into associated vectors than the
model&#x2019;s internal embedding lookup matrix.`,name:"inputs_embeds"},{anchor:"transformers.MegaForTokenClassification.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.MegaForTokenClassification.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.MegaForTokenClassification.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <a href="/docs/transformers/v4.29.0/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"},{anchor:"transformers.MegaForTokenClassification.forward.labels",description:`<strong>labels</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Labels for computing the token classification loss. Indices should be in <code>[0, ..., config.num_labels - 1]</code>.`,name:"labels"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/mega/modeling_mega.py#L2127",returnDescription:`
<p>A <a
  href="/docs/transformers/v4.29.0/en/main_classes/output#transformers.modeling_outputs.TokenClassifierOutput"
>transformers.modeling_outputs.TokenClassifierOutput</a> or a tuple of
<code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
  href="/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaConfig"
>MegaConfig</a>) and inputs.</p>
<ul>
<li>
<p><strong>loss</strong> (<code>torch.FloatTensor</code> of shape <code>(1,)</code>, <em>optional</em>, returned when <code>labels</code> is provided)  \u2014 Classification loss.</p>
</li>
<li>
<p><strong>logits</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, config.num_labels)</code>) \u2014 Classification scores (before SoftMax).</p>
</li>
<li>
<p><strong>hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.</p>
</li>
<li>
<p><strong>attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
heads.</p>
</li>
</ul>
`,returnType:`
<p><a
  href="/docs/transformers/v4.29.0/en/main_classes/output#transformers.modeling_outputs.TokenClassifierOutput"
>transformers.modeling_outputs.TokenClassifierOutput</a> or <code>tuple(torch.FloatTensor)</code></p>
`}}),Ve=new ho({props:{$$slots:{default:[Xc]},$$scope:{ctx:z}}}),Je=new Me({props:{anchor:"transformers.MegaForTokenClassification.forward.example",$$slots:{default:[Zc]},$$scope:{ctx:z}}}),eo=new te({}),to=new N({props:{name:"class transformers.MegaForQuestionAnswering",anchor:"transformers.MegaForQuestionAnswering",parameters:[{name:"config",val:""}],parametersDescription:[{anchor:"transformers.MegaForQuestionAnswering.config",description:`<strong>config</strong> (<a href="/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaConfig">MegaConfig</a>) &#x2014; Model configuration class with all the parameters of the
model. Initializing with a config file does not load the weights associated with the model, only the
configuration. Check out the <a href="/docs/transformers/v4.29.0/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/mega/modeling_mega.py#L2212"}}),ao=new N({props:{name:"forward",anchor:"transformers.MegaForQuestionAnswering.forward",parameters:[{name:"input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"attention_mask",val:": typing.Optional[torch.FloatTensor] = None"},{name:"token_type_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"inputs_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"start_positions",val:": typing.Optional[torch.LongTensor] = None"},{name:"end_positions",val:": typing.Optional[torch.LongTensor] = None"},{name:"output_attentions",val:": typing.Optional[bool] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"return_dict",val:": typing.Optional[bool] = None"}],parametersDescription:[{anchor:"transformers.MegaForQuestionAnswering.forward.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>) &#x2014;
Indices of input sequence tokens in the vocabulary.</p>
<p>Indices can be obtained using <a href="/docs/transformers/v4.29.0/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p>
<p><a href="../glossary#input-ids">What are input IDs?</a>`,name:"input_ids"},{anchor:"transformers.MegaForQuestionAnswering.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.MegaForQuestionAnswering.forward.token_type_ids",description:`<strong>token_type_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Segment token indices to indicate first and second portions of the inputs. Indices are selected in <code>[0,1]</code>:</p>
<ul>
<li>0 corresponds to a <em>sentence A</em> token,</li>
<li>1 corresponds to a <em>sentence B</em> token.
This parameter can only be used when the model is initialized with <code>add_token_type_embeddings</code> parameter
set to <code>True</code>. All the value in this tensor should be always &lt; config.type_vocab_size.</li>
</ul>
<p><a href="../glossary#token-type-ids">What are token type IDs?</a>`,name:"token_type_ids"},{anchor:"transformers.MegaForQuestionAnswering.forward.inputs_embeds",description:`<strong>inputs_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Optionally, instead of passing <code>input_ids</code> you can choose to directly pass an embedded representation. This
is useful if you want more control over how to convert <code>input_ids</code> indices into associated vectors than the
model&#x2019;s internal embedding lookup matrix.`,name:"inputs_embeds"},{anchor:"transformers.MegaForQuestionAnswering.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.MegaForQuestionAnswering.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.MegaForQuestionAnswering.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <a href="/docs/transformers/v4.29.0/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"},{anchor:"transformers.MegaForQuestionAnswering.forward.start_positions",description:`<strong>start_positions</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size,)</code>, <em>optional</em>) &#x2014;
Labels for position (index) of the start of the labelled span for computing the token classification loss.
Positions are clamped to the length of the sequence (<code>sequence_length</code>). Position outside of the sequence
are not taken into account for computing the loss.`,name:"start_positions"},{anchor:"transformers.MegaForQuestionAnswering.forward.end_positions",description:`<strong>end_positions</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size,)</code>, <em>optional</em>) &#x2014;
Labels for position (index) of the end of the labelled span for computing the token classification loss.
Positions are clamped to the length of the sequence (<code>sequence_length</code>). Position outside of the sequence
are not taken into account for computing the loss.`,name:"end_positions"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/mega/modeling_mega.py#L2226",returnDescription:`
<p>A <a
  href="/docs/transformers/v4.29.0/en/main_classes/output#transformers.modeling_outputs.QuestionAnsweringModelOutput"
>transformers.modeling_outputs.QuestionAnsweringModelOutput</a> or a tuple of
<code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
  href="/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaConfig"
>MegaConfig</a>) and inputs.</p>
<ul>
<li>
<p><strong>loss</strong> (<code>torch.FloatTensor</code> of shape <code>(1,)</code>, <em>optional</em>, returned when <code>labels</code> is provided) \u2014 Total span extraction loss is the sum of a Cross-Entropy for the start and end positions.</p>
</li>
<li>
<p><strong>start_logits</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length)</code>) \u2014 Span-start scores (before SoftMax).</p>
</li>
<li>
<p><strong>end_logits</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length)</code>) \u2014 Span-end scores (before SoftMax).</p>
</li>
<li>
<p><strong>hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.</p>
</li>
<li>
<p><strong>attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
heads.</p>
</li>
</ul>
`,returnType:`
<p><a
  href="/docs/transformers/v4.29.0/en/main_classes/output#transformers.modeling_outputs.QuestionAnsweringModelOutput"
>transformers.modeling_outputs.QuestionAnsweringModelOutput</a> or <code>tuple(torch.FloatTensor)</code></p>
`}}),Ze=new ho({props:{$$slots:{default:[Kc]},$$scope:{ctx:z}}}),Ke=new Me({props:{anchor:"transformers.MegaForQuestionAnswering.forward.example",$$slots:{default:[Yc]},$$scope:{ctx:z}}}),{c(){d=r("meta"),v=h(),g=r("h1"),p=r("a"),_=r("span"),k(n.$$.fragment),c=h(),x=r("span"),Zs=s("MEGA"),Yn=h(),oe=r("h2"),Te=r("a"),Uo=r("span"),k(rt.$$.fragment),Ks=h(),Ro=r("span"),Ys=s("Overview"),es=h(),$e=r("p"),ea=s("The MEGA model was proposed in "),it=r("a"),ta=s("Mega: Moving Average Equipped Gated Attention"),oa=s(` by Xuezhe Ma, Chunting Zhou, Xiang Kong, Junxian He, Liangke Gui, Graham Neubig, Jonathan May, and Luke Zettlemoyer.
MEGA proposes a new approach to self-attention with each encoder layer having a multi-headed exponential moving average in addition to a single head of standard dot-product attention, giving the attention mechanism
stronger positional biases. This allows MEGA to perform competitively to Transformers on standard benchmarks including LRA
while also having significantly fewer parameters. MEGA\u2019s compute efficiency allows it to scale to very long sequences, making it an
attractive option for long-document NLP tasks.`),ts=h(),mo=r("p"),na=s("The abstract from the paper is the following:"),os=h(),uo=r("p"),Bo=r("em"),sa=s("The design choices in the Transformer attention mechanism, including weak inductive bias and quadratic computational complexity, have limited its application for modeling long sequences. In this paper, we introduce Mega, a simple, theoretically grounded, single-head gated attention mechanism equipped with (exponential) moving average to incorporate inductive bias of position-aware local dependencies into the position-agnostic attention mechanism. We further propose a variant of Mega that offers linear time and space complexity yet yields only minimal quality loss, by efficiently splitting the whole sequence into multiple chunks with fixed length. Extensive experiments on a wide range of sequence modeling benchmarks, including the Long Range Arena, neural machine translation, auto-regressive language modeling, and image and speech classification, show that Mega achieves significant improvements over other sequence models, including variants of Transformers and recent state space models."),ns=h(),go=r("p"),aa=s("Tips:"),ss=h(),ze=r("ul"),lt=r("li"),ra=s("MEGA can perform quite well with relatively few parameters. See Appendix D in the MEGA paper for examples of architectural specs which perform well in various settings. If using MEGA as a decoder, be sure to set "),Vo=r("code"),ia=s("bidirectional=False"),la=s(" to avoid errors with default bidirectional."),da=h(),Jo=r("li"),ca=s("Mega-chunk is a variant of mega that reduces time and spaces complexity from quadratic to linear. Utilize chunking with MegaConfig.use_chunking and control chunk size with MegaConfig.chunk_size"),as=h(),B=r("p"),pa=s("This model was contributed by "),dt=r("a"),ha=s("mnaylor"),ma=s(`.
The original code can be found `),ct=r("a"),ua=s("here"),ga=s("."),rs=h(),fo=r("p"),fa=s("Implementation Notes:"),is=h(),xe=r("ul"),Xo=r("li"),_a=s("The original implementation of MEGA had an inconsistent expectation of attention masks for padding and causal self-attention between the softmax attention and Laplace/squared ReLU method. This implementation addresses that inconsistency."),ba=h(),Zo=r("li"),va=s("The original implementation did not include token type embeddings; this implementation adds support for these, with the option controlled by MegaConfig.add_token_type_embeddings"),ls=h(),ne=r("h2"),Fe=r("a"),Ko=r("span"),k(pt.$$.fragment),ka=h(),Yo=r("span"),Ma=s("MegaConfig"),ds=h(),D=r("div"),k(ht.$$.fragment),wa=h(),se=r("p"),ya=s("This is the configuration class to store the configuration of a "),_o=r("a"),Ta=s("MegaModel"),$a=s(`. It is used to instantiate a Mega
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults will yield a similar configuration to that of the Mega
`),mt=r("a"),za=s("mnaylor/mega-base-wikitext"),xa=s(" architecture."),Fa=h(),ae=r("p"),qa=s("Configuration objects inherit from "),bo=r("a"),Ca=s("PretrainedConfig"),Ea=s(` and can be used to control the model outputs. Read the
documentation from `),vo=r("a"),Aa=s("PretrainedConfig"),ja=s(" for more information."),Pa=h(),k(qe.$$.fragment),cs=h(),re=r("h2"),Ce=r("a"),en=r("span"),k(ut.$$.fragment),La=h(),tn=r("span"),Oa=s("MegaModel"),ps=h(),q=r("div"),k(gt.$$.fragment),Sa=h(),on=r("p"),Na=s("The bare MEGA Model transformer outputting raw hidden-states without any specific head on top."),Ia=h(),ft=r("p"),Da=s("This model inherits from "),ko=r("a"),Wa=s("PreTrainedModel"),Ga=s(`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),Ha=h(),_t=r("p"),Qa=s("This model is also a PyTorch "),bt=r("a"),Ua=s("torch.nn.Module"),Ra=s(` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Ba=h(),vt=r("p"),Va=s(`The model can behave as an encoder (with only self-attention) as well as a decoder, in which case a layer of
cross-attention is added after self-attention, following the architecture described in `),nn=r("em"),Ja=s(`Mega: Moving Average
Equipped Gated Attention`),Xa=s(`_ by Xuezhe Ma, Chunting Zhou, Xiang Kong, Junxian He, Liangke Gui, Graham Neubig,
Jonathan May, and Luke Zettlemoyer`),Za=h(),F=r("p"),Ka=s("To behave as a decoder the model needs to be initialized with the "),sn=r("code"),Ya=s("is_decoder"),er=s(` argument of the configuration set to
`),an=r("code"),tr=s("True"),or=s(" and "),rn=r("code"),nr=s("bidirectional"),sr=s(" set to "),ln=r("code"),ar=s("False"),rr=s(`. To be used in a Seq2Seq model, the model needs to initialized with both
`),dn=r("code"),ir=s("is_decoder=True"),lr=s(" and "),cn=r("code"),dr=s("bidirectional=False"),cr=s(" argument as well as "),pn=r("code"),pr=s("add_cross_attention"),hr=s(" set to "),hn=r("code"),mr=s("True"),ur=s(`; an
`),mn=r("code"),gr=s("encoder_hidden_states"),fr=s(" is then expected as an input to the forward pass."),_r=h(),Ee=r("p"),br=s(".. _"),un=r("em"),vr=s("Mega: Moving Average Equipped Gated Attention"),kr=s(": "),kt=r("a"),Mr=s("https://arxiv.org/abs/2209.10655"),wr=h(),W=r("div"),k(Mt.$$.fragment),yr=h(),ie=r("p"),Tr=s("The "),Mo=r("a"),$r=s("MegaModel"),zr=s(" forward method, overrides the "),gn=r("code"),xr=s("__call__"),Fr=s(" special method."),qr=h(),k(Ae.$$.fragment),Cr=h(),k(je.$$.fragment),hs=h(),le=r("h2"),Pe=r("a"),fn=r("span"),k(wt.$$.fragment),Er=h(),_n=r("span"),Ar=s("MegaForCausalLM"),ms=h(),A=r("div"),k(yt.$$.fragment),jr=h(),Tt=r("p"),Pr=s("MEGA Model with a "),bn=r("code"),Lr=s("language modeling"),Or=s(" head on top for CLM fine-tuning."),Sr=h(),$t=r("p"),Nr=s("This model inherits from "),wo=r("a"),Ir=s("PreTrainedModel"),Dr=s(`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),Wr=h(),zt=r("p"),Gr=s("This model is also a PyTorch "),xt=r("a"),Hr=s("torch.nn.Module"),Qr=s(` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Ur=h(),G=r("div"),k(Ft.$$.fragment),Rr=h(),de=r("p"),Br=s("The "),yo=r("a"),Vr=s("MegaForCausalLM"),Jr=s(" forward method, overrides the "),vn=r("code"),Xr=s("__call__"),Zr=s(" special method."),Kr=h(),k(Le.$$.fragment),Yr=h(),k(Oe.$$.fragment),us=h(),ce=r("h2"),Se=r("a"),kn=r("span"),k(qt.$$.fragment),ei=h(),Mn=r("span"),ti=s("MegaForMaskedLM"),gs=h(),j=r("div"),k(Ct.$$.fragment),oi=h(),Et=r("p"),ni=s("MEGA Model with a "),wn=r("code"),si=s("language modeling"),ai=s(" head on top."),ri=h(),At=r("p"),ii=s("This model inherits from "),To=r("a"),li=s("PreTrainedModel"),di=s(`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),ci=h(),jt=r("p"),pi=s("This model is also a PyTorch "),Pt=r("a"),hi=s("torch.nn.Module"),mi=s(` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),ui=h(),H=r("div"),k(Lt.$$.fragment),gi=h(),pe=r("p"),fi=s("The "),$o=r("a"),_i=s("MegaForMaskedLM"),bi=s(" forward method, overrides the "),yn=r("code"),vi=s("__call__"),ki=s(" special method."),Mi=h(),k(Ne.$$.fragment),wi=h(),k(Ie.$$.fragment),fs=h(),he=r("h2"),De=r("a"),Tn=r("span"),k(Ot.$$.fragment),yi=h(),$n=r("span"),Ti=s("MegaForSequenceClassification"),_s=h(),P=r("div"),k(St.$$.fragment),$i=h(),zn=r("p"),zi=s(`MEGA Model transformer with a sequence classification/regression head on top (a linear layer on top of the pooled
output) e.g. for GLUE tasks.`),xi=h(),Nt=r("p"),Fi=s("This model inherits from "),zo=r("a"),qi=s("PreTrainedModel"),Ci=s(`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),Ei=h(),It=r("p"),Ai=s("This model is also a PyTorch "),Dt=r("a"),ji=s("torch.nn.Module"),Pi=s(` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Li=h(),I=r("div"),k(Wt.$$.fragment),Oi=h(),me=r("p"),Si=s("The "),xo=r("a"),Ni=s("MegaForSequenceClassification"),Ii=s(" forward method, overrides the "),xn=r("code"),Di=s("__call__"),Wi=s(" special method."),Gi=h(),k(We.$$.fragment),Hi=h(),k(Ge.$$.fragment),Qi=h(),k(He.$$.fragment),bs=h(),ue=r("h2"),Qe=r("a"),Fn=r("span"),k(Gt.$$.fragment),Ui=h(),qn=r("span"),Ri=s("MegaForMultipleChoice"),vs=h(),L=r("div"),k(Ht.$$.fragment),Bi=h(),Cn=r("p"),Vi=s(`MEGA Model with a multiple choice classification head on top (a linear layer on top of the pooled output and a
softmax) e.g. for RocStories/SWAG tasks.`),Ji=h(),Qt=r("p"),Xi=s("This model inherits from "),Fo=r("a"),Zi=s("PreTrainedModel"),Ki=s(`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),Yi=h(),Ut=r("p"),el=s("This model is also a PyTorch "),Rt=r("a"),tl=s("torch.nn.Module"),ol=s(` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),nl=h(),Q=r("div"),k(Bt.$$.fragment),sl=h(),ge=r("p"),al=s("The "),qo=r("a"),rl=s("MegaForMultipleChoice"),il=s(" forward method, overrides the "),En=r("code"),ll=s("__call__"),dl=s(" special method."),cl=h(),k(Ue.$$.fragment),pl=h(),k(Re.$$.fragment),ks=h(),fe=r("h2"),Be=r("a"),An=r("span"),k(Vt.$$.fragment),hl=h(),jn=r("span"),ml=s("MegaForTokenClassification"),Ms=h(),O=r("div"),k(Jt.$$.fragment),ul=h(),Pn=r("p"),gl=s(`MEGA Model with a token classification head on top (a linear layer on top of the hidden-states output) e.g. for
Named-Entity-Recognition (NER) tasks.`),fl=h(),Xt=r("p"),_l=s("This model inherits from "),Co=r("a"),bl=s("PreTrainedModel"),vl=s(`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),kl=h(),Zt=r("p"),Ml=s("This model is also a PyTorch "),Kt=r("a"),wl=s("torch.nn.Module"),yl=s(` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Tl=h(),U=r("div"),k(Yt.$$.fragment),$l=h(),_e=r("p"),zl=s("The "),Eo=r("a"),xl=s("MegaForTokenClassification"),Fl=s(" forward method, overrides the "),Ln=r("code"),ql=s("__call__"),Cl=s(" special method."),El=h(),k(Ve.$$.fragment),Al=h(),k(Je.$$.fragment),ws=h(),be=r("h2"),Xe=r("a"),On=r("span"),k(eo.$$.fragment),jl=h(),Sn=r("span"),Pl=s("MegaForQuestionAnswering"),ys=h(),S=r("div"),k(to.$$.fragment),Ll=h(),ve=r("p"),Ol=s(`MEGA Model with a span classification head on top for extractive question-answering tasks like SQuAD (a linear
layers on top of the hidden-states output to compute `),Nn=r("code"),Sl=s("span start logits"),Nl=s(" and "),In=r("code"),Il=s("span end logits"),Dl=s(")."),Wl=h(),oo=r("p"),Gl=s("This model inherits from "),Ao=r("a"),Hl=s("PreTrainedModel"),Ql=s(`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),Ul=h(),no=r("p"),Rl=s("This model is also a PyTorch "),so=r("a"),Bl=s("torch.nn.Module"),Vl=s(` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Jl=h(),R=r("div"),k(ao.$$.fragment),Xl=h(),ke=r("p"),Zl=s("The "),jo=r("a"),Kl=s("MegaForQuestionAnswering"),Yl=s(" forward method, overrides the "),Dn=r("code"),ed=s("__call__"),td=s(" special method."),od=h(),k(Ze.$$.fragment),nd=h(),k(Ke.$$.fragment),this.h()},l(t){const f=Oc('[data-svelte="svelte-1phssyn"]',document.head);d=i(f,"META",{name:!0,content:!0}),f.forEach(o),v=m(t),g=i(t,"H1",{class:!0});var ro=l(g);p=i(ro,"A",{id:!0,class:!0,href:!0});var Wn=l(p);_=i(Wn,"SPAN",{});var Gn=l(_);M(n.$$.fragment,Gn),Gn.forEach(o),Wn.forEach(o),c=m(ro),x=i(ro,"SPAN",{});var Hn=l(x);Zs=a(Hn,"MEGA"),Hn.forEach(o),ro.forEach(o),Yn=m(t),oe=i(t,"H2",{class:!0});var io=l(oe);Te=i(io,"A",{id:!0,class:!0,href:!0});var Qn=l(Te);Uo=i(Qn,"SPAN",{});var Un=l(Uo);M(rt.$$.fragment,Un),Un.forEach(o),Qn.forEach(o),Ks=m(io),Ro=i(io,"SPAN",{});var Rn=l(Ro);Ys=a(Rn,"Overview"),Rn.forEach(o),io.forEach(o),es=m(t),$e=i(t,"P",{});var lo=l($e);ea=a(lo,"The MEGA model was proposed in "),it=i(lo,"A",{href:!0,rel:!0});var Bn=l(it);ta=a(Bn,"Mega: Moving Average Equipped Gated Attention"),Bn.forEach(o),oa=a(lo,` by Xuezhe Ma, Chunting Zhou, Xiang Kong, Junxian He, Liangke Gui, Graham Neubig, Jonathan May, and Luke Zettlemoyer.
MEGA proposes a new approach to self-attention with each encoder layer having a multi-headed exponential moving average in addition to a single head of standard dot-product attention, giving the attention mechanism
stronger positional biases. This allows MEGA to perform competitively to Transformers on standard benchmarks including LRA
while also having significantly fewer parameters. MEGA\u2019s compute efficiency allows it to scale to very long sequences, making it an
attractive option for long-document NLP tasks.`),lo.forEach(o),ts=m(t),mo=i(t,"P",{});var Vn=l(mo);na=a(Vn,"The abstract from the paper is the following:"),Vn.forEach(o),os=m(t),uo=i(t,"P",{});var Jn=l(uo);Bo=i(Jn,"EM",{});var Xn=l(Bo);sa=a(Xn,"The design choices in the Transformer attention mechanism, including weak inductive bias and quadratic computational complexity, have limited its application for modeling long sequences. In this paper, we introduce Mega, a simple, theoretically grounded, single-head gated attention mechanism equipped with (exponential) moving average to incorporate inductive bias of position-aware local dependencies into the position-agnostic attention mechanism. We further propose a variant of Mega that offers linear time and space complexity yet yields only minimal quality loss, by efficiently splitting the whole sequence into multiple chunks with fixed length. Extensive experiments on a wide range of sequence modeling benchmarks, including the Long Range Arena, neural machine translation, auto-regressive language modeling, and image and speech classification, show that Mega achieves significant improvements over other sequence models, including variants of Transformers and recent state space models."),Xn.forEach(o),Jn.forEach(o),ns=m(t),go=i(t,"P",{});var Zn=l(go);aa=a(Zn,"Tips:"),Zn.forEach(o),ss=m(t),ze=i(t,"UL",{});var co=l(ze);lt=i(co,"LI",{});var po=l(lt);ra=a(po,"MEGA can perform quite well with relatively few parameters. See Appendix D in the MEGA paper for examples of architectural specs which perform well in various settings. If using MEGA as a decoder, be sure to set "),Vo=i(po,"CODE",{});var sd=l(Vo);ia=a(sd,"bidirectional=False"),sd.forEach(o),la=a(po," to avoid errors with default bidirectional."),po.forEach(o),da=m(co),Jo=i(co,"LI",{});var ad=l(Jo);ca=a(ad,"Mega-chunk is a variant of mega that reduces time and spaces complexity from quadratic to linear. Utilize chunking with MegaConfig.use_chunking and control chunk size with MegaConfig.chunk_size"),ad.forEach(o),co.forEach(o),as=m(t),B=i(t,"P",{});var Po=l(B);pa=a(Po,"This model was contributed by "),dt=i(Po,"A",{href:!0,rel:!0});var rd=l(dt);ha=a(rd,"mnaylor"),rd.forEach(o),ma=a(Po,`.
The original code can be found `),ct=i(Po,"A",{href:!0,rel:!0});var id=l(ct);ua=a(id,"here"),id.forEach(o),ga=a(Po,"."),Po.forEach(o),rs=m(t),fo=i(t,"P",{});var ld=l(fo);fa=a(ld,"Implementation Notes:"),ld.forEach(o),is=m(t),xe=i(t,"UL",{});var $s=l(xe);Xo=i($s,"LI",{});var dd=l(Xo);_a=a(dd,"The original implementation of MEGA had an inconsistent expectation of attention masks for padding and causal self-attention between the softmax attention and Laplace/squared ReLU method. This implementation addresses that inconsistency."),dd.forEach(o),ba=m($s),Zo=i($s,"LI",{});var cd=l(Zo);va=a(cd,"The original implementation did not include token type embeddings; this implementation adds support for these, with the option controlled by MegaConfig.add_token_type_embeddings"),cd.forEach(o),$s.forEach(o),ls=m(t),ne=i(t,"H2",{class:!0});var zs=l(ne);Fe=i(zs,"A",{id:!0,class:!0,href:!0});var pd=l(Fe);Ko=i(pd,"SPAN",{});var hd=l(Ko);M(pt.$$.fragment,hd),hd.forEach(o),pd.forEach(o),ka=m(zs),Yo=i(zs,"SPAN",{});var md=l(Yo);Ma=a(md,"MegaConfig"),md.forEach(o),zs.forEach(o),ds=m(t),D=i(t,"DIV",{class:!0});var Ye=l(D);M(ht.$$.fragment,Ye),wa=m(Ye),se=i(Ye,"P",{});var Lo=l(se);ya=a(Lo,"This is the configuration class to store the configuration of a "),_o=i(Lo,"A",{href:!0});var ud=l(_o);Ta=a(ud,"MegaModel"),ud.forEach(o),$a=a(Lo,`. It is used to instantiate a Mega
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults will yield a similar configuration to that of the Mega
`),mt=i(Lo,"A",{href:!0,rel:!0});var gd=l(mt);za=a(gd,"mnaylor/mega-base-wikitext"),gd.forEach(o),xa=a(Lo," architecture."),Lo.forEach(o),Fa=m(Ye),ae=i(Ye,"P",{});var Oo=l(ae);qa=a(Oo,"Configuration objects inherit from "),bo=i(Oo,"A",{href:!0});var fd=l(bo);Ca=a(fd,"PretrainedConfig"),fd.forEach(o),Ea=a(Oo,` and can be used to control the model outputs. Read the
documentation from `),vo=i(Oo,"A",{href:!0});var _d=l(vo);Aa=a(_d,"PretrainedConfig"),_d.forEach(o),ja=a(Oo," for more information."),Oo.forEach(o),Pa=m(Ye),M(qe.$$.fragment,Ye),Ye.forEach(o),cs=m(t),re=i(t,"H2",{class:!0});var xs=l(re);Ce=i(xs,"A",{id:!0,class:!0,href:!0});var bd=l(Ce);en=i(bd,"SPAN",{});var vd=l(en);M(ut.$$.fragment,vd),vd.forEach(o),bd.forEach(o),La=m(xs),tn=i(xs,"SPAN",{});var kd=l(tn);Oa=a(kd,"MegaModel"),kd.forEach(o),xs.forEach(o),ps=m(t),q=i(t,"DIV",{class:!0});var E=l(q);M(gt.$$.fragment,E),Sa=m(E),on=i(E,"P",{});var Md=l(on);Na=a(Md,"The bare MEGA Model transformer outputting raw hidden-states without any specific head on top."),Md.forEach(o),Ia=m(E),ft=i(E,"P",{});var Fs=l(ft);Da=a(Fs,"This model inherits from "),ko=i(Fs,"A",{href:!0});var wd=l(ko);Wa=a(wd,"PreTrainedModel"),wd.forEach(o),Ga=a(Fs,`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),Fs.forEach(o),Ha=m(E),_t=i(E,"P",{});var qs=l(_t);Qa=a(qs,"This model is also a PyTorch "),bt=i(qs,"A",{href:!0,rel:!0});var yd=l(bt);Ua=a(yd,"torch.nn.Module"),yd.forEach(o),Ra=a(qs,` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),qs.forEach(o),Ba=m(E),vt=i(E,"P",{});var Cs=l(vt);Va=a(Cs,`The model can behave as an encoder (with only self-attention) as well as a decoder, in which case a layer of
cross-attention is added after self-attention, following the architecture described in `),nn=i(Cs,"EM",{});var Td=l(nn);Ja=a(Td,`Mega: Moving Average
Equipped Gated Attention`),Td.forEach(o),Xa=a(Cs,`_ by Xuezhe Ma, Chunting Zhou, Xiang Kong, Junxian He, Liangke Gui, Graham Neubig,
Jonathan May, and Luke Zettlemoyer`),Cs.forEach(o),Za=m(E),F=i(E,"P",{});var C=l(F);Ka=a(C,"To behave as a decoder the model needs to be initialized with the "),sn=i(C,"CODE",{});var $d=l(sn);Ya=a($d,"is_decoder"),$d.forEach(o),er=a(C,` argument of the configuration set to
`),an=i(C,"CODE",{});var zd=l(an);tr=a(zd,"True"),zd.forEach(o),or=a(C," and "),rn=i(C,"CODE",{});var xd=l(rn);nr=a(xd,"bidirectional"),xd.forEach(o),sr=a(C," set to "),ln=i(C,"CODE",{});var Fd=l(ln);ar=a(Fd,"False"),Fd.forEach(o),rr=a(C,`. To be used in a Seq2Seq model, the model needs to initialized with both
`),dn=i(C,"CODE",{});var qd=l(dn);ir=a(qd,"is_decoder=True"),qd.forEach(o),lr=a(C," and "),cn=i(C,"CODE",{});var Cd=l(cn);dr=a(Cd,"bidirectional=False"),Cd.forEach(o),cr=a(C," argument as well as "),pn=i(C,"CODE",{});var Ed=l(pn);pr=a(Ed,"add_cross_attention"),Ed.forEach(o),hr=a(C," set to "),hn=i(C,"CODE",{});var Ad=l(hn);mr=a(Ad,"True"),Ad.forEach(o),ur=a(C,`; an
`),mn=i(C,"CODE",{});var jd=l(mn);gr=a(jd,"encoder_hidden_states"),jd.forEach(o),fr=a(C," is then expected as an input to the forward pass."),C.forEach(o),_r=m(E),Ee=i(E,"P",{});var Kn=l(Ee);br=a(Kn,".. _"),un=i(Kn,"EM",{});var Pd=l(un);vr=a(Pd,"Mega: Moving Average Equipped Gated Attention"),Pd.forEach(o),kr=a(Kn,": "),kt=i(Kn,"A",{href:!0,rel:!0});var Ld=l(kt);Mr=a(Ld,"https://arxiv.org/abs/2209.10655"),Ld.forEach(o),Kn.forEach(o),wr=m(E),W=i(E,"DIV",{class:!0});var et=l(W);M(Mt.$$.fragment,et),yr=m(et),ie=i(et,"P",{});var So=l(ie);Tr=a(So,"The "),Mo=i(So,"A",{href:!0});var Od=l(Mo);$r=a(Od,"MegaModel"),Od.forEach(o),zr=a(So," forward method, overrides the "),gn=i(So,"CODE",{});var Sd=l(gn);xr=a(Sd,"__call__"),Sd.forEach(o),Fr=a(So," special method."),So.forEach(o),qr=m(et),M(Ae.$$.fragment,et),Cr=m(et),M(je.$$.fragment,et),et.forEach(o),E.forEach(o),hs=m(t),le=i(t,"H2",{class:!0});var Es=l(le);Pe=i(Es,"A",{id:!0,class:!0,href:!0});var Nd=l(Pe);fn=i(Nd,"SPAN",{});var Id=l(fn);M(wt.$$.fragment,Id),Id.forEach(o),Nd.forEach(o),Er=m(Es),_n=i(Es,"SPAN",{});var Dd=l(_n);Ar=a(Dd,"MegaForCausalLM"),Dd.forEach(o),Es.forEach(o),ms=m(t),A=i(t,"DIV",{class:!0});var V=l(A);M(yt.$$.fragment,V),jr=m(V),Tt=i(V,"P",{});var As=l(Tt);Pr=a(As,"MEGA Model with a "),bn=i(As,"CODE",{});var Wd=l(bn);Lr=a(Wd,"language modeling"),Wd.forEach(o),Or=a(As," head on top for CLM fine-tuning."),As.forEach(o),Sr=m(V),$t=i(V,"P",{});var js=l($t);Nr=a(js,"This model inherits from "),wo=i(js,"A",{href:!0});var Gd=l(wo);Ir=a(Gd,"PreTrainedModel"),Gd.forEach(o),Dr=a(js,`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),js.forEach(o),Wr=m(V),zt=i(V,"P",{});var Ps=l(zt);Gr=a(Ps,"This model is also a PyTorch "),xt=i(Ps,"A",{href:!0,rel:!0});var Hd=l(xt);Hr=a(Hd,"torch.nn.Module"),Hd.forEach(o),Qr=a(Ps,` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Ps.forEach(o),Ur=m(V),G=i(V,"DIV",{class:!0});var tt=l(G);M(Ft.$$.fragment,tt),Rr=m(tt),de=i(tt,"P",{});var No=l(de);Br=a(No,"The "),yo=i(No,"A",{href:!0});var Qd=l(yo);Vr=a(Qd,"MegaForCausalLM"),Qd.forEach(o),Jr=a(No," forward method, overrides the "),vn=i(No,"CODE",{});var Ud=l(vn);Xr=a(Ud,"__call__"),Ud.forEach(o),Zr=a(No," special method."),No.forEach(o),Kr=m(tt),M(Le.$$.fragment,tt),Yr=m(tt),M(Oe.$$.fragment,tt),tt.forEach(o),V.forEach(o),us=m(t),ce=i(t,"H2",{class:!0});var Ls=l(ce);Se=i(Ls,"A",{id:!0,class:!0,href:!0});var Rd=l(Se);kn=i(Rd,"SPAN",{});var Bd=l(kn);M(qt.$$.fragment,Bd),Bd.forEach(o),Rd.forEach(o),ei=m(Ls),Mn=i(Ls,"SPAN",{});var Vd=l(Mn);ti=a(Vd,"MegaForMaskedLM"),Vd.forEach(o),Ls.forEach(o),gs=m(t),j=i(t,"DIV",{class:!0});var J=l(j);M(Ct.$$.fragment,J),oi=m(J),Et=i(J,"P",{});var Os=l(Et);ni=a(Os,"MEGA Model with a "),wn=i(Os,"CODE",{});var Jd=l(wn);si=a(Jd,"language modeling"),Jd.forEach(o),ai=a(Os," head on top."),Os.forEach(o),ri=m(J),At=i(J,"P",{});var Ss=l(At);ii=a(Ss,"This model inherits from "),To=i(Ss,"A",{href:!0});var Xd=l(To);li=a(Xd,"PreTrainedModel"),Xd.forEach(o),di=a(Ss,`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),Ss.forEach(o),ci=m(J),jt=i(J,"P",{});var Ns=l(jt);pi=a(Ns,"This model is also a PyTorch "),Pt=i(Ns,"A",{href:!0,rel:!0});var Zd=l(Pt);hi=a(Zd,"torch.nn.Module"),Zd.forEach(o),mi=a(Ns,` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Ns.forEach(o),ui=m(J),H=i(J,"DIV",{class:!0});var ot=l(H);M(Lt.$$.fragment,ot),gi=m(ot),pe=i(ot,"P",{});var Io=l(pe);fi=a(Io,"The "),$o=i(Io,"A",{href:!0});var Kd=l($o);_i=a(Kd,"MegaForMaskedLM"),Kd.forEach(o),bi=a(Io," forward method, overrides the "),yn=i(Io,"CODE",{});var Yd=l(yn);vi=a(Yd,"__call__"),Yd.forEach(o),ki=a(Io," special method."),Io.forEach(o),Mi=m(ot),M(Ne.$$.fragment,ot),wi=m(ot),M(Ie.$$.fragment,ot),ot.forEach(o),J.forEach(o),fs=m(t),he=i(t,"H2",{class:!0});var Is=l(he);De=i(Is,"A",{id:!0,class:!0,href:!0});var ec=l(De);Tn=i(ec,"SPAN",{});var tc=l(Tn);M(Ot.$$.fragment,tc),tc.forEach(o),ec.forEach(o),yi=m(Is),$n=i(Is,"SPAN",{});var oc=l($n);Ti=a(oc,"MegaForSequenceClassification"),oc.forEach(o),Is.forEach(o),_s=m(t),P=i(t,"DIV",{class:!0});var X=l(P);M(St.$$.fragment,X),$i=m(X),zn=i(X,"P",{});var nc=l(zn);zi=a(nc,`MEGA Model transformer with a sequence classification/regression head on top (a linear layer on top of the pooled
output) e.g. for GLUE tasks.`),nc.forEach(o),xi=m(X),Nt=i(X,"P",{});var Ds=l(Nt);Fi=a(Ds,"This model inherits from "),zo=i(Ds,"A",{href:!0});var sc=l(zo);qi=a(sc,"PreTrainedModel"),sc.forEach(o),Ci=a(Ds,`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),Ds.forEach(o),Ei=m(X),It=i(X,"P",{});var Ws=l(It);Ai=a(Ws,"This model is also a PyTorch "),Dt=i(Ws,"A",{href:!0,rel:!0});var ac=l(Dt);ji=a(ac,"torch.nn.Module"),ac.forEach(o),Pi=a(Ws,` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Ws.forEach(o),Li=m(X),I=i(X,"DIV",{class:!0});var Z=l(I);M(Wt.$$.fragment,Z),Oi=m(Z),me=i(Z,"P",{});var Do=l(me);Si=a(Do,"The "),xo=i(Do,"A",{href:!0});var rc=l(xo);Ni=a(rc,"MegaForSequenceClassification"),rc.forEach(o),Ii=a(Do," forward method, overrides the "),xn=i(Do,"CODE",{});var ic=l(xn);Di=a(ic,"__call__"),ic.forEach(o),Wi=a(Do," special method."),Do.forEach(o),Gi=m(Z),M(We.$$.fragment,Z),Hi=m(Z),M(Ge.$$.fragment,Z),Qi=m(Z),M(He.$$.fragment,Z),Z.forEach(o),X.forEach(o),bs=m(t),ue=i(t,"H2",{class:!0});var Gs=l(ue);Qe=i(Gs,"A",{id:!0,class:!0,href:!0});var lc=l(Qe);Fn=i(lc,"SPAN",{});var dc=l(Fn);M(Gt.$$.fragment,dc),dc.forEach(o),lc.forEach(o),Ui=m(Gs),qn=i(Gs,"SPAN",{});var cc=l(qn);Ri=a(cc,"MegaForMultipleChoice"),cc.forEach(o),Gs.forEach(o),vs=m(t),L=i(t,"DIV",{class:!0});var K=l(L);M(Ht.$$.fragment,K),Bi=m(K),Cn=i(K,"P",{});var pc=l(Cn);Vi=a(pc,`MEGA Model with a multiple choice classification head on top (a linear layer on top of the pooled output and a
softmax) e.g. for RocStories/SWAG tasks.`),pc.forEach(o),Ji=m(K),Qt=i(K,"P",{});var Hs=l(Qt);Xi=a(Hs,"This model inherits from "),Fo=i(Hs,"A",{href:!0});var hc=l(Fo);Zi=a(hc,"PreTrainedModel"),hc.forEach(o),Ki=a(Hs,`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),Hs.forEach(o),Yi=m(K),Ut=i(K,"P",{});var Qs=l(Ut);el=a(Qs,"This model is also a PyTorch "),Rt=i(Qs,"A",{href:!0,rel:!0});var mc=l(Rt);tl=a(mc,"torch.nn.Module"),mc.forEach(o),ol=a(Qs,` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Qs.forEach(o),nl=m(K),Q=i(K,"DIV",{class:!0});var nt=l(Q);M(Bt.$$.fragment,nt),sl=m(nt),ge=i(nt,"P",{});var Wo=l(ge);al=a(Wo,"The "),qo=i(Wo,"A",{href:!0});var uc=l(qo);rl=a(uc,"MegaForMultipleChoice"),uc.forEach(o),il=a(Wo," forward method, overrides the "),En=i(Wo,"CODE",{});var gc=l(En);ll=a(gc,"__call__"),gc.forEach(o),dl=a(Wo," special method."),Wo.forEach(o),cl=m(nt),M(Ue.$$.fragment,nt),pl=m(nt),M(Re.$$.fragment,nt),nt.forEach(o),K.forEach(o),ks=m(t),fe=i(t,"H2",{class:!0});var Us=l(fe);Be=i(Us,"A",{id:!0,class:!0,href:!0});var fc=l(Be);An=i(fc,"SPAN",{});var _c=l(An);M(Vt.$$.fragment,_c),_c.forEach(o),fc.forEach(o),hl=m(Us),jn=i(Us,"SPAN",{});var bc=l(jn);ml=a(bc,"MegaForTokenClassification"),bc.forEach(o),Us.forEach(o),Ms=m(t),O=i(t,"DIV",{class:!0});var Y=l(O);M(Jt.$$.fragment,Y),ul=m(Y),Pn=i(Y,"P",{});var vc=l(Pn);gl=a(vc,`MEGA Model with a token classification head on top (a linear layer on top of the hidden-states output) e.g. for
Named-Entity-Recognition (NER) tasks.`),vc.forEach(o),fl=m(Y),Xt=i(Y,"P",{});var Rs=l(Xt);_l=a(Rs,"This model inherits from "),Co=i(Rs,"A",{href:!0});var kc=l(Co);bl=a(kc,"PreTrainedModel"),kc.forEach(o),vl=a(Rs,`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),Rs.forEach(o),kl=m(Y),Zt=i(Y,"P",{});var Bs=l(Zt);Ml=a(Bs,"This model is also a PyTorch "),Kt=i(Bs,"A",{href:!0,rel:!0});var Mc=l(Kt);wl=a(Mc,"torch.nn.Module"),Mc.forEach(o),yl=a(Bs,` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Bs.forEach(o),Tl=m(Y),U=i(Y,"DIV",{class:!0});var st=l(U);M(Yt.$$.fragment,st),$l=m(st),_e=i(st,"P",{});var Go=l(_e);zl=a(Go,"The "),Eo=i(Go,"A",{href:!0});var wc=l(Eo);xl=a(wc,"MegaForTokenClassification"),wc.forEach(o),Fl=a(Go," forward method, overrides the "),Ln=i(Go,"CODE",{});var yc=l(Ln);ql=a(yc,"__call__"),yc.forEach(o),Cl=a(Go," special method."),Go.forEach(o),El=m(st),M(Ve.$$.fragment,st),Al=m(st),M(Je.$$.fragment,st),st.forEach(o),Y.forEach(o),ws=m(t),be=i(t,"H2",{class:!0});var Vs=l(be);Xe=i(Vs,"A",{id:!0,class:!0,href:!0});var Tc=l(Xe);On=i(Tc,"SPAN",{});var $c=l(On);M(eo.$$.fragment,$c),$c.forEach(o),Tc.forEach(o),jl=m(Vs),Sn=i(Vs,"SPAN",{});var zc=l(Sn);Pl=a(zc,"MegaForQuestionAnswering"),zc.forEach(o),Vs.forEach(o),ys=m(t),S=i(t,"DIV",{class:!0});var ee=l(S);M(to.$$.fragment,ee),Ll=m(ee),ve=i(ee,"P",{});var Ho=l(ve);Ol=a(Ho,`MEGA Model with a span classification head on top for extractive question-answering tasks like SQuAD (a linear
layers on top of the hidden-states output to compute `),Nn=i(Ho,"CODE",{});var xc=l(Nn);Sl=a(xc,"span start logits"),xc.forEach(o),Nl=a(Ho," and "),In=i(Ho,"CODE",{});var Fc=l(In);Il=a(Fc,"span end logits"),Fc.forEach(o),Dl=a(Ho,")."),Ho.forEach(o),Wl=m(ee),oo=i(ee,"P",{});var Js=l(oo);Gl=a(Js,"This model inherits from "),Ao=i(Js,"A",{href:!0});var qc=l(Ao);Hl=a(qc,"PreTrainedModel"),qc.forEach(o),Ql=a(Js,`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),Js.forEach(o),Ul=m(ee),no=i(ee,"P",{});var Xs=l(no);Rl=a(Xs,"This model is also a PyTorch "),so=i(Xs,"A",{href:!0,rel:!0});var Cc=l(so);Bl=a(Cc,"torch.nn.Module"),Cc.forEach(o),Vl=a(Xs,` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Xs.forEach(o),Jl=m(ee),R=i(ee,"DIV",{class:!0});var at=l(R);M(ao.$$.fragment,at),Xl=m(at),ke=i(at,"P",{});var Qo=l(ke);Zl=a(Qo,"The "),jo=i(Qo,"A",{href:!0});var Ec=l(jo);Kl=a(Ec,"MegaForQuestionAnswering"),Ec.forEach(o),Yl=a(Qo," forward method, overrides the "),Dn=i(Qo,"CODE",{});var Ac=l(Dn);ed=a(Ac,"__call__"),Ac.forEach(o),td=a(Qo," special method."),Qo.forEach(o),od=m(at),M(Ze.$$.fragment,at),nd=m(at),M(Ke.$$.fragment,at),at.forEach(o),ee.forEach(o),this.h()},h(){u(d,"name","hf:doc:metadata"),u(d,"content",JSON.stringify(tp)),u(p,"id","mega"),u(p,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(p,"href","#mega"),u(g,"class","relative group"),u(Te,"id","overview"),u(Te,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(Te,"href","#overview"),u(oe,"class","relative group"),u(it,"href","https://arxiv.org/abs/2209.10655"),u(it,"rel","nofollow"),u(dt,"href","https://huggingface.co/mnaylor"),u(dt,"rel","nofollow"),u(ct,"href","https://github.com/facebookresearch/mega"),u(ct,"rel","nofollow"),u(Fe,"id","transformers.MegaConfig"),u(Fe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(Fe,"href","#transformers.MegaConfig"),u(ne,"class","relative group"),u(_o,"href","/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaModel"),u(mt,"href","https://huggingface.co/mnaylor/mega-base-wikitext"),u(mt,"rel","nofollow"),u(bo,"href","/docs/transformers/v4.29.0/en/main_classes/configuration#transformers.PretrainedConfig"),u(vo,"href","/docs/transformers/v4.29.0/en/main_classes/configuration#transformers.PretrainedConfig"),u(D,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(Ce,"id","transformers.MegaModel"),u(Ce,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(Ce,"href","#transformers.MegaModel"),u(re,"class","relative group"),u(ko,"href","/docs/transformers/v4.29.0/en/main_classes/model#transformers.PreTrainedModel"),u(bt,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),u(bt,"rel","nofollow"),u(kt,"href","https://arxiv.org/abs/2209.10655"),u(kt,"rel","nofollow"),u(Mo,"href","/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaModel"),u(W,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(q,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(Pe,"id","transformers.MegaForCausalLM"),u(Pe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(Pe,"href","#transformers.MegaForCausalLM"),u(le,"class","relative group"),u(wo,"href","/docs/transformers/v4.29.0/en/main_classes/model#transformers.PreTrainedModel"),u(xt,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),u(xt,"rel","nofollow"),u(yo,"href","/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaForCausalLM"),u(G,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(A,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(Se,"id","transformers.MegaForMaskedLM"),u(Se,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(Se,"href","#transformers.MegaForMaskedLM"),u(ce,"class","relative group"),u(To,"href","/docs/transformers/v4.29.0/en/main_classes/model#transformers.PreTrainedModel"),u(Pt,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),u(Pt,"rel","nofollow"),u($o,"href","/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaForMaskedLM"),u(H,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(j,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(De,"id","transformers.MegaForSequenceClassification"),u(De,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(De,"href","#transformers.MegaForSequenceClassification"),u(he,"class","relative group"),u(zo,"href","/docs/transformers/v4.29.0/en/main_classes/model#transformers.PreTrainedModel"),u(Dt,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),u(Dt,"rel","nofollow"),u(xo,"href","/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaForSequenceClassification"),u(I,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(P,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(Qe,"id","transformers.MegaForMultipleChoice"),u(Qe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(Qe,"href","#transformers.MegaForMultipleChoice"),u(ue,"class","relative group"),u(Fo,"href","/docs/transformers/v4.29.0/en/main_classes/model#transformers.PreTrainedModel"),u(Rt,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),u(Rt,"rel","nofollow"),u(qo,"href","/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaForMultipleChoice"),u(Q,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(L,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(Be,"id","transformers.MegaForTokenClassification"),u(Be,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(Be,"href","#transformers.MegaForTokenClassification"),u(fe,"class","relative group"),u(Co,"href","/docs/transformers/v4.29.0/en/main_classes/model#transformers.PreTrainedModel"),u(Kt,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),u(Kt,"rel","nofollow"),u(Eo,"href","/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaForTokenClassification"),u(U,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(O,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(Xe,"id","transformers.MegaForQuestionAnswering"),u(Xe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(Xe,"href","#transformers.MegaForQuestionAnswering"),u(be,"class","relative group"),u(Ao,"href","/docs/transformers/v4.29.0/en/main_classes/model#transformers.PreTrainedModel"),u(so,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),u(so,"rel","nofollow"),u(jo,"href","/docs/transformers/v4.29.0/en/model_doc/mega#transformers.MegaForQuestionAnswering"),u(R,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(S,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(t,f){e(document.head,d),b(t,v,f),b(t,g,f),e(g,p),e(p,_),w(n,_,null),e(g,c),e(g,x),e(x,Zs),b(t,Yn,f),b(t,oe,f),e(oe,Te),e(Te,Uo),w(rt,Uo,null),e(oe,Ks),e(oe,Ro),e(Ro,Ys),b(t,es,f),b(t,$e,f),e($e,ea),e($e,it),e(it,ta),e($e,oa),b(t,ts,f),b(t,mo,f),e(mo,na),b(t,os,f),b(t,uo,f),e(uo,Bo),e(Bo,sa),b(t,ns,f),b(t,go,f),e(go,aa),b(t,ss,f),b(t,ze,f),e(ze,lt),e(lt,ra),e(lt,Vo),e(Vo,ia),e(lt,la),e(ze,da),e(ze,Jo),e(Jo,ca),b(t,as,f),b(t,B,f),e(B,pa),e(B,dt),e(dt,ha),e(B,ma),e(B,ct),e(ct,ua),e(B,ga),b(t,rs,f),b(t,fo,f),e(fo,fa),b(t,is,f),b(t,xe,f),e(xe,Xo),e(Xo,_a),e(xe,ba),e(xe,Zo),e(Zo,va),b(t,ls,f),b(t,ne,f),e(ne,Fe),e(Fe,Ko),w(pt,Ko,null),e(ne,ka),e(ne,Yo),e(Yo,Ma),b(t,ds,f),b(t,D,f),w(ht,D,null),e(D,wa),e(D,se),e(se,ya),e(se,_o),e(_o,Ta),e(se,$a),e(se,mt),e(mt,za),e(se,xa),e(D,Fa),e(D,ae),e(ae,qa),e(ae,bo),e(bo,Ca),e(ae,Ea),e(ae,vo),e(vo,Aa),e(ae,ja),e(D,Pa),w(qe,D,null),b(t,cs,f),b(t,re,f),e(re,Ce),e(Ce,en),w(ut,en,null),e(re,La),e(re,tn),e(tn,Oa),b(t,ps,f),b(t,q,f),w(gt,q,null),e(q,Sa),e(q,on),e(on,Na),e(q,Ia),e(q,ft),e(ft,Da),e(ft,ko),e(ko,Wa),e(ft,Ga),e(q,Ha),e(q,_t),e(_t,Qa),e(_t,bt),e(bt,Ua),e(_t,Ra),e(q,Ba),e(q,vt),e(vt,Va),e(vt,nn),e(nn,Ja),e(vt,Xa),e(q,Za),e(q,F),e(F,Ka),e(F,sn),e(sn,Ya),e(F,er),e(F,an),e(an,tr),e(F,or),e(F,rn),e(rn,nr),e(F,sr),e(F,ln),e(ln,ar),e(F,rr),e(F,dn),e(dn,ir),e(F,lr),e(F,cn),e(cn,dr),e(F,cr),e(F,pn),e(pn,pr),e(F,hr),e(F,hn),e(hn,mr),e(F,ur),e(F,mn),e(mn,gr),e(F,fr),e(q,_r),e(q,Ee),e(Ee,br),e(Ee,un),e(un,vr),e(Ee,kr),e(Ee,kt),e(kt,Mr),e(q,wr),e(q,W),w(Mt,W,null),e(W,yr),e(W,ie),e(ie,Tr),e(ie,Mo),e(Mo,$r),e(ie,zr),e(ie,gn),e(gn,xr),e(ie,Fr),e(W,qr),w(Ae,W,null),e(W,Cr),w(je,W,null),b(t,hs,f),b(t,le,f),e(le,Pe),e(Pe,fn),w(wt,fn,null),e(le,Er),e(le,_n),e(_n,Ar),b(t,ms,f),b(t,A,f),w(yt,A,null),e(A,jr),e(A,Tt),e(Tt,Pr),e(Tt,bn),e(bn,Lr),e(Tt,Or),e(A,Sr),e(A,$t),e($t,Nr),e($t,wo),e(wo,Ir),e($t,Dr),e(A,Wr),e(A,zt),e(zt,Gr),e(zt,xt),e(xt,Hr),e(zt,Qr),e(A,Ur),e(A,G),w(Ft,G,null),e(G,Rr),e(G,de),e(de,Br),e(de,yo),e(yo,Vr),e(de,Jr),e(de,vn),e(vn,Xr),e(de,Zr),e(G,Kr),w(Le,G,null),e(G,Yr),w(Oe,G,null),b(t,us,f),b(t,ce,f),e(ce,Se),e(Se,kn),w(qt,kn,null),e(ce,ei),e(ce,Mn),e(Mn,ti),b(t,gs,f),b(t,j,f),w(Ct,j,null),e(j,oi),e(j,Et),e(Et,ni),e(Et,wn),e(wn,si),e(Et,ai),e(j,ri),e(j,At),e(At,ii),e(At,To),e(To,li),e(At,di),e(j,ci),e(j,jt),e(jt,pi),e(jt,Pt),e(Pt,hi),e(jt,mi),e(j,ui),e(j,H),w(Lt,H,null),e(H,gi),e(H,pe),e(pe,fi),e(pe,$o),e($o,_i),e(pe,bi),e(pe,yn),e(yn,vi),e(pe,ki),e(H,Mi),w(Ne,H,null),e(H,wi),w(Ie,H,null),b(t,fs,f),b(t,he,f),e(he,De),e(De,Tn),w(Ot,Tn,null),e(he,yi),e(he,$n),e($n,Ti),b(t,_s,f),b(t,P,f),w(St,P,null),e(P,$i),e(P,zn),e(zn,zi),e(P,xi),e(P,Nt),e(Nt,Fi),e(Nt,zo),e(zo,qi),e(Nt,Ci),e(P,Ei),e(P,It),e(It,Ai),e(It,Dt),e(Dt,ji),e(It,Pi),e(P,Li),e(P,I),w(Wt,I,null),e(I,Oi),e(I,me),e(me,Si),e(me,xo),e(xo,Ni),e(me,Ii),e(me,xn),e(xn,Di),e(me,Wi),e(I,Gi),w(We,I,null),e(I,Hi),w(Ge,I,null),e(I,Qi),w(He,I,null),b(t,bs,f),b(t,ue,f),e(ue,Qe),e(Qe,Fn),w(Gt,Fn,null),e(ue,Ui),e(ue,qn),e(qn,Ri),b(t,vs,f),b(t,L,f),w(Ht,L,null),e(L,Bi),e(L,Cn),e(Cn,Vi),e(L,Ji),e(L,Qt),e(Qt,Xi),e(Qt,Fo),e(Fo,Zi),e(Qt,Ki),e(L,Yi),e(L,Ut),e(Ut,el),e(Ut,Rt),e(Rt,tl),e(Ut,ol),e(L,nl),e(L,Q),w(Bt,Q,null),e(Q,sl),e(Q,ge),e(ge,al),e(ge,qo),e(qo,rl),e(ge,il),e(ge,En),e(En,ll),e(ge,dl),e(Q,cl),w(Ue,Q,null),e(Q,pl),w(Re,Q,null),b(t,ks,f),b(t,fe,f),e(fe,Be),e(Be,An),w(Vt,An,null),e(fe,hl),e(fe,jn),e(jn,ml),b(t,Ms,f),b(t,O,f),w(Jt,O,null),e(O,ul),e(O,Pn),e(Pn,gl),e(O,fl),e(O,Xt),e(Xt,_l),e(Xt,Co),e(Co,bl),e(Xt,vl),e(O,kl),e(O,Zt),e(Zt,Ml),e(Zt,Kt),e(Kt,wl),e(Zt,yl),e(O,Tl),e(O,U),w(Yt,U,null),e(U,$l),e(U,_e),e(_e,zl),e(_e,Eo),e(Eo,xl),e(_e,Fl),e(_e,Ln),e(Ln,ql),e(_e,Cl),e(U,El),w(Ve,U,null),e(U,Al),w(Je,U,null),b(t,ws,f),b(t,be,f),e(be,Xe),e(Xe,On),w(eo,On,null),e(be,jl),e(be,Sn),e(Sn,Pl),b(t,ys,f),b(t,S,f),w(to,S,null),e(S,Ll),e(S,ve),e(ve,Ol),e(ve,Nn),e(Nn,Sl),e(ve,Nl),e(ve,In),e(In,Il),e(ve,Dl),e(S,Wl),e(S,oo),e(oo,Gl),e(oo,Ao),e(Ao,Hl),e(oo,Ql),e(S,Ul),e(S,no),e(no,Rl),e(no,so),e(so,Bl),e(no,Vl),e(S,Jl),e(S,R),w(ao,R,null),e(R,Xl),e(R,ke),e(ke,Zl),e(ke,jo),e(jo,Kl),e(ke,Yl),e(ke,Dn),e(Dn,ed),e(ke,td),e(R,od),w(Ze,R,null),e(R,nd),w(Ke,R,null),Ts=!0},p(t,[f]){const ro={};f&2&&(ro.$$scope={dirty:f,ctx:t}),qe.$set(ro);const Wn={};f&2&&(Wn.$$scope={dirty:f,ctx:t}),Ae.$set(Wn);const Gn={};f&2&&(Gn.$$scope={dirty:f,ctx:t}),je.$set(Gn);const Hn={};f&2&&(Hn.$$scope={dirty:f,ctx:t}),Le.$set(Hn);const io={};f&2&&(io.$$scope={dirty:f,ctx:t}),Oe.$set(io);const Qn={};f&2&&(Qn.$$scope={dirty:f,ctx:t}),Ne.$set(Qn);const Un={};f&2&&(Un.$$scope={dirty:f,ctx:t}),Ie.$set(Un);const Rn={};f&2&&(Rn.$$scope={dirty:f,ctx:t}),We.$set(Rn);const lo={};f&2&&(lo.$$scope={dirty:f,ctx:t}),Ge.$set(lo);const Bn={};f&2&&(Bn.$$scope={dirty:f,ctx:t}),He.$set(Bn);const Vn={};f&2&&(Vn.$$scope={dirty:f,ctx:t}),Ue.$set(Vn);const Jn={};f&2&&(Jn.$$scope={dirty:f,ctx:t}),Re.$set(Jn);const Xn={};f&2&&(Xn.$$scope={dirty:f,ctx:t}),Ve.$set(Xn);const Zn={};f&2&&(Zn.$$scope={dirty:f,ctx:t}),Je.$set(Zn);const co={};f&2&&(co.$$scope={dirty:f,ctx:t}),Ze.$set(co);const po={};f&2&&(po.$$scope={dirty:f,ctx:t}),Ke.$set(po)},i(t){Ts||(y(n.$$.fragment,t),y(rt.$$.fragment,t),y(pt.$$.fragment,t),y(ht.$$.fragment,t),y(qe.$$.fragment,t),y(ut.$$.fragment,t),y(gt.$$.fragment,t),y(Mt.$$.fragment,t),y(Ae.$$.fragment,t),y(je.$$.fragment,t),y(wt.$$.fragment,t),y(yt.$$.fragment,t),y(Ft.$$.fragment,t),y(Le.$$.fragment,t),y(Oe.$$.fragment,t),y(qt.$$.fragment,t),y(Ct.$$.fragment,t),y(Lt.$$.fragment,t),y(Ne.$$.fragment,t),y(Ie.$$.fragment,t),y(Ot.$$.fragment,t),y(St.$$.fragment,t),y(Wt.$$.fragment,t),y(We.$$.fragment,t),y(Ge.$$.fragment,t),y(He.$$.fragment,t),y(Gt.$$.fragment,t),y(Ht.$$.fragment,t),y(Bt.$$.fragment,t),y(Ue.$$.fragment,t),y(Re.$$.fragment,t),y(Vt.$$.fragment,t),y(Jt.$$.fragment,t),y(Yt.$$.fragment,t),y(Ve.$$.fragment,t),y(Je.$$.fragment,t),y(eo.$$.fragment,t),y(to.$$.fragment,t),y(ao.$$.fragment,t),y(Ze.$$.fragment,t),y(Ke.$$.fragment,t),Ts=!0)},o(t){T(n.$$.fragment,t),T(rt.$$.fragment,t),T(pt.$$.fragment,t),T(ht.$$.fragment,t),T(qe.$$.fragment,t),T(ut.$$.fragment,t),T(gt.$$.fragment,t),T(Mt.$$.fragment,t),T(Ae.$$.fragment,t),T(je.$$.fragment,t),T(wt.$$.fragment,t),T(yt.$$.fragment,t),T(Ft.$$.fragment,t),T(Le.$$.fragment,t),T(Oe.$$.fragment,t),T(qt.$$.fragment,t),T(Ct.$$.fragment,t),T(Lt.$$.fragment,t),T(Ne.$$.fragment,t),T(Ie.$$.fragment,t),T(Ot.$$.fragment,t),T(St.$$.fragment,t),T(Wt.$$.fragment,t),T(We.$$.fragment,t),T(Ge.$$.fragment,t),T(He.$$.fragment,t),T(Gt.$$.fragment,t),T(Ht.$$.fragment,t),T(Bt.$$.fragment,t),T(Ue.$$.fragment,t),T(Re.$$.fragment,t),T(Vt.$$.fragment,t),T(Jt.$$.fragment,t),T(Yt.$$.fragment,t),T(Ve.$$.fragment,t),T(Je.$$.fragment,t),T(eo.$$.fragment,t),T(to.$$.fragment,t),T(ao.$$.fragment,t),T(Ze.$$.fragment,t),T(Ke.$$.fragment,t),Ts=!1},d(t){o(d),t&&o(v),t&&o(g),$(n),t&&o(Yn),t&&o(oe),$(rt),t&&o(es),t&&o($e),t&&o(ts),t&&o(mo),t&&o(os),t&&o(uo),t&&o(ns),t&&o(go),t&&o(ss),t&&o(ze),t&&o(as),t&&o(B),t&&o(rs),t&&o(fo),t&&o(is),t&&o(xe),t&&o(ls),t&&o(ne),$(pt),t&&o(ds),t&&o(D),$(ht),$(qe),t&&o(cs),t&&o(re),$(ut),t&&o(ps),t&&o(q),$(gt),$(Mt),$(Ae),$(je),t&&o(hs),t&&o(le),$(wt),t&&o(ms),t&&o(A),$(yt),$(Ft),$(Le),$(Oe),t&&o(us),t&&o(ce),$(qt),t&&o(gs),t&&o(j),$(Ct),$(Lt),$(Ne),$(Ie),t&&o(fs),t&&o(he),$(Ot),t&&o(_s),t&&o(P),$(St),$(Wt),$(We),$(Ge),$(He),t&&o(bs),t&&o(ue),$(Gt),t&&o(vs),t&&o(L),$(Ht),$(Bt),$(Ue),$(Re),t&&o(ks),t&&o(fe),$(Vt),t&&o(Ms),t&&o(O),$(Jt),$(Yt),$(Ve),$(Je),t&&o(ws),t&&o(be),$(eo),t&&o(ys),t&&o(S),$(to),$(ao),$(Ze),$(Ke)}}}const tp={local:"mega",sections:[{local:"overview",title:"Overview"},{local:"transformers.MegaConfig",title:"MegaConfig"},{local:"transformers.MegaModel",title:"MegaModel"},{local:"transformers.MegaForCausalLM",title:"MegaForCausalLM"},{local:"transformers.MegaForMaskedLM",title:"MegaForMaskedLM"},{local:"transformers.MegaForSequenceClassification",title:"MegaForSequenceClassification"},{local:"transformers.MegaForMultipleChoice",title:"MegaForMultipleChoice"},{local:"transformers.MegaForTokenClassification",title:"MegaForTokenClassification"},{local:"transformers.MegaForQuestionAnswering",title:"MegaForQuestionAnswering"}],title:"MEGA"};function op(z){return Sc(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class dp extends jc{constructor(d){super();Pc(this,d,op,ep,Lc,{})}}export{dp as default,tp as metadata};
