Instructions to use FacebookAI/xlm-roberta-large with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use FacebookAI/xlm-roberta-large with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("fill-mask", model="FacebookAI/xlm-roberta-large")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForMaskedLM tokenizer = AutoTokenizer.from_pretrained("FacebookAI/xlm-roberta-large") model = AutoModelForMaskedLM.from_pretrained("FacebookAI/xlm-roberta-large", device_map="auto") - Inference
- Notebooks
- Google Colab
- Kaggle
Download src/models/two_layer_nn.py from FacebookAI/xlm-roberta-large: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/FacebookAI/xlm-roberta-large/resolve/refs%2Fpr%2F8/src/models/two_layer_nn.py
- Command line
-
hf download hf://FacebookAI/xlm-roberta-large@refs/pr/8/src/models/two_layer_nn.py
-
curl -L -o two_layer_nn.py https://huggingface.co/FacebookAI/xlm-roberta-large/resolve/refs%2Fpr%2F8/src/models/two_layer_nn.py
1.44 kB
| """Implements a two layer Neural Network.""" | |
| from torch.nn import Module, Linear, ReLU | |
| from src.utils.mapper import configmapper | |
| class TwoLayerNN(Module): | |
| """Implements two layer neural network. | |
| Methods: | |
| forward(x_input): Returns the output of the neural network. | |
| """ | |
| def __init__(self, embedding, dims): | |
| """Construct the two layer Neural Network. | |
| This method is used to initialize the two layer neural network, | |
| with a given embedding type and corresponding arguments. | |
| Args: | |
| embedding (torch.nn.Module): The embedding layer for the model. | |
| dims (list): List of dimensions for the neural network, input to output. | |
| """ | |
| super(TwoLayerNN, self).__init__() | |
| self.embedding = embedding | |
| self.linear1 = Linear(dims[0], dims[1]) | |
| self.relu = ReLU() | |
| self.linear2 = Linear(dims[1], dims[2]) | |
| def forward(self, x_input): | |
| """ | |
| Return the output of the neural network for an input. | |
| Args: | |
| x_input (torch.Tensor): The input tensor to the neural network. | |
| Returns: | |
| x_output (torch.Tensor): The output tensor for the neural network. | |
| """ | |
| output = self.embedding(x_input) | |
| output = self.linear1(output) | |
| output = self.relu(output) | |
| x_output = self.linear2(output) | |
| return x_output | |