What are the effects of using Lambda functions in your datablock?

This question is referring to Chapter 6 of the book, where the following is stated:

Lambda functions are great for quickly iterating, but they are not compatible with serialization, so we advise you to use the more verbose approach if you want to export your Learner after training (lambdas are fine if you are just experimenting).

I trained a model using the PASCAL_2007 dataset with a DataBlock with a lambda for the inputs and labels, and a model using a function. Both executed in about the same time, the version using lambda was actually a bit faster, but with less CPU time.

Could someone help me better understand the statement made in the book?

1 Like

When you export the Learner via learn.export, or load it back in, you’ll get a function lambda xyz is unserializable (or cannot be referenced). It’s better to turn the lambda into a def xyz(): return something from the start to never have to worry about this

3 Likes

Aaah, now I get it. Thank you!