Example-wise Agnostic Transformer

11 views
Skip to first unread message

Petr Bělohlávek

unread,
Jul 14, 2016, 4:27:30 AM7/14/16
to fuel-users
Hi everybody,
I implemented my own transformer and I wonder if you could help me with the overall class design.

My transformer simulates function f which takes 3 arguments and returns 2 results. For simplicity, let's assume that it computes minimum and maximum.
> f(20,15,40)
(15,40)

So I extended the Transformer class with method transform_example(). It takes a tuple of three values, applies min/max and returns a tuple of two numbers.

The problem is when I want to implement also the transform_batch() method. The method takes a tuple of three lists of batch_size values. It seems tempting to make a for-cycle or something like that in order to compute min/max row-wise and than use some kind of stacking the proper values on top of another and than return tuple of two lists. But it introduces duplicite code, which is antipattern I'd like to avoid.

The second option is to iterate through the lists and call transform_example(). This is actually what I think it's best, but I still think it isn't right.

I've read about AgnosticTransformer, which is basically what I want, because I want to apply the exact transformation for both example and batch (example-wise). The thing is, that AgnosticTransformer actually applies the same code to whatever it is passed to it, hence it doesn't work.

I think this is a common problem, so there must be some kind of elegant solution. What would you suggest me to do?
Of course, I use more complicated function that can't be computed easily by applying some numpy trick :) The question is more abour how to design a transformer that handles batches example-wise without any duplicite code or special treatment. For example, I think there might be a class with only transform_example() that does the right thing for batches as well.

Thanks for help
Petr
Reply all
Reply to author
Forward
0 new messages