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/modules/embeddings.py from FacebookAI/xlm-roberta-large: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/FacebookAI/xlm-roberta-large/resolve/refs%2Fpr%2F8/src/modules/embeddings.py
- Command line
-
hf download hf://FacebookAI/xlm-roberta-large@refs/pr/8/src/modules/embeddings.py
-
curl -L -o embeddings.py https://huggingface.co/FacebookAI/xlm-roberta-large/resolve/refs%2Fpr%2F8/src/modules/embeddings.py
1.29 kB
| """Contains various kinds of embeddings like Glove, BERT, etc.""" | |
| from torch.nn import Module, Embedding, Flatten | |
| from src.utils.mapper import configmapper | |
| class GloveEmbedding(Module): | |
| """Implement Glove based Word Embedding.""" | |
| def __init__(self, embedding_matrix, padding_idx, static=True): | |
| """Construct GloveEmbedding. | |
| Args: | |
| embedding_matrix (torch.Tensor): The matrix contrainining the embedding weights | |
| padding_idx (int): The padding index in the tokenizer. | |
| static (bool): Whether or not to freeze embeddings. | |
| """ | |
| super(GloveEmbedding, self).__init__() | |
| self.embedding = Embedding.from_pretrained(embedding_matrix) | |
| self.embedding.padding_idx = padding_idx | |
| if static: | |
| self.embedding.weight.required_grad = False | |
| self.flatten = Flatten(start_dim=1) | |
| def forward(self, x_input): | |
| """Pass the input through the embedding. | |
| Args: | |
| x_input (torch.Tensor): The numericalized tokenized input | |
| Returns: | |
| x_output (torch.Tensor): The output from the embedding | |
| """ | |
| x_output = self.embedding(x_input) | |
| x_output = self.flatten(x_output) | |
| return x_output | |