Fill-Mask
Transformers
PyTorch
Norwegian
Norwegian Bokmål
Norwegian Nynorsk
BERT
NorBERT
Norwegian
encoder
custom_code
Instructions to use ltg/norbert3-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ltg/norbert3-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("fill-mask", model="ltg/norbert3-base", trust_remote_code=True)# Load model directly from transformers import AutoModelForMaskedLM model = AutoModelForMaskedLM.from_pretrained("ltg/norbert3-base", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
Update modeling_norbert.py
Browse files- modeling_norbert.py +4 -4
modeling_norbert.py
CHANGED
|
@@ -133,12 +133,12 @@ class Attention(nn.Module):
|
|
| 133 |
|
| 134 |
# Recompute position_indices at the beginning or if sequence length exceeds the precomputed size
|
| 135 |
if self.position_indices is None or self.position_indices.size(0) < query_len:
|
| 136 |
-
position_indices = torch.arange(query_len, dtype=torch.long).unsqueeze(1) \
|
| 137 |
- torch.arange(query_len, dtype=torch.long).unsqueeze(0)
|
| 138 |
-
position_indices = self.make_log_bucket_position(position_indices, self.config.position_bucket_size, 512)
|
| 139 |
-
position_indices = self.config.position_bucket_size - 1 + position_indices
|
| 140 |
if self.position_indices.device != hidden_states.device:
|
| 141 |
-
self.position_indices = position_indices.to(hidden_states.device)
|
| 142 |
|
| 143 |
# Pre-LN and project query/key/value.
|
| 144 |
hidden_states = self.pre_layer_norm(hidden_states) # shape: [B, T, D]
|
|
|
|
| 133 |
|
| 134 |
# Recompute position_indices at the beginning or if sequence length exceeds the precomputed size
|
| 135 |
if self.position_indices is None or self.position_indices.size(0) < query_len:
|
| 136 |
+
self.position_indices = torch.arange(query_len, dtype=torch.long).unsqueeze(1) \
|
| 137 |
- torch.arange(query_len, dtype=torch.long).unsqueeze(0)
|
| 138 |
+
self.position_indices = self.make_log_bucket_position(self.position_indices, self.config.position_bucket_size, 512)
|
| 139 |
+
self.position_indices = self.config.position_bucket_size - 1 + self.position_indices
|
| 140 |
if self.position_indices.device != hidden_states.device:
|
| 141 |
+
self.position_indices = self.position_indices.to(hidden_states.device)
|
| 142 |
|
| 143 |
# Pre-LN and project query/key/value.
|
| 144 |
hidden_states = self.pre_layer_norm(hidden_states) # shape: [B, T, D]
|