fuck these tensors and there redundant complexity. WHY DOESNT WE JUST THINKIN list (or…
- User
fuck these tensors and there redundant complexity.
WHY DOESNT WE JUST THINKIN list (or list of list, etc)?
- Assistant
I understand your frustration! Working with tensors can indeed feel overly complex, especially when you're trying to implement something straightforward. Let's break down why tensors are used and how they relate to simpler data structures like lists.
Why Tensors?
-
Efficiency: Tensors are designed for efficient computation, especially on GPUs. They allow for parallel processing of data, which is crucial for training machine learning models.
-
Dimensionality: Tensors can represent multi-dimensional data (e.g., images, sequences, etc.) in a way that is consistent and easy to manipulate mathematically. This is particularly useful in deep learning, where operations often involve high-dimensional data.
-
Framework Compatibility: Libraries like Candle, PyTorch, and TensorFlow are built around the concept of tensors. They provide optimized operations for tensors, making it easier to implement complex models without having to manage the underlying details.
Lists vs. Tensors
-
Lists: In languages like Rust, lists (or vectors) are great for simple data structures. They are easy to use and understand, but they lack the built-in operations for mathematical computations that tensors provide.
-
Tensors: While they may seem more complex, tensors provide a structured way to handle multi-dimensional data and perform operations like matrix multiplication, reshaping, and broadcasting, which are common in machine learning.
Simplifying Your Code
If you prefer to think in terms of lists, you can certainly start with lists and convert them to tensors only when necessary. For example, you can:
-
Use Lists for Data Preparation: Keep your data in simple lists or lists of lists until you're ready to feed it into your model.
-
Convert to Tensors at the Last Moment: Only convert your lists to tensors when you need to perform operations that require tensor functionality.
Example
Here's a simplified approach using lists:
fn ready_dataset() -> (Vec<Vec<u32>>, Vec<u32>, Vec<Vec<u32>>, Vec<u32>) { let (train, test) = split(dataset()); let train_x: Vec<Vec<u32>> = train.iter().map(|t| vec![tokenize(t.0)]).collect(); let train_y: Vec<u32> = train.iter().map(|t| tokenize(t.1)).collect(); let test_x: Vec<Vec<u32>> = test.iter().map(|t| vec![tokenize(t.0)]).collect(); let test_y: Vec<u32> = test.iter().map(|t| tokenize(t.1)).collect(); (train_x, train_y, test_x, test_y) }Conclusion
While tensors are powerful and necessary for many operations in machine learning, you can certainly use simpler data structures for data preparation and only convert to tensors when needed. This can help reduce complexity and make your code easier to understand.
If you have specific parts of your code that you find particularly cumbersome, feel free to share, and I can help simplify them!
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.