Instructions to use rrivera1849/LUAR-MUD with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use rrivera1849/LUAR-MUD with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="rrivera1849/LUAR-MUD", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("rrivera1849/LUAR-MUD", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files50 unmodified lines51525354555650 unmodified linesprint(attentions[0].size()) # torch.Size([48, 12, 32, 32])```## Citing & AuthorsIf you find this model helpful, feel free to cite our [publication](https://aclanthology.org/2021.emnlp-main.70.pdf).50 unmodified lines5152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017150 unmodified linesprint(attentions[0].size()) # torch.Size([48, 12, 32, 32])```## Usage (Batch)Here's a more fleshed out example showing how to run LUAR across many batches of data:```pythonimport numpy as npimport torchfrom termcolor import cprintfrom transformers import AutoModel, AutoTokenizerfrom tqdm import tqdmdef generate_data(num_batches: int = 100, batch_size: int = 32, num_samples_per_author: int = 16):"""Generator that produces dummy data for testing.Args:num_batches (int): Total number of batches to yield.batch_size (int): Number of authors per batch.num_samples_per_author (int): Number of text samples per author.Yields:list: A batch of data structured as a list of lists of strings.Shape: (batch_size, num_samples_per_author)"""s = "This is an example string."for batch in tqdm(range(num_batches)):# Create a batch where each element is a list of 's' repeated 'num_samples_per_author' timesyield [[s] * num_samples_per_author for _ in range(batch_size)]def flatten(l):"""Helper function to flatten a 2D list into a 1D list.Args:l (list): List of lists.Returns:list: Flattened list."""return [item for sublist in l for item in sublist]def main():cprint("Starting LUAR-MUD example script...", 'magenta')# --- Model Loading ---cprint("Loading model 'rrivera1849/LUAR-MUD'...", 'blue')# trust_remote_code=True is required for custom model architectures like LUAR-MUDmodel = AutoModel.from_pretrained("rrivera1849/LUAR-MUD", trust_remote_code=True)model.eval()# Check for CUDA availability and move model to appropriate devicedevice = "cuda" if torch.cuda.is_available() else "cpu"cprint(f"Moving model to device: {device}", 'yellow')model.to(device)# --- Tokenizer Loading ---cprint("Loading tokenizer...", 'blue')tokenizer = AutoTokenizer.from_pretrained("rrivera1849/LUAR-MUD", trust_remote_code=True)# --- Configuration ---num_batches = 100batch_size = 32num_samples_per_author = 16max_length = 512cprint("\nConfiguration:", 'cyan')print(f" Batch Size: {batch_size}")print(f" Samples per Author: {num_samples_per_author}")print(f" Max Length: {max_length}")print(f" Device: {device}\n")all_outputs = []cprint("Starting inference loop...", 'green')# context manager for disabling gradient calculation to save memory/computewith torch.inference_mode():for i, batch in enumerate(generate_data(num_batches=num_batches, batch_size=batch_size, num_samples_per_author=num_samples_per_author)):if (i + 1) % 10 == 0:print(f" Processing batch {i + 1}...")# Flatten the batch structure for tokenization:# (batch_size, num_samples) -> (batch_size * num_samples)batch = flatten(batch)# Tokenize the flattened batchinputs = tokenizer(batch, return_tensors="pt", padding=True, max_length=max_length, truncation=True)# Move inputs to the same device as the modelinputs = inputs.to(device)# Reshape input_ids and attention_mask to match the model's expected 3D input:# (batch_size, num_samples_per_author, sequence_length)inputs["input_ids"] = inputs["input_ids"].reshape(batch_size, num_samples_per_author, -1)inputs["attention_mask"] = inputs["attention_mask"].reshape(batch_size, num_samples_per_author, -1)# Forward pass through the modeloutputs = model(**inputs)# Move outputs back to CPU and convert to numpy for storageall_outputs.append(outputs.cpu().numpy())# Concatenate all batch results into a single array# axis=0 corresponds to the batch dimensionall_outputs = np.concatenate(all_outputs, axis=0)cprint("\nInference complete!", 'green')cprint(f"Final output shape: {all_outputs.shape}", attrs=['bold'])if __name__ == "__main__":main()```## Citing & AuthorsIf you find this model helpful, feel free to cite our [publication](https://aclanthology.org/2021.emnlp-main.70.pdf).
README.md+115