I couldn't add learnerbuilder to my Burn code . I will appreciate any help. here is the code ```
use burn::module::Module;
use burn::{
backend::Wgpu,
data::{
dataloader::{batcher::Batcher, DataLoader, DataLoaderBuilder},
dataset::InMemDataset,
},
nn::{Dropout, DropoutConfig, Gelu, Linear, LinearConfig},
tensor::{backend::Backend, Tensor},
};
use csv::ReaderBuilder;
use serde::Deserialize;
use std::{error::Error, sync::Arc};
#[derive(Debug, Deserialize, Clone)]
struct MyRecord {
slp: f64,
asp: f64,
curv: f64,
jeo: f64,
hey: isize,
}
#[derive(Debug, Clone)]
struct MyBatch<B: Backend> {
inputs: Tensor<B, 2>, // 2D Tensor for inputs
targets: Tensor<B, 1>, // 1D Tensor for targets
}
// Batcher for MyRecord
#[derive(Debug, Clone)]
struct MyBatcher;
impl<B: Backend> Batcher<MyRecord, MyBatch> for MyBatcher {
fn batch(&self, items: Vec) -> MyBatch {
let inputs: Vec<Tensor<B, 1>> = items
.iter()
.map(|item| {
Tensor::<B, 1>::from_floats(
[
item.slp as f32,
item.asp as f32,
item.curv as f32,
item.jeo as f32,
],
&B::Device::default(),
)
})
.collect();
let inputs = Tensor::stack(inputs, 0); // Stack into a single 2D tensor
let targets: Vec<Tensor<B, 1>> = items
.iter()
.map(|item| Tensor::<B, 1>::from_floats([item.hey as f32], &B::Device::default()))
.collect();
let targets = Tensor::cat(targets, 0); // Combine all target tensors into one 1D tensor
MyBatch { inputs, targets }
}
}
#[derive(Module, Debug)]
pub struct Model<B: Backend> {
linear_inner: Linear,
linear_outer: Linear,
dropout: Dropout,
gelu: Gelu,
}
impl<B: Backend> Model {
pub fn new(device: &B::Device, tensor_width: usize, num_neu: usize) -> Self {
let linear_inner = LinearConfig::new(tensor_width, num_neu).init(device);
let linear_outer = LinearConfig::new(num_neu, 2).init(device);
let dropout = DropoutConfig::new(0.5).init();
let gelu = Gelu::new();
Model {
linear_inner,
linear_outer,
dropout,
gelu,
}
}
pub fn forward<const D: usize>(&self, input: Tensor<B, D>) -> Tensor<B, D> {
let x = self.linear_inner.forward(input);
let x = self.gelu.forward(x);
let x = self.dropout.forward(x);
self.linear_outer.forward(x)
}
}
fn main() -> Result<(), Box> {
type B = Wgpu;
let device = ::Device::default();
// Specify the path to the CSV file
let csv_path = "train_scaled.csv";
let mut binding = ReaderBuilder::new();
let builder = binding.delimiter(b','); // Use ',' as delimiter
// Load the dataset using the CSV file and the ReaderBuilder
let dataset_train = InMemDataset::<MyRecord>::from_csv(csv_path, &builder)?;
// Set batch size and create DataLoader
let batch_size = 32;
let batcher = MyBatcher;
// Create DataLoader
let dataloader: Arc<dyn DataLoader<MyBatch<B>>> = DataLoaderBuilder::new(batcher)
.batch_size(batch_size)
.shuffle(42)
.build(dataset_train);
// Instantiate model
let tensor_width = 4; // Number of features in input
let num_neu = 64; // Number of neurons in hidden layer
let model = Model::<B>::new(&device, tensor_width, num_neu);
// Iterate over batches and apply the model
for batch in dataloader.iter() {
let inputs = batch.inputs;
let targets = batch.targets;
// Forward pass
let outputs = model.forward(inputs);
// For demonstration, printing out the targets and outputs
println!("Targets: {:?}", targets);
println!("Outputs: {:?}", outputs);
}
Ok(())
}